Esempio n. 1
0
 public void SetAsSampleTower(UnitTower tower)
 {
     isSampleTower  = true;
     srcTower       = tower;
     thisT.position = new Vector3(0, 9999, 0);
 }
Esempio n. 2
0
 void OnNewTower(UnitTower newTower)
 {
     UIBuildButton.AddNewTower(newTower);
 }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            GUI.changed = false;

            EditorGUILayout.Space();

            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);
            }
        }
Esempio n. 4
0
        Vector2 DrawUnitConfigurator(float startX, float startY, List <UnitTower> towerList)
        {
            float maxWidth = 0;

            UnitTower tower = towerList[selectID];


            float cachedY = startY;
            float cachedX = startX;

            startX += 65;   //startY+=20;

            int type = (int)tower.type;

            cont = new GUIContent("Tower Type:", "Type of the tower. Each type of tower serve a different function");
            EditorGUI.LabelField(new Rect(startX, startY, width, height), cont);
            contL = new GUIContent[towerTypeLabel.Length];
            for (int i = 0; i < contL.Length; i++)
            {
                contL[i] = new GUIContent(towerTypeLabel[i], towerTypeTooltip[i]);
            }
            type       = EditorGUI.Popup(new Rect(startX + 80, startY, width - 40, 15), new GUIContent(""), type, contL);
            tower.type = (_TowerType)type;
            startX     = cachedX;

            v3 = DrawIconAndName(tower, startX, startY); startY = v3.y;


            startX = cachedX;
            spaceX = 110;

            cachedY = startY;
            v3      = DrawUnitDefensiveSetting(tower, startX, startY, objHList, objHLabelList); //startY=v3.y;


            if (startX + spaceX + width > maxWidth)
            {
                maxWidth = startX + spaceX + width;
            }


            startY  = cachedY;
            startX += spaceX + width + 35;



            if (TowerDealDamage(tower))
            {
                int targetMode = (int)tower.targetMode;
                cont = new GUIContent("Target Mode:", "Determine which type of unit the tower can target");
                EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
                contL = new GUIContent[targetModeLabel.Length];
                for (int i = 0; i < contL.Length; i++)
                {
                    contL[i] = new GUIContent(targetModeLabel[i], targetModeTooltip[i]);
                }
                targetMode       = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), new GUIContent(""), targetMode, contL);
                tower.targetMode = (_TargetMode)targetMode;
                startY          += spaceY;
            }

            v3 = DrawUnitOffensiveSetting(tower, startX, startY, objHList, objHLabelList); startY = v3.y + spaceY;


            if (startX + spaceX + width > maxWidth)
            {
                maxWidth = startX + spaceX + width;
            }



            string[]         weaponNameList = EditorDBManager.GetFPSWeaponNameList();
            List <FPSWeapon> weaponList     = EditorDBManager.GetFPSWeaponList();
            int weaponID = 0;

            if (tower.FPSWeaponID != -1)
            {
                for (int i = 0; i < weaponList.Count; i++)
                {
                    if (weaponList[i].prefabID == tower.FPSWeaponID)
                    {
                        weaponID = i + 1; break;
                    }
                }
            }
            cont = new GUIContent("FPS Weapon:", "Weapon tied to this tower when using FPS mode");
            GUI.Label(new Rect(startX, startY, 120, height), cont);
            weaponID = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), weaponID, weaponNameList);
            if (weaponID == 0)
            {
                tower.FPSWeaponID = -1;
            }
            else
            {
                tower.FPSWeaponID = weaponList[weaponID - 1].prefabID;
            }



            //if(startY>maxHeight) maxHeight=startY;
            float maxY = startY;

            startY = 300;

            startX = cachedX; cachedY = startY;

            string[] towerNameList = EditorDBManager.GetTowerNameList();

            cont = new GUIContent("Prev lvl Tower:", "Tower prefab which this current selected tower is upgrade from. If blank then this is the base tower (level 1). ");
            GUI.Label(new Rect(startX, startY, 120, height), cont);
            int ID = -1;

            for (int i = 0; i < towerList.Count; i++)
            {
                if (towerList[i] == tower.prevLevelTower)
                {
                    ID = i + 1;
                }
            }
            ID = EditorGUI.Popup(new Rect(startX + spaceX, startY, 105, height), ID, towerNameList);
            if (GUI.Button(new Rect(startX + 215, startY, 20, 15), "^"))
            {
                if (tower.prevLevelTower != null)
                {
                    SelectTower(ID - 1);
                }
            }


            cont = new GUIContent("lvl within Prefab:", "");
            GUI.Label(new Rect(startX, startY += spaceY, 120, height), cont);
            if (GUI.Button(new Rect(startX + spaceX, startY, 50, 20), "-1"))
            {
                if (tower.stats.Count > 1)
                {
                    tower.stats.RemoveAt(tower.stats.Count - 1);
                }
            }
            if (GUI.Button(new Rect(startX + 165, startY, 50, 20), "+1"))
            {
                tower.stats.Add(tower.stats[tower.stats.Count - 1].Clone());
            }

            if (tower.nextLevelTowerList.Count == 0)
            {
                tower.nextLevelTowerList.Add(null);
            }

            cont = new GUIContent("Next lvl Tower 1:", "Tower prefab to be used beyond the stats level specified for this prefab");
            GUI.Label(new Rect(startX, startY += (spaceY + 10), 120, height), cont);
            ID = -1;
            for (int i = 0; i < towerList.Count; i++)
            {
                if (towerList[i] == tower.nextLevelTowerList[0])
                {
                    ID = i + 1;
                }
            }
            ID = EditorGUI.Popup(new Rect(startX + spaceX, startY, 105, height), ID, towerNameList);
            if (ID > 0 && towerList[ID - 1] != tower)
            {
                if (tower.nextLevelTowerList[0] != null)
                {
                    tower.nextLevelTowerList[0].prevLevelTower = null;
                }

                tower.nextLevelTowerList[0]      = towerList[ID - 1];
                towerList[ID - 1].prevLevelTower = tower;
            }
            else if (ID == 0)
            {
                tower.nextLevelTowerList[0] = null;
            }

            if (GUI.Button(new Rect(startX + 215, startY, 20, 15), "^"))
            {
                if (tower.nextLevelTowerList[0] != null)
                {
                    SelectTower(ID - 1);
                }
            }

            if (tower.nextLevelTowerList[0] == null)
            {
                if (tower.nextLevelTowerList.Count > 1 && tower.nextLevelTowerList[1] != null)
                {
                    tower.nextLevelTowerList[0] = tower.nextLevelTowerList[1];
                    tower.nextLevelTowerList.RemoveAt(1);
                }
            }

            if (tower.nextLevelTowerList[0] != null)
            {
                if (tower.nextLevelTowerList.Count < 2)
                {
                    tower.nextLevelTowerList.Add(null);
                }

                //startX+=295;
                cont = new GUIContent("Next lvl Tower 2:", "Tower prefab to be used beyond the stats level specified for this prefab");
                GUI.Label(new Rect(startX, startY += spaceY, 120, height), cont);
                ID = -1;
                for (int i = 0; i < towerList.Count; i++)
                {
                    if (towerList[i] == tower.nextLevelTowerList[1])
                    {
                        ID = i + 1;
                    }
                }
                ID = EditorGUI.Popup(new Rect(startX + spaceX, startY, 105, height), ID, towerNameList);
                if (ID > 0 && towerList[ID - 1] != tower && !tower.nextLevelTowerList.Contains(towerList[ID - 1]))
                {
                    if (tower.nextLevelTowerList[1] != null)
                    {
                        tower.nextLevelTowerList[1].prevLevelTower = null;
                    }

                    tower.nextLevelTowerList[1]      = towerList[ID - 1];
                    towerList[ID - 1].prevLevelTower = tower;
                }
                else if (ID == 0)
                {
                    tower.nextLevelTowerList[1] = null;
                }
                if (GUI.Button(new Rect(startX + 215, startY, 20, 15), "^"))
                {
                    if (tower.nextLevelTowerList[1] != null)
                    {
                        SelectTower(ID - 1);
                    }
                }

                //GUI.Label(new Rect(startX+270, startY, 200, height), "(for alternate upgrade path)");
                //startX=cachedX;
            }



            startY = Mathf.Max(maxY + 20, 400);
            startX = cachedX;

            float maxHeight        = 0;
            float maxContentHeight = 0;

            minimiseStat = EditorGUI.Foldout(new Rect(startX, startY -= 30, width, height), minimiseStat, "Show Stats");
            if (!minimiseStat)
            {
                startY += spaceY;
                startX += 15;

                int lvl = GetStatsLevelStartOffset(tower);

                if (tower.stats.Count == 0)
                {
                    tower.stats.Add(new UnitStat());
                }
                for (int i = 0; i < tower.stats.Count; i++)
                {
                    EditorGUI.LabelField(new Rect(startX, startY, width, height), "Level " + (lvl + i + 1) + " Stats");
                    v3 = DrawStat(tower.stats[i], startX, startY + spaceY - 20, statContentHeight, tower);
                    if (maxContentHeight < v3.z)
                    {
                        maxContentHeight = v3.z;
                    }
                    //statContentHeight=v3.z;
                    startX = v3.x + 10;
                    if (startX > maxWidth)
                    {
                        maxWidth = startX;
                    }
                    if (maxHeight < v3.y)
                    {
                        maxHeight = v3.y;
                    }
                }
                statContentHeight = maxContentHeight;
                startY            = maxHeight;
            }

            startX  = cachedX;
            startY += spaceY;


            GUIStyle style = new GUIStyle("TextArea");

            style.wordWrap = true;
            cont           = new GUIContent("Unit general description (to be used in runtime): ", "");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, 400, 20), cont);
            tower.desp = EditorGUI.TextArea(new Rect(startX, startY + spaceY - 3, 530, 50), tower.desp, style);

            startX = maxWidth - cachedX + 80;

            return(new Vector2(startX, startY));
        }
Esempio n. 5
0
        Vector2 DrawUnitList(float startX, float startY, List <UnitTower> towerList)
        {
            float width = FULL_WIDTH_TOWER_LIST;

            if (minimiseList)
            {
                width = COLAPSED_WIDTH_TOWER_LIST;
            }

            if (!minimiseList)
            {
                if (GUI.Button(new Rect(startX + 100, startY - 20, 40, 18), "up"))
                {
                    if (selectID > 0)
                    {
                        UnitTower tower = towerList[selectID];
                        towerList[selectID]     = towerList[selectID - 1];
                        towerList[selectID - 1] = tower;
                        selectID -= 1;

                        if (selectID * 35 < scrollPos1.y)
                        {
                            scrollPos1.y = selectID * 35;
                        }
                    }
                }
                if (GUI.Button(new Rect(startX + 142, startY - 20, 40, 18), "down"))
                {
                    if (selectID < towerList.Count - 1)
                    {
                        UnitTower tower = towerList[selectID];
                        towerList[selectID]     = towerList[selectID + 1];
                        towerList[selectID + 1] = tower;
                        selectID += 1;

                        if (listVisibleRect.height - 35 < selectID * 35)
                        {
                            scrollPos1.y = (selectID + 1) * 35 - listVisibleRect.height + 5;
                        }
                    }
                }
            }


            listVisibleRect = new Rect(startX, startY, width + 15, window.position.height - startY - 5);
            listContentRect = new Rect(startX, startY, width, towerList.Count * 35 + 5);

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

            scrollPos1 = GUI.BeginScrollView(listVisibleRect, scrollPos1, listContentRect);


            startY += 5; startX += 5;

            for (int i = 0; i < towerList.Count; i++)
            {
                EditorUtilities.DrawSprite(new Rect(startX, startY + (i * 35), 30, 30), towerList[i].iconSprite);

                if (minimiseList)
                {
                    if (selectID == i)
                    {
                        GUI.color = new Color(0, 1f, 1f, 1f);
                    }
                    if (GUI.Button(new Rect(startX + 115, startY + (i * 35), 30, 30), "X"))
                    {
                        SelectTower(i);
                    }
                    GUI.color = Color.white;

                    continue;
                }



                if (selectID == i)
                {
                    GUI.color = new Color(0, 1f, 1f, 1f);
                }
                if (GUI.Button(new Rect(startX + 35, startY + (i * 35), 180, 30), towerList[i].unitName))
                {
                    SelectTower(i);
                }
                GUI.color = Color.white;

                if (deleteID == i)
                {
                    if (GUI.Button(new Rect(startX + 137, startY + (i * 35), 20, 20), "N"))
                    {
                        deleteID = -1;
                    }

                    GUI.color = Color.red;
                    if (GUI.Button(new Rect(startX + 137, startY + (i * 35) + 15, 20, 20), "Y"))
                    {
                        if (selectID >= deleteID)
                        {
                            SelectTower(Mathf.Max(0, selectID - 1));
                        }
                        EditorDBManager.RemoveTower(deleteID);
                        deleteID = -1;
                    }
                    GUI.color = Color.white;
                }
                else
                {
                    if (GUI.Button(new Rect(startX + 217, startY + (i * 35), 25, 25), "X"))
                    {
                        deleteID = i;
                    }
                }
            }

            GUI.EndScrollView();

            return(new Vector2(startX + width, startY));
        }
Esempio n. 6
0
        void OnGUI()
        {
            if (window == null)
            {
                Init();
            }

            GUI.skin = skin;

            List <UnitTower> towerList = filterTowers();

            if (GUI.Button(new Rect(window.position.width - 120, 5, 100, 25), "Save"))
            {
                EditorDBManager.SetDirtyTower();
            }

            EditorGUI.LabelField(new Rect(5, 7, 150, 17), "Add new tower:");
            UnitTower newTower = null;

            newTower = (UnitTower)EditorGUI.ObjectField(new Rect(100, 7, 140, 17), newTower, typeof(UnitTower), false);
            if (newTower != null)
            {
                int newSelectID = EditorDBManager.AddNewTower(newTower);
                if (newSelectID != -1)
                {
                    SelectTower(newSelectID);
                }
            }


            float startX = 5;
            float startY = 50;

            if (minimiseList)
            {
                if (GUI.Button(new Rect(startX, startY - 20, 30, 18), ">"))
                {
                    minimiseList = false;
                }
            }
            else
            {
                if (GUI.Button(new Rect(startX, startY - 20, 30, 18), "<"))
                {
                    minimiseList = true;
                }
            }
            Vector2 v2 = DrawUnitList(startX, startY, towerList);

            startX = v2.x + 25;

            if (towerList.Count == 0)
            {
                return;
            }

            cont = new GUIContent("Tower Prefab:", "The prefab object of the tower\nClick this to highlight it in the ProjectTab");
            EditorGUI.LabelField(new Rect(startX, startY, width, height), cont);
            EditorGUI.ObjectField(new Rect(startX + 90, startY, 185, height), towerList[selectID].gameObject, typeof(GameObject), false);

            cont = new GUIContent("Disable in BuildManager:", "When checked, tower won't appear on BuildManager list and thus can't be built\nThis is to mark towers that can only be upgrade from a built tower or unlock from perk");
            EditorGUI.LabelField(new Rect(startX + 295, startY, width, height), cont);
            towerList[selectID].disableInBuildManager = EditorGUI.Toggle(new Rect(startX + 440, startY, 185, height), towerList[selectID].disableInBuildManager);

            startY += spaceY + 10;


            Rect visibleRect = new Rect(startX, startY, window.position.width - startX - 10, window.position.height - startY - 5);
            Rect contentRect = new Rect(startX, startY, contentWidth - startY, contentHeight);

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

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

            v2            = DrawUnitConfigurator(startX, startY, towerList);
            contentWidth  = v2.x;
            contentHeight = v2.y;

            GUI.EndScrollView();


            if (GUI.changed)
            {
                EditorDBManager.SetDirtyTower();
            }
        }