Ejemplo n.º 1
0
    private void DrawNewEnvironmentWindow()
    {
        GUILayout.Label("Create New Environment", EditorStyles.boldLabel);

        _newEnvironmentName = EditorGUILayout.TextField("Name", _newEnvironmentName);

        GUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Create"))
            {
                if (!string.IsNullOrEmpty(_newEnvironmentName))
                {
                    AddEnvironmentToMainEnvironmentCode(_newEnvironmentName);
                    SaveAllVariables();
                    _environmentEditorState = EnvironmentVariablesEditorState.EDITING;
                }
                else
                {
                    if (EditorUtility.DisplayDialog("Warning", "New Environment variable is null or empty.", "Ok"))
                    {
                        _environmentEditorState = EnvironmentVariablesEditorState.EDITING;
                    }
                }
            }

            if (GUILayout.Button("Cancel"))
            {
                _newEnvironmentName     = string.Empty;
                _environmentEditorState = EnvironmentVariablesEditorState.EDITING;
            }
        }
        GUILayout.EndHorizontal();
    }
Ejemplo n.º 2
0
    private void DrawRemoveEnvironmentWindow()
    {
        EnvironmentType[] __environmentTypeValues = (EnvironmentType[])Enum.GetValues(typeof(EnvironmentType));

        List <EnvironmentType> __listEnviromnentTypes = new List <EnvironmentType>(__environmentTypeValues);

        __listEnviromnentTypes.Remove(EnvironmentType.Production);
        __listEnviromnentTypes.Remove(EnvironmentType.Development);
        __listEnviromnentTypes.Remove(EnvironmentType.Test);

        if (__listEnviromnentTypes.Count > 0)
        {
            string[] __enumOptions       = new string[__listEnviromnentTypes.Count];
            int[]    __enumOptionsValues = new int[__listEnviromnentTypes.Count];

            for (int i = 0; i < __listEnviromnentTypes.Count; i++)
            {
                if (_toRemoveEnvironmentIndex == -1)
                {
                    _toRemoveEnvironmentIndex = (int)__listEnviromnentTypes[i];
                }
                __enumOptions[i]       = __listEnviromnentTypes[i].ToString();
                __enumOptionsValues[i] = (int)__listEnviromnentTypes[i];
            }

            _toRemoveEnvironmentIndex = EditorGUILayout.IntPopup("Build Target", _toRemoveEnvironmentIndex, __enumOptions, __enumOptionsValues);

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Remove"))
                {
                    RemoveEnvironmentToMainEnvironmentCode((EnvironmentType)_toRemoveEnvironmentIndex);
                    _environmentEditorState   = EnvironmentVariablesEditorState.EDITING;
                    _toRemoveEnvironmentIndex = -1;
                    LoadData();
                }

                if (GUILayout.Button("Cancel"))
                {
                    _toRemoveEnvironmentIndex = -1;
                    _environmentEditorState   = EnvironmentVariablesEditorState.EDITING;
                }
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            if (EditorUtility.DisplayDialog("Warning", "You must have at least one custom enviroment to remove.", "Ok"))
            {
                _environmentEditorState = EnvironmentVariablesEditorState.EDITING;
            }
        }
    }
Ejemplo n.º 3
0
    private void DrawEditingWindow()
    {
        GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.MinHeight(28));
        {
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Local Environment: ");

                EditorGUI.BeginChangeCheck();
                {
                    _currentEnvironmentSelected = (EnvironmentType)EditorGUILayout.EnumPopup(_currentEnvironmentSelected);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetInt("CurrenEditorEnvironment", (int)_currentEnvironmentSelected);
                    SaveCurrentSelectedEnvironment(_currentEnvironmentSelected);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Add Environment"))
                {
                    _environmentEditorState = EnvironmentVariablesEditorState.ADDING_ENVIRONMENT;
                }

                if (GUILayout.Button("Remove Environment"))
                {
                    _environmentEditorState = EnvironmentVariablesEditorState.REMOVING_ENVIRONMENT;
                }
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();

        GUI.color = Color.white;

        DrawVariables();
    }
Ejemplo n.º 4
0
    private void DrawVariables()
    {
        GUILayout.BeginVertical(EditorStyles.helpBox);
        {
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Variables", EditorStyles.boldLabel);

                GUILayout.FlexibleSpace();
                if (HasModifications())
                {
                    GUI.color = NewColors.PaleGreen;

                    if (GUILayout.Button("Save all", GUILayout.Width(100)))
                    {
                        SaveAllVariables();
                    }
                }


                GUI.color = Color.white;
                GUI.color = Color.green;

                // Color myColor = new Color();
                // ColorUtility.TryParseHtmlString ("#99ccff", out myColor);

                GUI.color = NewColors.PowderBlue;
                if (GUILayout.Button("Add Variable"))
                {
                    _environmentEditorState = EnvironmentVariablesEditorState.ADDING_VARIABLE;
                }
            }
            GUILayout.EndHorizontal();

            GUI.color = Color.white;

            if (dictOfEnvVariablesByID.Keys.Count == 0)
            {
                GUILayout.Label("No Variables To Display");
            }
            else
            {
                _scrollPosition = GUILayout.BeginScrollView(_scrollPosition);

                foreach (string key in dictOfEnvVariablesByID.Keys)
                {
                    EnvironmentVariableData __variable = dictOfEnvVariablesByID[key];

                    GUI.backgroundColor = __variable.wasModified ? NewColors.FireBrick : Color.white;// new  Color(0.8f, 0.1f, 0.1f, 0.4f) : Color.white;

                    GUILayout.BeginVertical(EditorStyles.helpBox);
                    {
                        GUI.backgroundColor = Color.white;

                        GUILayout.BeginHorizontal();
                        {
                            __variable.isUnfolded = EditorGUILayout.Foldout(__variable.isUnfolded, string.Empty);
                            GUILayout.Space(-40);
                            GUILayout.Label("<b><size=12><color=#0066ff> " + __variable.type.ToString().ToLower() + ": </color></size></b>", _styleHtml);
                            GUILayout.Label("<b><size=12>" + __variable.id + "</size></b>", _styleHtml);

                            GUILayout.FlexibleSpace();


                            if (__variable.wasModified)
                            {
                                GUI.color = NewColors.SpringGreen;

                                if (GUILayout.Button("Save changes", GUILayout.Width(100)))
                                {
                                    if (__variable.wasModified)
                                    {
                                        __variable.wasModified = false;
                                    }

                                    SaveEnvironmentVariable(__variable, true);
                                }

                                GUI.color = NewColors.Orange;
                                if (GUILayout.Button("Revert changes", GUILayout.Width(100)))
                                {
                                    RevertChanges(__variable);
                                }
                                GUI.color = Color.white;
                            }


                            GUI.color = Color.red;

                            if (GUILayout.Button("X", GUILayout.Width(40)))
                            {
                                if (EditorUtility.DisplayDialog("Deleting variable!", "Do you want to delete it now?", "Yes", "No"))
                                {
                                    DeleteVariable(__variable);
                                }
                            }

                            GUI.color = Color.white;
                        }
                        GUILayout.EndHorizontal();

                        GUILayout.Space(4);

                        if (__variable.isUnfolded)
                        {
                            EditorGUI.BeginChangeCheck();

                            GUI.color = Color.white;
                            DrawValue(__variable);

                            if (EditorGUI.EndChangeCheck())
                            {
                                __variable.wasModified = true;
                            }
                        }
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndScrollView();
            }
        }
        GUILayout.EndVertical();
    }
Ejemplo n.º 5
0
    private void DrawNewVariableCreationWindow()
    {
        GUILayout.Label("Create New Variable", EditorStyles.boldLabel);

        EditorGUI.BeginChangeCheck();

        _newVariableName = EditorGUILayout.TextField("Name", _newVariableName);

        if (EditorGUI.EndChangeCheck())
        {
            Regex           rgx     = new Regex(VariablesNameAcceptedCharacters, RegexOptions.IgnoreCase);
            MatchCollection matches = rgx.Matches(_newVariableName);

            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    _newVariableName = match.Value;
                }
            }
        }

        EditorGUI.BeginChangeCheck();

        _newVariabletype = (VariableType)EditorGUILayout.EnumPopup("Type", _newVariabletype);
        bool __canCreateIfEnumerator = false;

        if (_newVariabletype == VariableType.ENUM)
        {
            _enumTypeStr = EditorGUILayout.TextField("Enumerator Type", _enumTypeStr);
            string __enumTypeStrConvertedToAssembly = (_enumTypeStr + ",Assembly-CSharp").Replace(".", "+");

            if (Type.GetType(__enumTypeStrConvertedToAssembly) != null)
            {
                __canCreateIfEnumerator = true;
                GUILayout.Label("It is a valid enumerator.");
            }
            else
            {
                GUILayout.Label("Not a valid enumerator.");
            }
        }

        if (EditorGUI.EndChangeCheck())
        {
            FindDefaultValueForType(_newVariabletype);
        }

        GUILayout.BeginHorizontal();
        {
            GUI.color = Color.white;

            if (string.IsNullOrEmpty(_newVariableName) == false)
            {
                GUI.color = Color.green;
            }

            if (GUILayout.Button("Create"))
            {
                Action __createCallback = () =>
                {
                    if (!string.IsNullOrEmpty(_newVariableName))
                    {
                        EnvironmentVariableData newVar = new EnvironmentVariableData();
                        _newVariableName    = _newVariableName.Substring(0, 1).ToUpper() + _newVariableName.Remove(0, 1);
                        newVar.variableName = _newVariableName;
                        newVar.id           = _newVariableName;
                        newVar.type         = _newVariabletype;
                        if (_newVariabletype == VariableType.ENUM)
                        {
                            string __enumTypeStrConvertedToAssembly = (_enumTypeStr + ",Assembly-CSharp").Replace(".", "+");
                            Type   __enumType = Type.GetType(__enumTypeStrConvertedToAssembly);
                            if (__enumType != null)
                            {
                                newVar.enumType = __enumType;
                            }
                        }

                        newVar.dictOfValuebyEnvironment.Add(EnvironmentType.Test, _defaultEmptyValue);
                        SaveEnvironmentVariable(newVar);
                        _newVariableName = string.Empty;

                        _environmentEditorState = EnvironmentVariablesEditorState.EDITING;
                    }
                };

                if (_newVariabletype == VariableType.ENUM)
                {
                    if (__canCreateIfEnumerator == true)
                    {
                        __createCallback();
                    }
                    else
                    {
                        if (EditorUtility.DisplayDialog("Warning", "The typed enum type does not exist", "Ok"))
                        {
                            _enumTypeStr = string.Empty;
                        }
                    }
                }
                else
                {
                    __createCallback();
                }
            }

            GUI.color = Color.white;

            if (GUILayout.Button("Cancel"))
            {
                _environmentEditorState = EnvironmentVariablesEditorState.EDITING;
            }
        }
    }