/// <summary> /// Create a new interaction definition for the game object, used to add new interactions /// </summary> /// <param name="_name"> Name for the new interaction </param> /// <returns>An interaction definition, that can be modified in order to create dependencies, /// conditions and action. </returns> public S_InteractionDefinition CreateInteractionDefinition(string _name) { S_InteractionDefinition definition = new S_InteractionDefinition(_name); Interactions.Add(definition); return(definition); }
/// <summary> /// Creates all the interactions specified in the IO definition and binds them into the /// newly created Interactive Object /// </summary> /// <param name="_ioDef"> The definition of the IO in process of creation </param> /// <param name="_io"> The instance of the interactive object being created </param> /// <param name="_wireDependencies"> Do the dependencies will be wired now ? (set that to false if you have circular dependencies that need /// to be post processed when all the ios and interactions have been created) </param> private static void CreateInteractionsForGameObject(S_IODefinition _ioDef, Gaze_InteractiveObject _io, bool _wireDependencies) { // Get the base interaction in order to replicate it as many times as needed Gaze_Interaction modelInteraction = _io.GetComponentInChildren <Gaze_Interaction>(); // Create all the interactions specified on the io definition int numInteractions = _ioDef.Interactions.Count; for (int i = 0; i < numInteractions; i++) { // Create a new copy of the model interation and parent it to the interactions of the io GameObject interaction = GameObject.Instantiate(modelInteraction.gameObject, modelInteraction.transform.parent); // Get the interaction definition S_InteractionDefinition interDef = _ioDef.Interactions[i]; // Add a GUID in order to identify in a unique way across all the apps and runtimes interaction.AddComponent <S_Guid>().SetGUID(interDef.GUID); // Set the interaction name interaction.name = interDef.Name; // Create the interaction conditions CreateConditionsForInteraction(interDef, interaction); // Create the interaction Actions CreateActionsForInteraction(interDef, interaction); // Add the Delay to the interaction if (interDef.Delay > 0) { Gaze_Conditions cond = interaction.GetComponent <Gaze_Conditions>(); cond.delayed = true; cond.delayDuration = interDef.Delay; } // Destroy the game object used to hold the monobehaivours before // the creation of the interaction interDef.DestroyComponentHolder(); // Create the interaction dependencies if necessary if (_wireDependencies) { CreateDependenciesForInteraction(interDef, interaction); } else { depenenciesToWire.Add(new KeyValuePair <GameObject, S_InteractionDefinition>(interaction, interDef)); } } }
/// <summary> /// Creates all the dependencies for the interaction being created, we should consider /// exposing this method in order to allow the creation of circular dependencies, like that /// the user will be able to first, create all the ios, conditions, actions and then wire up /// all the dependencies without having to care about the order of creation of the ios. /// </summary> /// <param name="_interDef"> The definition of the interaciton being created </param> /// <param name="_interaction"> The interaction in process of creation </param> private static void CreateDependenciesForInteraction(S_InteractionDefinition _interDef, GameObject _interaction) { int numConditions = _interDef.ConditionsAndDependencies.Count; for (int i = 0; i < numConditions; i++) { Gaze_AbstractCondition cond = _interDef.ConditionsAndDependencies[i]; // We need to make sure that the object is a dependency (a dependency is a condition as well) if (cond is Gaze_Dependency) { cond.SetupUsingApi(_interaction); } } }
/// <summary> /// Creates all the specified conditions for the interaction being created /// </summary> /// <param name="_interDef">The interaction definition file</param> /// <param name="_interaction"> The interaction in process of creation </param> private static void CreateConditionsForInteraction(S_InteractionDefinition _interDef, GameObject _interaction) { int numConditions = _interDef.ConditionsAndDependencies.Count; for (int i = 0; i < numConditions; i++) { Gaze_AbstractCondition cond = _interDef.ConditionsAndDependencies[i]; // Create all the conditions letting the dependencies being created in next stages if (!(cond is Gaze_Dependency)) { cond.SetupUsingApi(_interaction); } } }
/// <summary> /// Creates all the actions defined on the S_Interaction definitions /// </summary> /// <param name="_interDef"> Interaction definition object </param> /// <param name="_interaction"> Interaction </param> private static void CreateActionsForInteraction(S_InteractionDefinition _interDef, GameObject _interaction) { int numActions = _interDef.Actions.Count; for (int i = 0; i < numActions; i++) { // Get the temporary action Gaze_AbstractBehaviour tempAction = _interDef.Actions[i]; // Create the final action using the temporary aciton type Component comp = _interaction.AddComponent(tempAction.GetType()); // Cast to get the Gaze_AbstractBehaivour of the action Gaze_AbstractBehaviour finalAction = ((Gaze_AbstractBehaviour)comp); // Copy the temp action data to the final data finalAction.creationData = new List <object>(tempAction.creationData); // Setupt the final action finalAction.SetupUsingApi(_interaction); } }