Пример #1
0
        private void DrawButton_Generate()
        {
            if (!GUILayout.Button("Generate"))
            {
                return;
            }

            GenerateEnum.Generate(this);
            EditorHelper.UnfocusControl();
        }
Пример #2
0
        /// <summary>
        /// Draws the data for generating a single enum's entries.
        /// If drawCallback is null, the default draw method is used.
        /// If drawCallback is not null, the default draw method may or may not be called.
        /// If drawCallbackReplacesDefault is true, the default is not called,
        /// otherwise the default is called and then the given callback is.
        /// </summary>
        public void DrawInspector(
            Callback <int> drawCallback, bool drawCallbackReplacesDefault,
            Callback <int> addCallback, Callback <int> delCallback,
            Callback <int> moveUpCallback, Callback <int> moveDownCallback,
            params DrawSettings[] settings)
        {
            //	Turn settings into bools
            List <DrawSettings> listSettings = new List <DrawSettings> (settings);
            bool automaticGeneration         = listSettings.Contains(DrawSettings.AutomaticGeneration);
            bool drawPath = listSettings.Contains(DrawSettings.DrawPath);
            bool drawType = listSettings.Contains(DrawSettings.DrawType);

            showData = EditorGUILayout.Toggle("Show " + enumType + " Data", showData);
            if (!showData)
            {
                return;
            }

            if (drawPath)
            {
                enumPath = EditorGUILayout.TextField("Path", enumPath);
            }
            if (drawType)
            {
                enumType = EditorGUILayout.TextField("Type", enumType);
            }

            EditorGUILayout.BeginHorizontal();

            if (!automaticGeneration)
            {
                if (Application.isPlaying)
                {
                    EditorGUILayout.LabelField("Generation disabled while playing.");
                }
                else
                {
                    DrawButton_Generate();
                }
            }

            DrawButton_LoadExisting();
            EditorGUILayout.Space();

            EditorGUILayout.EndHorizontal();

            // Make the draw callback act like the enumName and enumID are one unit.
            // Makes drawing a list of Enum_Datas a lot smoother than having a list of
            // enum names followed by another list with enum IDs.
            Callback <int> defaultDrawCallback = DrawEnumName;

            if (!automaticGeneration)
            {
                defaultDrawCallback += DrawEnumID;
            }

            Callback <int> actualDrawCallback = defaultDrawCallback;

            if (drawCallback != null)
            {
                if (drawCallbackReplacesDefault)
                {
                    actualDrawCallback = drawCallback;
                }
                else
                {
                    actualDrawCallback += drawCallback;
                }
            }

            if (_generateNextDraw)
            {
                GenerateEnum.Generate(this, true);
                _generateNextDraw = false;
            }

            bool drawList = true;
            bool modded   = EditorHelper.DrawResizableList <SingleEnum_Data> ("Enum Values", ref drawList, ref enumValues, actualDrawCallback, addCallback, delCallback, moveUpCallback, moveDownCallback);

            if (modded && automaticGeneration)
            {
                _generateNextDraw = true;
            }
        }