예제 #1
0
        Vector2 DrawItemIDTower(float startX, float startY, Perk perk, int limit = 1)
        {
            string[]         towerNameList = EditorDBManager.GetTowerNameList();
            List <UnitTower> towerList     = EditorDBManager.GetTowerList();

            if (perk.itemIDList.Count == 0)
            {
                perk.itemIDList.Add(-1);
            }
            while (perk.itemIDList.Count > limit)
            {
                perk.itemIDList.RemoveAt(perk.itemIDList.Count - 1);
            }

            for (int i = 0; i < perk.itemIDList.Count; i++)
            {
                int ID = perk.itemIDList[i];

                if (ID >= 0)
                {
                    for (int n = 0; n < towerList.Count; n++)
                    {
                        if (towerList[n].prefabID == ID)
                        {
                            ID = n + 1; break;
                        }
                    }
                }

                cont = new GUIContent(" - Tower:", "The tower to add to game when the perk is unlocked");
                EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
                ID = EditorGUI.Popup(new Rect(startX + spaceX - 20, startY, width, 15), ID, towerNameList);
                if (ID > 0 && !perk.itemIDList.Contains(towerList[ID - 1].prefabID))
                {
                    perk.itemIDList[i] = towerList[ID - 1].prefabID;
                }
                else if (ID == 0)
                {
                    perk.itemIDList[i] = -1;
                }

                //if the list is full, extend it
                if (i == perk.itemIDList.Count - 1 && ID >= 0 && perk.itemIDList.Count < limit)
                {
                    perk.itemIDList.Add(-1);
                }

                //if one of the element in the list is empty, shrink it
                if (i < perk.itemIDList.Count - 1 && perk.itemIDList[i] == -1)
                {
                    perk.itemIDList.RemoveAt(i); i -= 1;
                }
            }

            return(new Vector2(startX, startY));
        }
예제 #2
0
        private static void UpdateObjectHierarchyList()
        {
            List <UnitTower> towerList = EditorDBManager.GetTowerList();

            if (towerList.Count <= 0 || selectID >= towerList.Count)
            {
                return;
            }
            EditorUtilities.GetObjectHierarchyList(towerList[selectID].gameObject, SetObjListCallback);
        }
예제 #3
0
        private static void GetTower()
        {
            EditorDBManager.Init();

            towerList = EditorDBManager.GetTowerList();

            if (Application.isPlaying)
            {
                return;
            }

            List <int> towerIDList = EditorDBManager.GetTowerIDList();

            for (int i = 0; i < instance.availableTowerIDList.Count; i++)
            {
                if (!towerIDList.Contains(instance.availableTowerIDList[i]))
                {
                    instance.availableTowerIDList.RemoveAt(i);      i -= 1;
                }
            }
        }
예제 #4
0
        void OnGUI()
        {
            if (window == null)
            {
                Init();
            }

            List <UnitTower> towerList = EditorDBManager.GetTowerList();

            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;
            }

            selectID = Mathf.Clamp(selectID, 0, towerList.Count - 1);

            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();
            }
        }