示例#1
0
        public static bool DrawInspectorGUI(Behavior behavior, SerializedObject serializedObject, bool fromInspector, ref bool externalModification, ref bool showOptions, ref bool showVariables)
        {
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            EditorGUILayout.LabelField("Behavior Name", new GUILayoutOption[]
            {
                GUILayout.Width(120f)
            });
            behavior.GetBehaviorSource().behaviorName = EditorGUILayout.TextField(behavior.GetBehaviorSource().behaviorName, new GUILayoutOption[0]);
            if (fromInspector && GUILayout.Button("Open", new GUILayoutOption[0]))
            {
                BehaviorDesignerWindow.ShowWindow();
                BehaviorDesignerWindow.instance.LoadBehavior(behavior.GetBehaviorSource(), false, true);
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.LabelField("Behavior Description", new GUILayoutOption[0]);
            behavior.GetBehaviorSource().behaviorDescription = EditorGUILayout.TextArea(behavior.GetBehaviorSource().behaviorDescription, BehaviorDesignerUtility.TaskInspectorCommentGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Height(48f)
            });
            serializedObject.Update();
            GUI.enabled = PrefabUtility.GetPrefabInstanceStatus(behavior) != PrefabInstanceStatus.MissingAsset || BehaviorDesignerPreferences.GetBool(BDPreferences.EditablePrefabInstances);
            SerializedProperty serializedProperty = serializedObject.FindProperty("externalBehavior");
            ExternalBehavior   externalBehavior   = serializedProperty.objectReferenceValue as ExternalBehavior;

            EditorGUILayout.PropertyField(serializedProperty, true, new GUILayoutOption[0]);
            serializedObject.ApplyModifiedProperties();
            if ((!(behavior.ExternalBehavior is null) && !behavior.ExternalBehavior.Equals(externalBehavior)) || (!ReferenceEquals(externalBehavior, null) && !externalBehavior.Equals(behavior.ExternalBehavior)))
            {
                if (!(behavior.ExternalBehavior is null))
                {
                    behavior.ExternalBehavior.BehaviorSource.Owner = behavior.ExternalBehavior;
                    behavior.ExternalBehavior.BehaviorSource.CheckForSerialization(true, behavior.GetBehaviorSource());
                }
 public static bool LeftMouseDown(IVariableSource variableSource, BehaviorSource behaviorSource, Vector2 mousePosition, List <float> variablePosition, float variableStartPosition, Vector2 scrollPosition, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex)
 {
     if (variablePosition != null && mousePosition.y > variableStartPosition && variableSource != null)
     {
         List <SharedVariable> allVariables;
         if (!Application.isPlaying && behaviorSource != null && behaviorSource.Owner is Behavior)
         {
             Behavior behavior = behaviorSource.Owner as Behavior;
             if (behavior.ExternalBehavior != null)
             {
                 BehaviorSource behaviorSource2 = behavior.GetBehaviorSource();
                 behaviorSource2.CheckForSerialization(true, null);
                 allVariables = behaviorSource2.GetAllVariables();
                 ExternalBehavior externalBehavior = behavior.ExternalBehavior;
                 externalBehavior.BehaviorSource.Owner = externalBehavior;
                 externalBehavior.BehaviorSource.CheckForSerialization(true, behaviorSource);
             }
             else
             {
                 allVariables = variableSource.GetAllVariables();
             }
         }
         else
         {
             allVariables = variableSource.GetAllVariables();
         }
         if (allVariables == null || allVariables.Count != variablePosition.Count)
         {
             return(false);
         }
         int i = 0;
         while (i < variablePosition.Count)
         {
             if (mousePosition.y < variablePosition[i] - scrollPosition.y)
             {
                 if (i == selectedVariableIndex)
                 {
                     return(false);
                 }
                 selectedVariableIndex     = i;
                 selectedVariableName      = allVariables[i].Name;
                 selectedVariableTypeIndex = VariableInspector.sharedVariableTypesDict[allVariables[i].GetType().Name];
                 return(true);
             }
             else
             {
                 i++;
             }
         }
     }
     if (selectedVariableIndex != -1)
     {
         selectedVariableIndex = -1;
         return(true);
     }
     return(false);
 }
示例#3
0
        public void Reset()
        {
            ExternalBehavior externalBehavior = this.target as ExternalBehavior;

            if (externalBehavior == null)
            {
                return;
            }
            if (externalBehavior.BehaviorSource.Owner == null)
            {
                externalBehavior.BehaviorSource.Owner = externalBehavior;
            }
        }
示例#4
0
        public override void OnInspectorGUI()
        {
            ExternalBehavior externalBehavior = this.target as ExternalBehavior;

            if (externalBehavior == null)
            {
                return;
            }
            if (ExternalBehaviorInspector.DrawInspectorGUI(externalBehavior.BehaviorSource, true, ref this.mShowVariables))
            {
                EditorUtility.SetDirty(externalBehavior);
            }
        }
        private static void PropertySelected(object selected)
        {
            bool flag = false;

            if (!Application.isPlaying && VariableInspector.mPropertyMappingBehaviorSource.Owner.GetObject() is Behavior && (VariableInspector.mPropertyMappingBehaviorSource.Owner.GetObject() as Behavior).ExternalBehavior != null)
            {
                VariableInspector.mPropertyMappingBehaviorSource.CheckForSerialization(true, null);
                VariableInspector.mPropertyMappingVariable = VariableInspector.mPropertyMappingBehaviorSource.GetVariable(VariableInspector.mPropertyMappingVariable.Name);
                flag = true;
            }
            VariableInspector.SelectedPropertyMapping selectedPropertyMapping = selected as VariableInspector.SelectedPropertyMapping;
            if (selectedPropertyMapping.Property.Equals("None"))
            {
                VariableInspector.mPropertyMappingVariable.PropertyMapping      = string.Empty;
                VariableInspector.mPropertyMappingVariable.PropertyMappingOwner = null;
            }
            else
            {
                VariableInspector.mPropertyMappingVariable.PropertyMapping      = selectedPropertyMapping.Property;
                VariableInspector.mPropertyMappingVariable.PropertyMappingOwner = selectedPropertyMapping.GameObject;
            }
            if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
            {
                BinarySerialization.Save(VariableInspector.mPropertyMappingBehaviorSource);
            }
            else
            {
                SerializeJSON.Save(VariableInspector.mPropertyMappingBehaviorSource);
            }
            if (flag)
            {
                ExternalBehavior externalBehavior = (VariableInspector.mPropertyMappingBehaviorSource.Owner as Behavior).ExternalBehavior;
                externalBehavior.BehaviorSource.Owner = externalBehavior;
                externalBehavior.BehaviorSource.CheckForSerialization(true, VariableInspector.mPropertyMappingBehaviorSource);
            }
        }
        public static bool DrawVariables(IVariableSource variableSource, bool enabled, BehaviorSource behaviorSource, ref string variableName, ref bool focusNameField, ref int variableTypeIndex, ref Vector2 scrollPosition, ref List <float> variablePosition, ref float variableStartPosition, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex)
        {
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, new GUILayoutOption[0]);
            GUI.enabled    = enabled;
            bool flag  = false;
            bool flag2 = false;
            List <SharedVariable> list = (variableSource == null) ? null : variableSource.GetAllVariables();

            if (!Application.isPlaying && behaviorSource != null && behaviorSource.Owner is Behavior)
            {
                Behavior behavior = behaviorSource.Owner as Behavior;
                if (behavior.ExternalBehavior != null)
                {
                    flag2       = true;
                    GUI.enabled = false;
                    BehaviorSource behaviorSource2 = behavior.GetBehaviorSource();
                    behaviorSource2.CheckForSerialization(true, null);
                    if (VariableInspector.DrawHeader(behaviorSource2, false, ref variableStartPosition, ref variableName, ref focusNameField, ref variableTypeIndex, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex))
                    {
                        flag = true;
                    }
                    GUI.enabled = enabled;
                    if (VariableInspector.SyncVariables(behaviorSource2, list))
                    {
                        flag = true;
                    }
                    List <SharedVariable> allVariables = behaviorSource2.GetAllVariables();
                    if (VariableInspector.DrawAllVariables(true, behaviorSource, ref allVariables, false, ref variablePosition, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex, false, true))
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
                        {
                            BinarySerialization.Save(behaviorSource2);
                        }
                        else
                        {
                            SerializeJSON.Save(behaviorSource2);
                        }
                    }
                    ExternalBehavior externalBehavior = (behaviorSource.Owner as Behavior).ExternalBehavior;
                    externalBehavior.BehaviorSource.Owner = externalBehavior;
                    externalBehavior.BehaviorSource.CheckForSerialization(true, behaviorSource);
                }
            }
            if (!flag2)
            {
                if (VariableInspector.DrawHeader(variableSource, behaviorSource == null, ref variableStartPosition, ref variableName, ref focusNameField, ref variableTypeIndex, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex))
                {
                    flag = true;
                }
                list = ((variableSource == null) ? null : variableSource.GetAllVariables());
                if (list != null && list.Count > 0)
                {
                    GUI.enabled = (enabled && !flag2);
                    if (VariableInspector.DrawAllVariables(true, variableSource, ref list, true, ref variablePosition, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex, true, true))
                    {
                        flag = true;
                    }
                }
                if (flag && variableSource != null)
                {
                    variableSource.SetAllVariables(list);
                }
            }
            GUI.enabled = true;
            GUILayout.EndScrollView();
            return(flag);
        }
        public static bool DrawInspectorGUI(Behavior behavior, SerializedObject serializedObject, bool fromInspector, ref bool externalModification, ref bool showOptions, ref bool showVariables)
        {
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            EditorGUILayout.LabelField("Behavior Name", new GUILayoutOption[]
            {
                GUILayout.Width(120f)
            });
            behavior.GetBehaviorSource().behaviorName = EditorGUILayout.TextField(behavior.GetBehaviorSource().behaviorName, new GUILayoutOption[0]);
            if (fromInspector && GUILayout.Button("Open", new GUILayoutOption[0]))
            {
                BehaviorDesignerWindow.ShowWindow();
                BehaviorDesignerWindow.instance.LoadBehavior(behavior.GetBehaviorSource(), false, true);
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.LabelField("Behavior Description", new GUILayoutOption[0]);
            behavior.GetBehaviorSource().behaviorDescription = EditorGUILayout.TextArea(behavior.GetBehaviorSource().behaviorDescription, BehaviorDesignerUtility.TaskInspectorCommentGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Height(48f)
            });
            serializedObject.Update();
            GUI.enabled = (PrefabUtility.GetPrefabType(behavior) != PrefabType.PrefabInstance || BehaviorDesignerPreferences.GetBool(BDPreferences.EditablePrefabInstances));
            SerializedProperty serializedProperty = serializedObject.FindProperty("externalBehavior");
            ExternalBehavior   externalBehavior   = serializedProperty.objectReferenceValue as ExternalBehavior;

            EditorGUILayout.PropertyField(serializedProperty, true, new GUILayoutOption[0]);
            serializedObject.ApplyModifiedProperties();
            if ((!object.ReferenceEquals(behavior.ExternalBehavior, null) && !behavior.ExternalBehavior.Equals(externalBehavior)) || (!object.ReferenceEquals(externalBehavior, null) && !externalBehavior.Equals(behavior.ExternalBehavior)))
            {
                if (!object.ReferenceEquals(behavior.ExternalBehavior, null))
                {
                    behavior.ExternalBehavior.BehaviorSource.Owner = behavior.ExternalBehavior;
                    behavior.ExternalBehavior.BehaviorSource.CheckForSerialization(true, behavior.GetBehaviorSource());
                }
                else
                {
                    behavior.GetBehaviorSource().EntryTask     = null;
                    behavior.GetBehaviorSource().RootTask      = null;
                    behavior.GetBehaviorSource().DetachedTasks = null;
                    behavior.GetBehaviorSource().Variables     = null;
                    behavior.GetBehaviorSource().CheckForSerialization(true, null);
                    behavior.GetBehaviorSource().Variables = null;
                    if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
                    {
                        BinarySerialization.Save(behavior.GetBehaviorSource());
                    }
                    else
                    {
                        SerializeJSON.Save(behavior.GetBehaviorSource());
                    }
                }
                externalModification = true;
            }
            GUI.enabled        = true;
            serializedProperty = serializedObject.FindProperty("group");
            EditorGUILayout.PropertyField(serializedProperty, true, new GUILayoutOption[0]);
            if (fromInspector && (showVariables = EditorGUILayout.Foldout(showVariables, "Variables")))
            {
                EditorGUI.indentLevel++;
                List <SharedVariable> allVariables   = behavior.GetAllVariables();
                BehaviorSource        behaviorSource = behavior.GetBehaviorSource();
                bool flag = false;
                if (!Application.isPlaying && behavior.ExternalBehavior != null)
                {
                    behaviorSource.CheckForSerialization(true, null);
                    flag = true;
                }
                bool flag2 = false;
                if (VariableInspector.SyncVariables(behaviorSource, allVariables))
                {
                    flag2 = true;
                }
                if (allVariables != null && allVariables.Count > 0)
                {
                    List <SharedVariable> allVariables2 = behaviorSource.GetAllVariables();
                    if (VariableInspector.DrawAllVariables(false, behaviorSource, ref allVariables2, false, ref BehaviorInspector.variablePosition, ref BehaviorInspector.selectedVariableIndex, ref BehaviorInspector.selectedVariableName, ref BehaviorInspector.selectedVariableTypeIndex, false, true))
                    {
                        flag2 = true;
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("There are no variables to display", new GUILayoutOption[0]);
                }
                if (flag)
                {
                    ExternalBehavior externalBehavior2 = (behaviorSource.Owner as Behavior).ExternalBehavior;
                    externalBehavior2.BehaviorSource.Owner = externalBehavior2;
                    externalBehavior2.BehaviorSource.CheckForSerialization(true, behaviorSource);
                }
                if (flag2)
                {
                    if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
                    {
                        BinarySerialization.Save(behaviorSource);
                    }
                    else
                    {
                        SerializeJSON.Save(behaviorSource);
                    }
                }
                EditorGUI.indentLevel--;
            }
            if (!fromInspector || (showOptions = EditorGUILayout.Foldout(showOptions, "Options")))
            {
                if (fromInspector)
                {
                    EditorGUI.indentLevel++;
                }
                serializedProperty = serializedObject.FindProperty("startWhenEnabled");
                EditorGUILayout.PropertyField(serializedProperty, true, new GUILayoutOption[0]);
                serializedProperty = serializedObject.FindProperty("pauseWhenDisabled");
                EditorGUILayout.PropertyField(serializedProperty, true, new GUILayoutOption[0]);
                serializedProperty = serializedObject.FindProperty("restartWhenComplete");
                EditorGUILayout.PropertyField(serializedProperty, true, new GUILayoutOption[0]);
                serializedProperty = serializedObject.FindProperty("resetValuesOnRestart");
                EditorGUILayout.PropertyField(serializedProperty, true, new GUILayoutOption[0]);
                serializedProperty = serializedObject.FindProperty("logTaskChanges");
                EditorGUILayout.PropertyField(serializedProperty, true, new GUILayoutOption[0]);
                if (fromInspector)
                {
                    EditorGUI.indentLevel--;
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                return(true);
            }
            return(false);
        }