Dowload as PDF

1.8. Procedures

Just as Variables this entity is not represented in the editor, but at the same time is a very useful element of the system. Mecanim Callbacker gives many callbacks for working with events… But almost all of them are dependant on Update/FixedUpdate look. What if it's necessary to perform code, that is dependent on what state, Group, Category or even Between Event we are located in? Procedures can help us do that!

So, what is Procedure? It's a named entity that lets you bind your code and listed above entities (all of them are united by that we can be located in them). This is the usual pipeline for working with Procedures:

  1. Create/get procedure by calling method Сontroller.Procedures.GetProcedure. This method has versions with the ability to create procedures with parameters (up to five). As long as types of parameters are different, you can use the same name for procedure.
    csharp
    //Sample
    //Get first procedure
    var p1 = controller.Procedures.GetProcedure<float>("proc");
    //Get second procedure
    var p2 = controller.Procedures.GetProcedure("proc");
    //Get third procedure, but its the same that first
    var p3 = controller.Procedures.GetProcedure<float>("proc");
  2. Bind our code to procedure.
    csharp
    //Sample
    //Get procedure
    var p = controller.Procedures.GetProcedure<float>("proc");
    var c = controller.Categories["category"];
    c.BindProcedure(swapProcedure).OnCall += (sourceController, f) => {
    Debug.Log("Hello there! I got value = " + f);
    }
  3. Call procedure in any part of the code, and only code that's bound to currently active entities will be called.
    csharp
    //Sample
    //Get procedure
    var p = controller.Procedures.GetProcedure<float>("proc");
    p.Call(10f);
Yes No
0 of 0 users found this section helpful
Suggest Edit