Parallel Action

A Parallel Action is used to create an Alternative Path decision making action.

Multiple actions can be initialized and according to which action is completed, the session will follow the according path.

Example of Parallel Action Script:

/// <summary>
/// This is an example of Parallel Action
/// Both Actions (AssembleKnossosPartOfAction, AssembleSponzaPartOfAction) will initialized automatically and run in parallel
/// </summary>
public class AssembleKnossosORSponzaAction : ParallelAction {

    /// <summary>
    /// Combined Action consists of several "sub-Actions" that run one after another
    /// In this Combined Action we have InsertAction->InsertAction->ToolAction
    /// </summary>
    public class AssembleKnossosPartOfAction : CombinedAction
    {
        public override void Initialize()
        {
            AnalyticsManager.AddScoringFactor<ForceScoringFactor>(2);

            //InsertAction sub-Action
            InsertAction insertFrontGateAction = gameObject.AddComponent<InsertAction>();
            insertFrontGateAction.SetInsertPrefab("Lesson0/Stage1/Action0/FrontPartInteractable",
                                                "Lesson0/Stage1/Action0/FrontPartFinal");
            insertFrontGateAction.SetHoloObject("Lesson0/Stage1/Action0/Hologram/FrontPartHologram");

            //--------------------------------------------------------------------------------------------
            //InsertAction sub - Action
            InsertAction insertBackGateAction = gameObject.AddComponent<InsertAction>();
            insertBackGateAction.SetInsertPrefab("Lesson0/Stage1/Action0/BackPartInteractable",
                                                "Lesson0/Stage1/Action0/BackPartFinal");
            insertBackGateAction.SetHoloObject("Lesson0/Stage1/Action0/Hologram/BackPartHologram");
            //--------------------------------------------------------------------------------------------
            //ToolAction sub - Action
            ToolAction hitWithMallet = gameObject.AddComponent<ToolAction>();
            hitWithMallet.SetToolActionPrefab("Lesson0/Stage1/Action0/BackPartHitMallet", ovidVR.toolManager.tool.ToolsEnum.Mallet);
            hitWithMallet.SetHoloObject("Lesson0/Stage1/Action0/Hologram/MalletHologramL0S1A0");
            //hitWithMallet.SetAidLine("AidLine_MalletGrab");

            InsertIActions(insertFrontGateAction, insertBackGateAction, hitWithMallet);

            base.Initialize();
        }
    }

    /// <summary>
    /// Example of Insert Action
    /// </summary>
    public class AssembleSponzaPartOfAction : InsertAction
    {
        /// <summary>
        /// Initialize method overrides base.Initialize() and sets the prefab user will insert
        /// </summary>
        public override void Initialize()
        {
            //Set Prefab to insert
            //First Argument: Interactable prefab
            //Second Argument: Final prefab
            //Third Argument: Hologram
            SetInsertPrefab("Lesson0/Stage1/Action0/SponzaInteractable", "Lesson0/Stage1/Action0/SponzaFinal");
            SetHoloObject("Lesson0/Stage1/Action0/Hologram/HologramSponzaFinal");
            SetAidLine("AidLine_Decision");
            base.Initialize();
        }
    }

    /// <summary>
    /// Initialize() function for Parallel Action
    /// Sets the alt path to triggen when performing each Action
    /// </summary>
    public override void Initialize()
    {
        AssembleKnossosPartOfAction assembleKnossosPartOfAction = this.gameObject.AddComponent<AssembleKnossosPartOfAction>();

        AssembleSponzaPartOfAction assembleSponzaPartOfAction = this.gameObject.AddComponent<AssembleSponzaPartOfAction>();
        //Set different event Manager for second Action
        assembleSponzaPartOfAction.SetEventListener("SponzaPart");

        InsertIActionToDictionary(-1, assembleKnossosPartOfAction);
        InsertIActionToDictionary(0, assembleSponzaPartOfAction);

        base.Initialize();
    }
}

Action Script Explanation

In this example we create two Actions (one Combined Action and one Insert Action) and initialize them asynchronously. To correctly initialize a Parallel Action add the classes of the actions inside the Parallel Action class. Then, add them as a Component as shown in the example above.

The final step is to set each action to trigger a specific Path, using the InsertIActionToDictionary function.

Note

Keep in mind, that once performed, the Parallel Action will trigger all Perform() functions of each action it contains. This may result in gameobject deletion or other unintended behavior, so make sure you handle each occasion.