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);
 }
        private static bool AddVariable(IVariableSource variableSource, string variableName, int variableTypeIndex, bool fromGlobalVariablesWindow)
        {
            SharedVariable        item = VariableInspector.CreateVariable(variableTypeIndex, variableName, fromGlobalVariablesWindow);
            List <SharedVariable> list = (variableSource == null) ? null : variableSource.GetAllVariables();

            if (list == null)
            {
                list = new List <SharedVariable>();
            }
            list.Add(item);
            GUI.FocusControl("Add");
            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;
            }
            variableSource.SetAllVariables(list);
            return(true);
        }
        // Token: 0x060002B9 RID: 697 RVA: 0x0001AB2C File Offset: 0x00018D2C
        public static bool DrawVariables(IVariableSource variableSource, 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]);
            bool flag  = false;
            bool flag2 = false;
            List <SharedVariable> list = (variableSource == null) ? null : variableSource.GetAllVariables();

            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 = !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();
            if (flag && !EditorApplication.isPlayingOrWillChangePlaymode && behaviorSource != null && behaviorSource.Owner is Behavior)
            {
                Behavior behavior = behaviorSource.Owner as Behavior;
                if (behavior.ExternalBehavior != null)
                {
                    if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
                    {
                        BinarySerialization.Save(behaviorSource);
                    }
                    else
                    {
                        JSONSerialization.Save(behaviorSource);
                    }
                    BehaviorSource behaviorSource2 = behavior.ExternalBehavior.GetBehaviorSource();
                    behaviorSource2.CheckForSerialization(true, null);
                    VariableInspector.SyncVariables(behaviorSource2, list);
                }
            }
            return(flag);
        }
        // Token: 0x060002BC RID: 700 RVA: 0x0001B100 File Offset: 0x00019300
        private static bool AddVariable(IVariableSource variableSource, string variableName, int variableTypeIndex, bool fromGlobalVariablesWindow)
        {
            SharedVariable        item = VariableInspector.CreateVariable(variableTypeIndex, variableName, fromGlobalVariablesWindow);
            List <SharedVariable> list = (variableSource == null) ? null : variableSource.GetAllVariables();

            if (list == null)
            {
                list = new List <SharedVariable>();
            }
            list.Add(item);
            variableSource.SetAllVariables(list);
            return(true);
        }
        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);
        }
        // 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);
        }