예제 #1
0
        private void DrawButton_Generate()
        {
            if (!GUILayout.Button("Generate"))
            {
                return;
            }

            GenerateEnum.Generate(this);
            EditorHelper.UnfocusControl();
        }
예제 #2
0
        private void DrawButton_LoadExisting()
        {
            if (!GUILayout.Button("Load Existing"))
            {
                return;
            }

            GenerateEnum.LoadExisting(this);
            EditorHelper.UnfocusControl();
        }
예제 #3
0
        /// <summary>
        /// Using theData.enumType, finds the existing compiled enum values.
        /// Then loads theData.enumValues with the found existing values.
        /// If no enum type is found, exits without changing theData.enumValues.
        /// </summary>
        public static void LoadExisting(GenerateEnum_Data theData)
        {
            theData.enumValues.Clear();

            //	Get Type by string
            System.Type theType = EditorHelper.GetEnumType(theData.enumType);
            if (theType == null)
            {
                return;
            }

            List <string> values = GenerateEnum.FindValuesByType(theData.enumType);

            for (int i = 0; i < values.Count; i++)
            {
                //	Turn enum value string into int value
                int enumID = System.Convert.ToInt32(System.Enum.Parse(theType, values[i]));
                //	Add to given data structure, theData.enumValues
                theData.enumValues.Add(new GenerateEnum_Data.SingleEnum_Data(values[i], enumID));
            }
        }
예제 #4
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;
            }
        }