Esempio n. 1
0
        public Gaze_Dependency Add(Gaze_Conditions conditions)
        {
            Gaze_Dependency d = new Gaze_Dependency(conditions);

            dependencies.Add(d);
            return(d);
        }
Esempio n. 2
0
        private void ValidateDependencies(GameObject sender, int triggerStateIndex)
        {
            if (!ActivateOnDependencyMap.AreDependenciesSatisfied && !ActivateOnDependencyMap.isEmpty())
            {
                Gaze_Dependency activator = ActivateOnDependencyMap.Get(sender);

                if (activator != null)
                {
                    ValidateDependency(activator, triggerStateIndex);

                    if (ValidateDependencyMap(ActivateOnDependencyMap, requireAllActivators))
                    {
                        ActivateOnDependencyMap.AreDependenciesSatisfied = true;

                        // reset start time reference for next delay computation
                        startTime = Time.time;
                    }
                }
            }

            if (!DeactivateOnDependencyMap.isEmpty())
            {
                Gaze_Dependency deactivator = DeactivateOnDependencyMap.Get(sender);

                if (deactivator != null)
                {
                    ValidateDependency(deactivator, triggerStateIndex);

                    if (ValidateDependencyMap(DeactivateOnDependencyMap, requireAllDeactivators))
                    {
                        ActivateOnDependencyMap.AreDependenciesSatisfied = false;
                    }
                }
            }
        }
Esempio n. 3
0
 public bool Delete(Gaze_Dependency d)
 {
     if (dependencies.Contains(d))
     {
         // Destroy the dependency from the list
         d.Dispose();
         return(dependencies.Remove(d));
     }
     return(false);
 }
Esempio n. 4
0
 private void ValidateDependency(Gaze_Dependency d, int triggerStateIndex)
 {
     if (triggerStateIndex == -1)
     {
         // dependend on trigger
         d.SetSatisfied(d.onTrigger);
     }
     else
     {
         // dependent on state
         d.SetSatisfied(triggerStateIndex.Equals(d.triggerStateIndex));
     }
 }
Esempio n. 5
0
        private void DisplayDependencyBlock()
        {
            // NOTE : should check if there are null ref in gazable.dependencies still
            if (hierarchyInteractions.Count == 0)
            {
                EditorGUILayout.HelpBox("No triggers found.", MessageType.Warning);
                return;
            }

            // check if there are conditions specified
            if (targetConditions.ActivateOnDependencyMap.dependencies.Count < 1 && targetConditions.DeactivateOnDependencyMap.dependencies.Count < 1)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox("Add at least one dependency or deactivate it if not needed.", MessageType.Warning);
                EditorGUILayout.EndHorizontal();
            }

            // On Activation button
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Activate on");
            targetConditions.requireAllActivators = EditorGUILayout.ToggleLeft("Require all", targetConditions.requireAllActivators);
            EditorGUILayout.EndHorizontal();

            // update dependencies list in gazable (gazables may have been removed in the hierarchy)
            if (targetConditions.ActivateOnDependencyMap.dependencies.Count > 0)
            {
                // NOTE don't use foreach to avoid InvalidOperationException
                for (int i = 0; i < targetConditions.ActivateOnDependencyMap.dependencies.Count; i++)
                {
                    if (!hierarchyInteractions.Contains(targetConditions.ActivateOnDependencyMap.dependencies[i].dependentGameObject))
                    {
                        targetConditions.ActivateOnDependencyMap.Delete(targetConditions.ActivateOnDependencyMap.dependencies[i]);
                    }
                }
            }

            // display all existing dependencies in the Gazable
            for (int i = 0; i < targetConditions.ActivateOnDependencyMap.dependencies.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();

                var activateDependency = EditorGUILayout.ObjectField(targetConditions.ActivateOnDependencyMap.dependencies[i].dependentGameObject, typeof(Gaze_Conditions), true);

                if (activateDependency != null)
                {
                    if (activateDependency is Gaze_Conditions)
                    {
                        targetConditions.ActivateOnDependencyMap.dependencies[i].dependentGameObject = ((Gaze_Conditions)activateDependency).gameObject;
                    }
                    else
                    {
                        targetConditions.ActivateOnDependencyMap.dependencies[i].dependentGameObject = (GameObject)activateDependency;
                    }
                }

                targetConditions.ActivateOnDependencyMap.dependencies[i].triggerStateIndex = EditorGUILayout.Popup(targetConditions.ActivateOnDependencyMap.dependencies[i].triggerStateIndex, Enum.GetNames(typeof(DependencyTriggerEventsAndStates)));

                // if dependent on Trigger event
                targetConditions.ActivateOnDependencyMap.dependencies[i].onTrigger = targetConditions.ActivateOnDependencyMap.dependencies[i].triggerStateIndex == (int)DependencyTriggerEventsAndStates.Triggered;

                if (GUILayout.Button("-"))
                {
                    targetConditions.ActivateOnDependencyMap.Delete(targetConditions.ActivateOnDependencyMap.dependencies[i]);
                }

                EditorGUILayout.EndHorizontal();
            }

            // display 'add' button
            if (GUILayout.Button("+"))
            {
                Gaze_Dependency d = targetConditions.ActivateOnDependencyMap.Add(targetConditions);
                EditorGUILayout.BeginHorizontal();
                d.dependentGameObject = hierarchyInteractions[EditorGUILayout.Popup(0, hierarchyInteractionsNames.ToArray())];

                d.triggerStateIndex = (int)DependencyTriggerEventsAndStates.Triggered;
                if (GUILayout.Button("-"))
                {
                    targetConditions.ActivateOnDependencyMap.Delete(d);
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.Space();

            // Deactivate
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Deactivate on");
            targetConditions.requireAllDeactivators = EditorGUILayout.ToggleLeft("Require all", targetConditions.requireAllDeactivators);
            EditorGUILayout.EndHorizontal();

            // update dependencies list in gazable (gazables may have been removed in the hierarchy)
            if (targetConditions.DeactivateOnDependencyMap.dependencies.Count > 0)
            {
                // NOTE don't use foreach to avoid InvalidOperationException
                for (int i = 0; i < targetConditions.DeactivateOnDependencyMap.dependencies.Count; i++)
                {
                    if (!hierarchyInteractions.Contains(targetConditions.DeactivateOnDependencyMap.dependencies[i].dependentGameObject))
                    {
                        targetConditions.DeactivateOnDependencyMap.Delete(targetConditions.DeactivateOnDependencyMap.dependencies[i]);
                    }
                }
            }

            // display all existing dependencies in the Gazable
            for (int i = 0; i < targetConditions.DeactivateOnDependencyMap.dependencies.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();

                var activateDependency = EditorGUILayout.ObjectField(targetConditions.DeactivateOnDependencyMap.dependencies[i].dependentGameObject, typeof(Gaze_Conditions), true);

                if (activateDependency != null)
                {
                    if (activateDependency is Gaze_Conditions)
                    {
                        targetConditions.DeactivateOnDependencyMap.dependencies[i].dependentGameObject = ((Gaze_Conditions)activateDependency).gameObject;
                    }
                    else
                    {
                        targetConditions.DeactivateOnDependencyMap.dependencies[i].dependentGameObject = (GameObject)activateDependency;
                    }
                }

                targetConditions.DeactivateOnDependencyMap.dependencies[i].triggerStateIndex = EditorGUILayout.Popup(targetConditions.DeactivateOnDependencyMap.dependencies[i].triggerStateIndex, Enum.GetNames(typeof(DependencyTriggerEventsAndStates)));

                // if dependent on Trigger event
                targetConditions.DeactivateOnDependencyMap.dependencies[i].onTrigger = targetConditions.DeactivateOnDependencyMap.dependencies[i].triggerStateIndex == (int)DependencyTriggerEventsAndStates.Triggered;

                if (GUILayout.Button("-"))
                {
                    targetConditions.DeactivateOnDependencyMap.Delete(targetConditions.DeactivateOnDependencyMap.dependencies[i]);
                }
                EditorGUILayout.EndHorizontal();
            }

            // display 'add' button
            if (GUILayout.Button("+"))
            {
                Gaze_Dependency d = targetConditions.DeactivateOnDependencyMap.Add(targetConditions);
                EditorGUILayout.BeginHorizontal();
                d.dependentGameObject = hierarchyInteractions[EditorGUILayout.Popup(0, hierarchyInteractionsNames.ToArray())];
                d.triggerStateIndex   = (int)DependencyTriggerEventsAndStates.Triggered;
                if (GUILayout.Button("-"))
                {
                    targetConditions.DeactivateOnDependencyMap.Delete(d);
                }
                EditorGUILayout.EndHorizontal();
            }
        }