// Token: 0x060002BE RID: 702 RVA: 0x0001B430 File Offset: 0x00019630
        private static bool DrawSharedVariable(IVariableSource variableSource, SharedVariable sharedVariable, bool selected)
        {
            if (sharedVariable == null || sharedVariable.GetType().GetProperty("Value") == null)
            {
                return(false);
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            bool result = false;

            if (!string.IsNullOrEmpty(sharedVariable.PropertyMapping))
            {
                if (selected)
                {
                    GUILayout.Label("Property", new GUILayoutOption[0]);
                }
                else
                {
                    GUILayout.Label(sharedVariable.Name, new GUILayoutOption[0]);
                }
                string[] array = sharedVariable.PropertyMapping.Split(new char[]
                {
                    '.'
                });
                GUILayout.Label(array[array.Length - 1].Replace('/', '.'), new GUILayoutOption[0]);
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                FieldInspector.DrawFields(null, sharedVariable, new GUIContent(sharedVariable.Name));
                result = EditorGUI.EndChangeCheck();
            }
            if (!sharedVariable.IsGlobal && GUILayout.Button(BehaviorDesignerUtility.VariableMapButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(19f)
            }))
            {
                VariableInspector.ShowPropertyMappingMenu(variableSource as BehaviorSource, sharedVariable);
            }
            GUILayout.EndHorizontal();
            return(result);
        }
Esempio n. 2
0
 public static bool DrawInspectorGUI(BehaviorSource behaviorSource, bool fromInspector, ref bool showVariables)
 {
     EditorGUI.BeginChangeCheck();
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     EditorGUILayout.LabelField("Behavior Name", new GUILayoutOption[]
     {
         GUILayout.Width(120f)
     });
     behaviorSource.behaviorName = EditorGUILayout.TextField(behaviorSource.behaviorName, new GUILayoutOption[0]);
     if (fromInspector && GUILayout.Button("Open", new GUILayoutOption[0]))
     {
         BehaviorDesignerWindow.ShowWindow();
         BehaviorDesignerWindow.instance.LoadBehavior(behaviorSource, false, true);
     }
     GUILayout.EndHorizontal();
     EditorGUILayout.LabelField("Behavior Description", new GUILayoutOption[0]);
     behaviorSource.behaviorDescription = EditorGUILayout.TextArea(behaviorSource.behaviorDescription, new GUILayoutOption[]
     {
         GUILayout.Height(48f)
     });
     if (fromInspector && (showVariables = EditorGUILayout.Foldout(showVariables, "Variables")))
     {
         List <SharedVariable> allVariables = behaviorSource.GetAllVariables();
         if (allVariables != null && VariableInspector.DrawAllVariables(false, behaviorSource, ref allVariables, false, ref ExternalBehaviorInspector.variablePosition, ref ExternalBehaviorInspector.selectedVariableIndex, ref ExternalBehaviorInspector.selectedVariableName, ref ExternalBehaviorInspector.selectedVariableTypeIndex, true, false))
         {
             if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
             {
                 BinarySerialization.Save(behaviorSource);
             }
             else
             {
                 SerializeJSON.Save(behaviorSource);
             }
         }
     }
     return(EditorGUI.EndChangeCheck());
 }
        private static bool DrawSelectedVariable(IVariableSource variableSource, ref List <SharedVariable> variables, SharedVariable sharedVariable, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex, ref bool deleted)
        {
            bool result = false;

            GUILayout.BeginVertical(BehaviorDesignerUtility.SelectedBackgroundGUIStyle, new GUILayoutOption[0]);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Label("Name", new GUILayoutOption[]
            {
                GUILayout.Width(70f)
            });
            EditorGUI.BeginChangeCheck();
            selectedVariableName = GUILayout.TextField(selectedVariableName, new GUILayoutOption[]
            {
                GUILayout.Width(140f)
            });
            if (EditorGUI.EndChangeCheck())
            {
                if (VariableInspector.VariableNameValid(variableSource, selectedVariableName))
                {
                    variableSource.UpdateVariableName(sharedVariable, selectedVariableName);
                }
                result = true;
            }
            GUILayout.Space(10f);
            bool enabled = GUI.enabled;

            GUI.enabled = (enabled && selectedVariableIndex < variables.Count - 1);
            if (GUILayout.Button(BehaviorDesignerUtility.DownArrowButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(19f)
            }))
            {
                SharedVariable value = variables[selectedVariableIndex + 1];
                variables[selectedVariableIndex + 1] = variables[selectedVariableIndex];
                variables[selectedVariableIndex]     = value;
                selectedVariableIndex++;
                result = true;
            }
            GUI.enabled = (enabled && (selectedVariableIndex < variables.Count - 1 || selectedVariableIndex != 0));
            GUILayout.Box(string.Empty, BehaviorDesignerUtility.ArrowSeparatorGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(1f),
                GUILayout.Height(18f)
            });
            GUI.enabled = (enabled && selectedVariableIndex != 0);
            if (GUILayout.Button(BehaviorDesignerUtility.UpArrowButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(20f)
            }))
            {
                SharedVariable value2 = variables[selectedVariableIndex - 1];
                variables[selectedVariableIndex - 1] = variables[selectedVariableIndex];
                variables[selectedVariableIndex]     = value2;
                selectedVariableIndex--;
                result = true;
            }
            GUI.enabled = enabled;
            if (GUILayout.Button(BehaviorDesignerUtility.VariableDeleteButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(19f)
            }) && EditorUtility.DisplayDialog("Delete Variable", "Are you sure you want to delete this variable?", "Yes", "No"))
            {
                deleted = true;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(2f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Label("Type", new GUILayoutOption[]
            {
                GUILayout.Width(70f)
            });
            EditorGUI.BeginChangeCheck();
            selectedVariableTypeIndex = EditorGUILayout.Popup(selectedVariableTypeIndex, VariableInspector.sharedVariableStrings, EditorStyles.toolbarPopup, new GUILayoutOption[]
            {
                GUILayout.Width(200f)
            });
            if (EditorGUI.EndChangeCheck() && VariableInspector.sharedVariableTypesDict[sharedVariable.GetType().Name] != selectedVariableTypeIndex)
            {
                if (BehaviorDesignerWindow.instance != null)
                {
                    BehaviorDesignerWindow.instance.RemoveSharedVariableReferences(sharedVariable);
                }
                sharedVariable = VariableInspector.CreateVariable(selectedVariableTypeIndex, sharedVariable.Name, sharedVariable.IsGlobal);
                variables[selectedVariableIndex] = sharedVariable;
                result = true;
            }
            GUILayout.EndHorizontal();
            EditorGUI.BeginChangeCheck();
            GUILayout.Space(4f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUI.enabled = VariableInspector.CanNetworkSync(sharedVariable.GetType().GetProperty("Value").PropertyType);
            EditorGUI.BeginChangeCheck();
            sharedVariable.NetworkSync = EditorGUILayout.Toggle(new GUIContent("Network Sync", "Sync this variable over the network. Requires Unity 5.1 or greator. A NetworkIdentity must be attached to the behavior tree GameObject."), sharedVariable.NetworkSync, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                result = true;
            }
            GUILayout.EndHorizontal();
            GUI.enabled = enabled;
            if (VariableInspector.DrawSharedVariable(variableSource, sharedVariable, true))
            {
                result = true;
            }
            BehaviorDesignerUtility.DrawContentSeperator(4, 7);
            GUILayout.EndVertical();
            GUILayout.Space(3f);
            return(result);
        }
        public static bool DrawAllVariables(bool showFooter, IVariableSource variableSource, ref List <SharedVariable> variables, bool canSelect, ref List <float> variablePosition, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex, bool drawRemoveButton, bool drawLastSeparator)
        {
            if (variables == null)
            {
                return(false);
            }
            bool result = false;

            if (canSelect && variablePosition == null)
            {
                variablePosition = new List <float>();
            }
            for (int i = 0; i < variables.Count; i++)
            {
                SharedVariable sharedVariable = variables[i];
                if (sharedVariable != null)
                {
                    if (canSelect && selectedVariableIndex == i)
                    {
                        if (i == 0)
                        {
                            GUILayout.Space(2f);
                        }
                        bool flag = false;
                        if (VariableInspector.DrawSelectedVariable(variableSource, ref variables, sharedVariable, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex, ref flag))
                        {
                            result = true;
                        }
                        if (flag)
                        {
                            if (BehaviorDesignerWindow.instance != null)
                            {
                                BehaviorDesignerWindow.instance.RemoveSharedVariableReferences(sharedVariable);
                            }
                            variables.RemoveAt(i);
                            if (selectedVariableIndex == i)
                            {
                                selectedVariableIndex = -1;
                            }
                            else if (selectedVariableIndex > i)
                            {
                                selectedVariableIndex--;
                            }
                            result = true;
                            break;
                        }
                    }
                    else
                    {
                        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        if (VariableInspector.DrawSharedVariable(variableSource, sharedVariable, false))
                        {
                            result = true;
                        }
                        if (drawRemoveButton && GUILayout.Button(BehaviorDesignerUtility.VariableDeleteButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
                        {
                            GUILayout.Width(19f)
                        }) && EditorUtility.DisplayDialog("Delete Variable", "Are you sure you want to delete this variable?", "Yes", "No"))
                        {
                            if (BehaviorDesignerWindow.instance != null)
                            {
                                BehaviorDesignerWindow.instance.RemoveSharedVariableReferences(sharedVariable);
                            }
                            variables.RemoveAt(i);
                            if (canSelect)
                            {
                                if (selectedVariableIndex == i)
                                {
                                    selectedVariableIndex = -1;
                                }
                                else if (selectedVariableIndex > i)
                                {
                                    selectedVariableIndex--;
                                }
                            }
                            result = true;
                            break;
                        }
                        GUILayout.Space(10f);
                        GUILayout.EndHorizontal();
                        if (i != variables.Count - 1 || drawLastSeparator)
                        {
                            BehaviorDesignerUtility.DrawContentSeperator(2, 7);
                        }
                    }
                    GUILayout.Space(4f);
                    if (canSelect && Event.current.type == EventType.Repaint)
                    {
                        if (variablePosition.Count <= i)
                        {
                            variablePosition.Add(GUILayoutUtility.GetLastRect().yMax);
                        }
                        else
                        {
                            variablePosition[i] = GUILayoutUtility.GetLastRect().yMax;
                        }
                    }
                }
            }
            if (canSelect && variables.Count < variablePosition.Count)
            {
                for (int j = variablePosition.Count - 1; j >= variables.Count; j--)
                {
                    variablePosition.RemoveAt(j);
                }
            }
            if (showFooter && variables.Count > 0)
            {
                GUI.enabled = true;
                GUILayout.Label("Select a variable to change its properties.", BehaviorDesignerUtility.LabelWrapGUIStyle, new GUILayoutOption[0]);
            }
            return(result);
        }
        private static bool DrawHeader(IVariableSource variableSource, bool fromGlobalVariablesWindow, ref float variableStartPosition, ref string variableName, ref bool focusNameField, ref int variableTypeIndex, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex)
        {
            if (VariableInspector.sharedVariableStrings == null)
            {
                VariableInspector.FindAllSharedVariableTypes(true);
            }
            EditorGUIUtility.labelWidth = 150f;
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(4f);
            EditorGUILayout.LabelField("Name", new GUILayoutOption[]
            {
                GUILayout.Width(70f)
            });
            GUI.SetNextControlName("Name");
            variableName = EditorGUILayout.TextField(variableName, new GUILayoutOption[]
            {
                GUILayout.Width(212f)
            });
            if (focusNameField)
            {
                GUI.FocusControl("Name");
                focusNameField = false;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(2f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(4f);
            GUILayout.Label("Type", new GUILayoutOption[]
            {
                GUILayout.Width(70f)
            });
            variableTypeIndex = EditorGUILayout.Popup(variableTypeIndex, VariableInspector.sharedVariableStrings, EditorStyles.toolbarPopup, new GUILayoutOption[]
            {
                GUILayout.Width(163f)
            });
            GUILayout.Space(8f);
            bool flag    = false;
            bool flag2   = VariableInspector.VariableNameValid(variableSource, variableName);
            bool enabled = GUI.enabled;

            GUI.enabled = (flag2 && enabled);
            GUI.SetNextControlName("Add");
            if (GUILayout.Button("Add", EditorStyles.toolbarButton, new GUILayoutOption[]
            {
                GUILayout.Width(40f)
            }) && flag2)
            {
                flag = VariableInspector.AddVariable(variableSource, variableName, variableTypeIndex, fromGlobalVariablesWindow);
                if (flag)
                {
                    selectedVariableIndex     = variableSource.GetAllVariables().Count - 1;
                    selectedVariableName      = variableName;
                    selectedVariableTypeIndex = variableTypeIndex;
                    variableName = string.Empty;
                }
            }
            GUILayout.Space(6f);
            GUILayout.EndHorizontal();
            if (!fromGlobalVariablesWindow)
            {
                GUI.enabled = true;
                GUILayout.Space(3f);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(5f);
                if (GUILayout.Button("Global Variables", EditorStyles.toolbarButton, new GUILayoutOption[]
                {
                    GUILayout.Width(284f)
                }))
                {
                    GlobalVariablesWindow.ShowWindow();
                }
                GUILayout.EndHorizontal();
            }
            BehaviorDesignerUtility.DrawContentSeperator(2);
            GUILayout.Space(4f);
            if (variableStartPosition == -1f && Event.current.type == EventType.Repaint)
            {
                variableStartPosition = GUILayoutUtility.GetLastRect().yMax;
            }
            GUI.enabled = enabled;
            return(flag);
        }
        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 bool DrawVariables(BehaviorSource behaviorSource, bool enabled)
 {
     return(VariableInspector.DrawVariables(behaviorSource, enabled, behaviorSource, ref this.mVariableName, ref this.mFocusNameField, ref this.mVariableTypeIndex, ref this.mScrollPosition, ref this.mVariablePosition, ref this.mVariableStartPosition, ref this.mSelectedVariableIndex, ref this.mSelectedVariableName, ref this.mSelectedVariableTypeIndex));
 }
 public bool LeftMouseDown(IVariableSource variableSource, BehaviorSource behaviorSource, Vector2 mousePosition)
 {
     return(VariableInspector.LeftMouseDown(variableSource, behaviorSource, mousePosition, this.mVariablePosition, this.mVariableStartPosition, this.mScrollPosition, ref this.mSelectedVariableIndex, ref this.mSelectedVariableName, ref this.mSelectedVariableTypeIndex));
 }
        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);
        }
        // Token: 0x060002BB RID: 699 RVA: 0x0001ADF4 File Offset: 0x00018FF4
        private static bool DrawHeader(IVariableSource variableSource, bool fromGlobalVariablesWindow, ref float variableStartPosition, ref string variableName, ref bool focusNameField, ref int variableTypeIndex, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex)
        {
            if (VariableInspector.sharedVariableStrings == null)
            {
                VariableInspector.FindAllSharedVariableTypes(true);
            }
            EditorGUIUtility.labelWidth = 150f;
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(4f);
            EditorGUILayout.LabelField("Name", new GUILayoutOption[]
            {
                GUILayout.Width(70f)
            });
            GUI.SetNextControlName("Name");
            variableName = EditorGUILayout.TextField(variableName, new GUILayoutOption[]
            {
                GUILayout.Width(212f)
            });
            if (focusNameField)
            {
                GUI.FocusControl("Name");
                focusNameField = false;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(2f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(4f);
            GUILayout.Label("Type", new GUILayoutOption[]
            {
                GUILayout.Width(70f)
            });
            variableTypeIndex = EditorGUILayout.Popup(variableTypeIndex, VariableInspector.sharedVariableStrings, EditorStyles.toolbarPopup, new GUILayoutOption[]
            {
                GUILayout.Width(163f)
            });
            GUILayout.Space(8f);
            bool flag    = false;
            bool flag2   = VariableInspector.VariableNameValid(variableSource, variableName);
            bool enabled = GUI.enabled;

            GUI.enabled = (flag2 && enabled);
            GUI.SetNextControlName("Add");
            if (GUILayout.Button("Add", EditorStyles.toolbarButton, new GUILayoutOption[]
            {
                GUILayout.Width(40f)
            }) && flag2)
            {
                if (fromGlobalVariablesWindow && variableSource == null)
                {
                    GlobalVariables globalVariables = ScriptableObject.CreateInstance(typeof(GlobalVariables)) as GlobalVariables;
                    string          text            = BehaviorDesignerUtility.GetEditorBaseDirectory(null).Substring(6, BehaviorDesignerUtility.GetEditorBaseDirectory(null).Length - 13);
                    string          str             = text + "/Resources/BehaviorDesignerGlobalVariables.asset";
                    if (!Directory.Exists(Application.dataPath + text + "/Resources"))
                    {
                        Directory.CreateDirectory(Application.dataPath + text + "/Resources");
                    }
                    if (!File.Exists(Application.dataPath + str))
                    {
                        AssetDatabase.CreateAsset(globalVariables, "Assets" + str);
                        EditorUtility.DisplayDialog("Created Global Variables", "Behavior Designer Global Variables asset created:\n\nAssets" + text + "/Resources/BehaviorDesignerGlobalVariables.asset\n\nNote: Copy this file to transfer global variables between projects.", "OK");
                    }
                    variableSource = globalVariables;
                }
                flag = VariableInspector.AddVariable(variableSource, variableName, variableTypeIndex, fromGlobalVariablesWindow);
                if (flag)
                {
                    selectedVariableIndex     = variableSource.GetAllVariables().Count - 1;
                    selectedVariableName      = variableName;
                    selectedVariableTypeIndex = variableTypeIndex;
                    variableName = string.Empty;
                }
            }
            GUILayout.Space(6f);
            GUILayout.EndHorizontal();
            if (!fromGlobalVariablesWindow)
            {
                GUI.enabled = true;
                GUILayout.Space(3f);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(5f);
                if (GUILayout.Button("Global Variables", EditorStyles.toolbarButton, new GUILayoutOption[]
                {
                    GUILayout.Width(284f)
                }))
                {
                    GlobalVariablesWindow.ShowWindow();
                }
                GUILayout.EndHorizontal();
            }
            BehaviorDesignerUtility.DrawContentSeperator(2);
            GUILayout.Space(4f);
            if (variableStartPosition == -1f && (int)Event.current.type == 7)
            {
                variableStartPosition = GUILayoutUtility.GetLastRect().yMax;
            }
            GUI.enabled = enabled;
            return(flag);
        }