public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (instance == null)
            {
                Awake(); return;
            }

            GUI.changed = false;

            EditorGUILayout.Space();

            PrefabType type = PrefabUtility.GetPrefabType(instance);

            if (type == PrefabType.Prefab || type == PrefabType.PrefabInstance)
            {
                UnitCreep prefab = instance;
                if (type == PrefabType.PrefabInstance)
                {
                    prefab = (UnitCreep)PrefabUtility.GetPrefabParent(instance);
                }
                bool existInDB = CreepDB.GetPrefabIndex(prefab) >= 0;

                if (!existInDB)
                {
                    if (instance.prefabID >= 0)
                    {
                        instance.prefabID = -1; EditorUtility.SetDirty(instance);
                    }

                    EditorGUILayout.Space();

                    EditorGUILayout.HelpBox("This prefab hasn't been added to database hence it won't be accessible to the game.", MessageType.Warning);
                    GUI.color = new Color(1f, 0.7f, .2f, 1f);
                    if (GUILayout.Button("Add Prefab to Database"))
                    {
                        UnitCreepEditorWindow.Init();
                        UnitCreepEditorWindow.NewItem(instance);
                        UnitCreepEditorWindow.Init();                                   //call again to select the instance in editor window
                    }
                    GUI.color = Color.white;
                }
                else
                {
                    EditorGUILayout.HelpBox("Editing creep using Inspector is not recommended.\nPlease use the editor window instead", MessageType.Info);
                    if (GUILayout.Button("Creep Editor Window"))
                    {
                        UnitCreepEditorWindow.Init(instance.prefabID);
                    }
                }

                EditorGUILayout.Space();
            }
            else
            {
                if (instance.prefabID >= 0)
                {
                    instance.prefabID = -1; EditorUtility.SetDirty(instance);
                }

                string text = "Creep object won't be available to be deployed to game, or accessible in TDTK editor until it's made a prefab and added to TDTK database.";
                text += "\n\nYou can still edit the creep using default inspector. However it's not recommended";
                EditorGUILayout.HelpBox(text, MessageType.Warning);

                EditorGUILayout.Space();
                if (GUILayout.Button("Creep Editor Window"))
                {
                    UnitCreepEditorWindow.Init(instance.prefabID);
                }
            }


            DefaultInspector();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }
Beispiel #2
0
        public override bool OnGUI()
        {
            if (!base.OnGUI())
            {
                return(true);
            }

            if (window == null)
            {
                Init();
            }

            if (instance == null && !GetSpawnManager())
            {
                return(true);
            }

            Undo.RecordObject(this, "window");
            Undo.RecordObject(instance, "SpawnManager");

            UpdateProceduralUnitList();

            configureProcedural = instance.spawnLimit == SpawnManager._SpawnLimit.Infinite | configureProceduralSetting | instance.procedurallyGenerateWave;

            if (instance.spawnLimit == SpawnManager._SpawnLimit.Finite && !instance.procedurallyGenerateWave)
            {
                string text = configureProceduralSetting ? "Wave List" : "Configuration";
                if (GUI.Button(new Rect(window.position.width - 130, 5, 125, 25), text))
                {
                    configureProceduralSetting = !configureProceduralSetting;
                }

                if (!configureProceduralSetting)
                {
                    GUI.color = new Color(0, 1, 1, 1);
                    cont      = new GUIContent("Auto Generate", "Procedurally generate all the waves\nCAUTION: overwirte all existing wave!");
                    if (GUI.Button(new Rect(window.position.width - 130, 35, 125, 25), cont))
                    {
                        for (int i = 0; i < instance.waveList.Count; i++)
                        {
                            instance.waveList[i] = instance.waveGenerator.Generate(i);
                        }
                    }
                    GUI.color = Color.white;
                }
            }

            if (GUI.Button(new Rect(window.position.width - 130, 110, 125, 25), "Save"))
            {
                SetDirtyTD();
            }

            if (GUI.Button(new Rect(window.position.width - 130, 80, 125, 25), "Creep Editor"))
            {
                UnitCreepEditorWindow.Init();
            }


            float startX = 5; float startY = 5;

            startY = DrawGeneralSetting(startX, startY) + 10;

            if (!configureProcedural)
            {
                EditorGUI.LabelField(new Rect(startX, startY, 2 * width, height), "Spawn Info (wave list)", headerStyle);
            }
            else
            {
                EditorGUI.LabelField(new Rect(startX, startY, 2 * width, height), "Procedural Wave Generation Parameters", headerStyle);
            }


            startY += spaceY;
            Rect visibleRect = new Rect(startX, startY, window.position.width - startX * 2, window.position.height - (startY + 5));
            Rect contentRect = new Rect(startX, startY, contentWidth - 25, contentHeight);


            GUI.color = new Color(.8f, .8f, .8f, 1f);
            GUI.Box(visibleRect, "");
            GUI.color = Color.white;


            scrollPos = GUI.BeginScrollView(visibleRect, scrollPos, contentRect);

            if (configureProcedural)
            {
                startY = DrawProceduralSetting(startX += 5, startY += 5) + 10;

                contentWidth  = proUnitItemWidth + 10;
                contentHeight = startY - visibleRect.y;
            }
            else
            {
                startY = DrawSpawnInfo(startX += 5, startY += 5);

                maxSubWaveSize = 1;
                for (int i = 0; i < instance.waveList.Count; i++)
                {
                    maxSubWaveSize = Mathf.Max(instance.waveList[i].subWaveList.Count, maxSubWaveSize);
                }

                contentWidth  = (subWaveBoxWidth + 10) * maxSubWaveSize + 60;
                contentHeight = startY - visibleRect.y;
            }

            GUI.EndScrollView();


            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
            if (GUI.changed)
            {
                SetDirtyTD();
            }

            return(true);
        }
 static void OpenCreepEditor()
 {
     UnitCreepEditorWindow.Init();
 }