コード例 #1
0
        public static void Init()
        {
            // Get existing open window or if none, make a new one:
            window = (UnitTowerEditorWindow)EditorWindow.GetWindow(typeof (UnitTowerEditorWindow));
            //~ window.minSize=new Vector2(375, 449);
            //~ window.maxSize=new Vector2(375, 800);

            EditorDBManager.Init();

            UpdateObjectHierarchyList();
        }
コード例 #2
0
        public static void Init()
        {
            // Get existing open window or if none, make a new one:
            window = (UnitTowerEditorWindow)EditorWindow.GetWindow(typeof(UnitTowerEditorWindow));
            //~ window.minSize=new Vector2(375, 449);
            //~ window.maxSize=new Vector2(375, 800);

            EditorDBManager.Init();

            InitLabel();
            UpdateObjectHierarchyList();
        }
コード例 #3
0
        public static void Init(int prefabID = -1)
        {
            window         = (UnitTowerEditorWindow)EditorWindow.GetWindow(typeof(UnitTowerEditorWindow), false, "TowerEditor");
            window.minSize = new Vector2(420, 300);

            TDE.Init();

            InitLabel();

            if (prefabID >= 0)
            {
                window.selectID = TowerDB.GetPrefabIndex(prefabID);
            }

            window.SelectItem(window.selectID);
        }
コード例 #4
0
        public static void Init(int prefabID = -1)
        {
            // Get existing open window or if none, make a new one:
            window         = (UnitTowerEditorWindow)EditorWindow.GetWindow(typeof(UnitTowerEditorWindow), false, "Tower Editor");
            window.minSize = new Vector2(420, 300);

            LoadDB();

            InitLabel();

            if (prefabID >= 0)
            {
                window.selectID = TDEditor.GetTowerIndex(prefabID) - 1;
            }

            window.SetupCallback();
        }
コード例 #5
0
        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)
            {
                UnitTower prefab = instance;
                if (type == PrefabType.PrefabInstance)
                {
                    prefab = (UnitTower)PrefabUtility.GetCorrespondingObjectFromSource(instance);
                }
                bool existInDB = TowerDB.GetPrefabIndex(prefab) >= 0;

                if (!existInDB)
                {
                    if (instance.prefabID >= 0)
                    {
                        Debug.Log("reset prefabID"); 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"))
                    {
                        UnitTowerEditorWindow.Init();
                        UnitTowerEditorWindow.NewItem(instance);
                        UnitTowerEditorWindow.Init();                                   //call again to select the instance in editor window
                    }
                    GUI.color = Color.white;
                }
                else
                {
                    EditorGUILayout.HelpBox("Editing tower using Inspector is not recommended.\nPlease use the editor window instead", MessageType.Info);
                    if (GUILayout.Button("Tower Editor Window"))
                    {
                        UnitTowerEditorWindow.Init(instance.prefabID);
                    }
                }

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

                string text = "Tower 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 tower using default inspector. However it's not recommended";
                EditorGUILayout.HelpBox(text, MessageType.Warning);

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


            DefaultInspector();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }
コード例 #6
0
 static void OpenTowerEditor()
 {
     UnitTowerEditorWindow.Init();
 }
コード例 #7
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

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

            GUI.changed = false;

            EditorGUILayout.Space();



            PrefabType type = PrefabUtility.GetPrefabType(instance);

            if (type == PrefabType.Prefab || type == PrefabType.PrefabInstance)
            {
                bool existInDB = false;
                if (type == PrefabType.PrefabInstance)
                {
                    existInDB = TDEditor.ExistInDB((UnitTower)PrefabUtility.GetPrefabParent(instance));
                }
                else if (type == PrefabType.Prefab)
                {
                    existInDB = TDEditor.ExistInDB(instance);
                }

                if (!existInDB)
                {
                    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"))
                    {
                        UnitTowerEditorWindow.Init();
                        UnitTowerEditorWindow.NewItem(instance);
                        UnitTowerEditorWindow.Init();                                   //call again to select the instance in editor window
                    }
                    GUI.color = Color.white;
                }
                else
                {
                    EditorGUILayout.HelpBox("Editing tower using Inspector is not recommended.\nPlease use the editor window instead.", MessageType.Info);
                    if (GUILayout.Button("Tower Editor Window"))
                    {
                        UnitTowerEditorWindow.Init(instance.prefabID);
                    }
                }

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

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


            DefaultInspector();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }
コード例 #8
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            GUI.changed = false;
            Undo.RecordObject(instance, "BuildManager");

            serializedObject.Update();

            EditorGUILayout.Space();


            srlPpt = serializedObject.FindProperty("buildMode");
            EditorGUI.BeginChangeCheck();

            cont  = new GUIContent("Build Mode:", "");
            contL = new GUIContent[buildModeLabel.Length];
            for (int i = 0; i < contL.Length; i++)
            {
                contL[i] = new GUIContent(buildModeLabel[i], buildModeTooltip[i]);
            }
            int type = EditorGUILayout.Popup(cont, srlPpt.enumValueIndex, contL);

            if (EditorGUI.EndChangeCheck())
            {
                srlPpt.enumValueIndex = type;
            }


            EditorGUILayout.Space();


            cont = new GUIContent("Grid Size:", "The grid size of the grid on the platform");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("gridSize"), cont);

            cont = new GUIContent("AutoAdjustTextureToGrid:", "Check to let the BuildManager reformat the texture tiling of the platform to fix the gridsize");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("autoAdjustTextureToGrid"), cont);


            EditorGUILayout.Space();

            cont = new GUIContent("DisableBuildInPlay:", "When checked, the player cannot build tower when there are active creep in the game");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("disableBuildWhenInPlay"), cont);

            EditorGUILayout.Space();


            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MaxWidth(10));
            showTowerList = EditorGUILayout.Foldout(showTowerList, "Show Tower List");
            EditorGUILayout.EndHorizontal();
            if (showTowerList)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("EnableAll") && !Application.isPlaying)
                {
                    instance.unavailableTowerIDList = new List <int>();
                }
                if (GUILayout.Button("DisableAll") && !Application.isPlaying)
                {
                    instance.unavailableTowerIDList = new List <int>();
                    for (int i = 0; i < towerDB.towerList.Count; i++)
                    {
                        if (towerDB.towerList[i].disableInBuildManager)
                        {
                            continue;
                        }
                        instance.unavailableTowerIDList.Add(towerDB.towerList[i].prefabID);
                    }
                }
                EditorGUILayout.EndHorizontal();

                int disableCount = 0;
                for (int i = 0; i < towerDB.towerList.Count; i++)
                {
                    UnitTower tower = towerDB.towerList[i];

                    if (tower.disableInBuildManager)
                    {
                        if (instance.unavailableTowerIDList.Contains(tower.prefabID))
                        {
                            instance.unavailableTowerIDList.Remove(tower.prefabID);
                        }
                        disableCount += 1;
                        continue;
                    }

                    GUILayout.BeginHorizontal();

                    GUILayout.Box("", GUILayout.Width(40), GUILayout.Height(40));
                    Rect rect = GUILayoutUtility.GetLastRect();
                    TDEditor.DrawSprite(rect, tower.iconSprite, tower.desp, false);

                    GUILayout.BeginVertical();
                    EditorGUILayout.Space();
                    GUILayout.Label(tower.unitName, GUILayout.ExpandWidth(false));

                    EditorGUI.BeginChangeCheck();
                    bool flag = !instance.unavailableTowerIDList.Contains(tower.prefabID) ? true : false;
                    flag = EditorGUILayout.Toggle(new GUIContent(" - enabled: ", "check to enable the tower in this level"), flag);

                    if (!Application.isPlaying && EditorGUI.EndChangeCheck())
                    {
                        if (!flag && !instance.unavailableTowerIDList.Contains(tower.prefabID))
                        {
                            instance.unavailableTowerIDList.Add(tower.prefabID);
                        }
                        else if (flag)
                        {
                            instance.unavailableTowerIDList.Remove(tower.prefabID);
                        }
                    }

                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                }

                if (disableCount > 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField(" - " + disableCount + " Towers are disabled in BuildManager");
                }
            }


            EditorGUILayout.Space();
            EditorGUILayout.Space();


            if (GUILayout.Button("Open TowerEditor"))
            {
                UnitTowerEditorWindow.Init();
            }


            EditorGUILayout.Space();


            DefaultInspector();

            serializedObject.ApplyModifiedProperties();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }
コード例 #9
0
        public override void OnInspectorGUI()
        {
            GUI.changed = false;

            EditorGUILayout.Space();

            cont = new GUIContent("Grid Object:", "The grid object to show when build tower");
            instance.gridBuild = (GameObject)EditorGUILayout.ObjectField(cont, instance.gridBuild, typeof(GameObject), true);

            cont = new GUIContent("Grid Size:", "The grid size of the grid on the platform");
            instance.gridSize = EditorGUILayout.FloatField(cont, instance.gridSize);

            cont = new GUIContent("AutoSearchForPlatform:", "Check to let the BuildManager automatically serach of all the build platform in game\nThis will override the BuildPlatform list");
            instance.autoSearchForPlatform = EditorGUILayout.Toggle(cont, instance.autoSearchForPlatform);

            cont = new GUIContent("AutoAdjustTextureToGrid:", "Check to let the BuildManager reformat the texture tiling of the platform to fix the gridsize");
            instance.AutoAdjustTextureToGrid = EditorGUILayout.Toggle(cont, instance.AutoAdjustTextureToGrid);

            EditorGUILayout.Space();

            if (GUILayout.Button("Enable All Towers On All Platforms") && !Application.isPlaying)
            {
                EnableAllToweronAllPlatform();
            }

            cont = new GUIContent("Build Platforms", "Build Platform in this level\nOnly applicable when AutoSearchForPlatform is unchecked");

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MaxWidth(10));
            showPlatforms = EditorGUILayout.Foldout(showPlatforms, cont);
            EditorGUILayout.EndHorizontal();

            if (showPlatforms)
            {
                cont = new GUIContent("Build Platforms:", "The grid size of the grid on the platform");
                float listSize = instance.buildPlatforms.Count;
                listSize = EditorGUILayout.FloatField("    Size:", listSize);

                //if(!EditorGUIUtility.editingTextField && listSize!=instance.buildPlatforms.Count){
                if (listSize != instance.buildPlatforms.Count)
                {
                    while (instance.buildPlatforms.Count < listSize)
                    {
                        instance.buildPlatforms.Add(null);
                    }
                    while (instance.buildPlatforms.Count > listSize)
                    {
                        instance.buildPlatforms.RemoveAt(instance.buildPlatforms.Count - 1);
                    }
                }

                for (int i = 0; i < instance.buildPlatforms.Count; i++)
                {
                    instance.buildPlatforms[i] = (PlatformTD)EditorGUILayout.ObjectField("    Element " + i, instance.buildPlatforms[i], typeof(PlatformTD), true);
                }
            }


            EditorGUILayout.Space();


            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MaxWidth(10));
            showTowerList = EditorGUILayout.Foldout(showTowerList, "Show Tower List");
            EditorGUILayout.EndHorizontal();
            if (showTowerList)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("EnableAll") && !Application.isPlaying)
                {
                    instance.unavailableTowerIDList = new List <int>();
                }
                if (GUILayout.Button("DisableAll") && !Application.isPlaying)
                {
                    instance.unavailableTowerIDList = new List <int>();
                    for (int i = 0; i < towerList.Count; i++)
                    {
                        instance.unavailableTowerIDList.Add(towerList[i].prefabID);
                    }
                }
                EditorGUILayout.EndHorizontal();

                //scrollPosition = GUILayout.BeginScrollView (scrollPosition);

                for (int i = 0; i < towerList.Count; i++)
                {
                    UnitTower tower = towerList[i];

                    if (tower.disableInBuildManager)
                    {
                        continue;
                    }

                    GUILayout.BeginHorizontal();

                    GUILayout.Box("", GUILayout.Width(40), GUILayout.Height(40));
                    Rect rect = GUILayoutUtility.GetLastRect();
                    EditorUtilities.DrawSprite(rect, tower.iconSprite, false);

                    GUILayout.BeginVertical();
                    EditorGUILayout.Space();
                    GUILayout.Label(tower.unitName, GUILayout.ExpandWidth(false));

                    bool flag = !instance.unavailableTowerIDList.Contains(tower.prefabID) ? true : false;
                    if (Application.isPlaying)
                    {
                        flag = !flag;                           //switch it around in runtime
                    }
                    flag = EditorGUILayout.Toggle(new GUIContent(" - enabled: ", "check to enable the tower in this level"), flag);

                    if (!Application.isPlaying)
                    {
                        if (flag)
                        {
                            instance.unavailableTowerIDList.Remove(tower.prefabID);
                        }
                        else
                        {
                            if (!instance.unavailableTowerIDList.Contains(tower.prefabID))
                            {
                                instance.unavailableTowerIDList.Add(tower.prefabID);
                            }
                        }
                    }

                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                }

                //GUILayout.EndScrollView ();
            }

            EditorGUILayout.Space();

            int cursorMode = (int)instance.cursorIndicatorMode;

            cont     = new GUIContent("Tile Cursor Mode:", "The way to indicate a tile on a grid when it's currently being hovered on by the cursor");
            contList = new GUIContent[cursorIndModeLabel.Length];
            for (int i = 0; i < contList.Length; i++)
            {
                contList[i] = new GUIContent(cursorIndModeLabel[i], cursorIndModeTooltip[i]);
            }
            cursorMode = EditorGUILayout.Popup(cont, cursorMode, contList);
            instance.cursorIndicatorMode = (BuildManager._CursorIndicatorMode)cursorMode;

            EditorGUILayout.Space();



            if (GUILayout.Button("Open TowerEditor"))
            {
                UnitTowerEditorWindow.Init();
            }
            EditorGUILayout.Space();


            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MaxWidth(10));
            showDefaultFlag = EditorGUILayout.Foldout(showDefaultFlag, "Show default editor");
            EditorGUILayout.EndHorizontal();
            if (showDefaultFlag)
            {
                DrawDefaultInspector();
            }
            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }