Esempio n. 1
0
        // Use this for initialization
        void Awake()
        {
            instance = this;

            List <UnitTower> dbList = TowerDB.GetList();

            for (int i = 0; i < dbList.Count; i++)
            {
                if (!unavailablePrefabIDList.Contains(dbList[i].prefabID) && !dbList[i].hideInInspector)
                {
                    buildableList.Add(dbList[i]);
                }
            }

            for (int i = 0; i < buildableList.Count; i++)
            {
                GameObject obj = (GameObject)Instantiate(buildableList[i].gameObject);
                sampleList.Add(obj.GetComponent <UnitTower>());
                sampleList[sampleList.Count - 1].isPreview        = true;
                sampleList[sampleList.Count - 1].gameObject.layer = TDTK.GetLayerTerrain();
                sampleList[sampleList.Count - 1].transform.parent = transform;
                obj.SetActive(false);
            }

            //Debug.Log("remove this");
            //for(int i=0; i<buildableList.Count; i++) buildableList[i].prefabID=i;
        }
Esempio n. 2
0
 protected override void ShiftItemDown()
 {
     if (selectID < TowerDB.GetList().Count - 1)
     {
         ShiftItem(1);
     }
 }
Esempio n. 3
0
        private static void LoadTower()
        {
            towerDBPrefab = TowerDB.LoadDB();
            towerList     = towerDBPrefab.towerList;

            for (int i = 0; i < towerList.Count; i++)
            {
                //towerList[i].prefabID=i;
                if (towerList[i] != null)
                {
                    towerIDList.Add(towerList[i].prefabID);
                    if (towerList[i].stats.Count == 0)
                    {
                        towerList[i].stats.Add(new UnitStat());
                    }
                }
                else
                {
                    towerList.RemoveAt(i);
                    i -= 1;
                }
            }

            UpdateTowerNameList();
        }
Esempio n. 4
0
        public void InitTower()
        {
            List <UnitTower> towerListDB = TowerDB.Load();

            towerList = new List <UnitTower>();
            for (int i = 0; i < towerListDB.Count; i++)
            {
                if (towerListDB[i] == null)
                {
                    continue;
                }
                if (towerListDB[i].disableInBuildManager)
                {
                    continue;
                }
                if (!unavailableTowerIDList.Contains(towerListDB[i].prefabID))
                {
                    towerList.Add(towerListDB[i]);
                }
            }

            List <UnitTower> newList = PerkManager.GetUnlockedTower();

            for (int i = 0; i < newList.Count; i++)
            {
                towerList.Add(newList[i]);
            }
        }
Esempio n. 5
0
        private void ShiftItem(int dir)
        {
            UnitTower tower = TowerDB.GetList()[selectID];

            TowerDB.GetList()[selectID]       = TowerDB.GetList()[selectID + dir];
            TowerDB.GetList()[selectID + dir] = tower;
            selectID += dir;
        }
Esempio n. 6
0
 public static TowerDB Init()
 {
     if (instance != null)
     {
         return(instance);
     }
     instance = LoadDB();
     return(instance);
 }
Esempio n. 7
0
        private void SelectItem(int newID)
        {
            selectID = newID;
            if (TowerDB.GetList().Count <= 0)
            {
                return;
            }

            selectID = Mathf.Clamp(selectID, 0, TowerDB.GetList().Count - 1);
            UpdateObjHierarchyList(TowerDB.GetList()[selectID].transform);
        }
Esempio n. 8
0
        public static void InitDB()
        {
            if (init)
            {
                return;
            }
            init = true;

            towerDBList     = TowerDB.Load();
            abilityDBList   = AbilityDB.Load();
            perkDBList      = PerkDB.Load();
            fpsWeaponDBList = FPSWeaponDB.Load();
        }
Esempio n. 9
0
        public static List <UnitTower> Load()
        {
            GameObject obj = Resources.Load("DB_TDTK/TowerDB", typeof(GameObject)) as GameObject;

                        #if UNITY_EDITOR
            if (obj == null)
            {
                obj = CreatePrefab();
            }
                        #endif

            TowerDB instance = obj.GetComponent <TowerDB>();
            return(instance.towerList);
        }
Esempio n. 10
0
        private int _NewItem(UnitTower tower)
        {
            if (TowerDB.GetList().Contains(tower))
            {
                return(selectID);
            }

            tower.prefabID = TDE.GenerateNewID(TowerDB.GetPrefabIDList());

            TowerDB.GetList().Add(tower);
            TowerDB.UpdateLabel();

            return(TowerDB.GetList().Count - 1);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public static void AddBuildable(int prefabID, int replacePID = -1)
        {
            if (instance == null)
            {
                return;
            }
            Debug.Log("prefabID = " + prefabID.ToString());

            UnitTower newTower = TowerDB.GetPrefab(prefabID);

            if (newTower == null)
            {
                Debug.LogWarning("Invalid prefabID?"); return;
            }

            int replaceIdx = -1;

            if (replacePID >= 0)
            {
                for (int i = 0; i < instance.buildableList.Count; i++)
                {
                    if (instance.buildableList[i].prefabID == replacePID)
                    {
                        replaceIdx = i; break;
                    }
                }
            }

            GameObject obj = (GameObject)Instantiate(newTower.gameObject);

            obj.SetActive(false);

            if (replaceIdx >= 0)
            {
                instance.buildableList[replaceIdx]        = newTower;
                instance.sampleList[replaceIdx]           = obj.GetComponent <UnitTower>();
                instance.sampleList[replaceIdx].isPreview = true;
            }
            else
            {
                instance.buildableList.Add(newTower);
                instance.sampleList.Add(obj.GetComponent <UnitTower>());
                instance.sampleList[instance.sampleList.Count - 1].isPreview = true;
            }
            Debug.Log("AddBuildable");
            TDTK.OnNewBuildable(newTower);
        }
		private static void LoadTower(){
			towerDBPrefab=TowerDB.LoadDB();
			towerList=towerDBPrefab.towerList;
			
			for(int i=0; i<towerList.Count; i++){
				//towerList[i].prefabID=i;
				if(towerList[i]!=null){
					towerIDList.Add(towerList[i].prefabID);
					if(towerList[i].stats.Count==0) towerList[i].stats.Add(new UnitStat());
				}
				else{
					towerList.RemoveAt(i);
					i-=1;
				}
			}
			
			UpdateTowerNameList();
		}
Esempio n. 14
0
        public static void LoadTower()
        {
            towerDB = TowerDB.LoadDB();

            for (int i = 0; i < towerDB.towerList.Count; i++)
            {
                if (towerDB.towerList[i] != null)
                {
                    towerIDList.Add(towerDB.towerList[i].prefabID);
                }
                else
                {
                    towerDB.towerList.RemoveAt(i);    i -= 1;
                }
            }

            UpdateLabel_Tower();

            TDEditorWindow.SetTowerDB(towerDB, towerIDList, towerLabel);
            TDEditorInspector.SetTowerDB(towerDB, towerIDList, towerLabel);
        }
Esempio n. 15
0
        public static void Init()
        {
            if (init)
            {
                return;
            }

            init = true;                //Debug.Log(" - Init Editor - ");

            damageTableDB = DamageTableDB.Init();
            rscDB         = RscDB.Init();
            towerDB       = TowerDB.Init();
            creepDB       = CreepDB.Init();
            abilityDB     = AbilityDB.Init();
            perkDB        = PerkDB.Init();
            effectDB      = EffectDB.Init();

            DamageTableDB.UpdateLabel();
            TowerDB.UpdateLabel();
            CreepDB.UpdateLabel();
            AbilityDB.UpdateLabel();
            PerkDB.UpdateLabel();
            EffectDB.UpdateLabel();
        }
Esempio n. 16
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);
            }
        }
Esempio n. 17
0
        public void OnGUI()
        {
            TDE.InitGUIStyle();

            if (!CheckIsPlaying())
            {
                return;
            }
            if (window == null)
            {
                Init();
            }


            List <UnitTower> towerList = TowerDB.GetList();

            Undo.RecordObject(this, "window");
            Undo.RecordObject(TowerDB.GetDB(), "towerDB");
            if (towerList.Count > 0)
            {
                Undo.RecordObject(towerList[selectID], "tower");
            }


            if (GUI.Button(new Rect(Math.Max(260, window.position.width - 120), 5, 100, 25), "Save"))
            {
                TDE.SetDirty();
            }

            UnitTower newTower = null;

            TDE.Label(5, 7, 150, 17, "Add New Tower:", "Drag tower prefab to this slot to add it to the list");
            newTower = (UnitTower)EditorGUI.ObjectField(new Rect(115, 7, 150, 17), newTower, typeof(UnitTower), false);
            if (newTower != null)
            {
                Select(NewItem(newTower));
            }


            float startX = 5; float startY = 55;

            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 = DrawTowerList(startX, startY, towerList);

            startX = v2.x + 25;

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


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

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

            v2            = DrawUnitConfigurator(startX, startY, towerList[selectID]);
            contentWidth  = v2.x - startX;
            contentHeight = v2.y - 55;

            GUI.EndScrollView();


            if (GUI.changed)
            {
                TDE.SetDirty();
            }
        }
Esempio n. 18
0
        protected float DrawEffectSetting(float startX, float startY, Perk item)
        {
            //TDE.Label(startX, startY, spaceX*2, height, "Perk Effect Attribute", "", TDE.headerS);	startY+=spaceY;
            string text = "Perk Effect Attribute ";          //+ (!foldStats ? "(show)" : "(hide)");

            foldStats = EditorGUI.Foldout(new Rect(startX, startY += spaceY, spaceX, height), foldStats, text, TDE.foldoutS);
            if (!foldStats)
            {
                return(startY + spaceY);
            }

            startY += spaceY; startX += 12;

            if (item.type == _PerkType.NewTower)
            {
                TDE.Label(startX, startY, width, height, "New Tower:", "The new tower to be added to game");
                item.newTowerPID = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), item.newTowerPID, TowerDB.label);

                TDE.Label(startX, startY += spaceY, width, height, " - Replacing:", "OPTIONAL - exiting tower that will be replaced");
                item.replaceTowerPID      = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), item.replaceTowerPID, TowerDB.label);
            }

            else if (item.type == _PerkType.NewAbility)
            {
                TDE.Label(startX, startY, width, height, "New Ability:", "The new ability to be added to game");
                item.newAbilityPID = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), item.newAbilityPID, AbilityDB.label);

                TDE.Label(startX, startY += spaceY, width, height, " - Replacing:", "OPTIONAL - exiting ability that will be replaced");
                item.replaceAbilityPID    = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), item.replaceAbilityPID, AbilityDB.label);
            }

            else if (item.UseGainValue() || item.UseGainList())
            {
                startY = DrawEffectTypeSetting(startX, startY, item);

                string txtType = item.IsMultiplier() ? "Multiplier:" : "Modifier:";
                if (!item.SupportModNMul())
                {
                    txtType = "Gain:";
                }

                if (item.UseGainValue())
                {
                    string txt = item.UseGainList() ? "Global " : "";

                    TDE.Label(startX, startY, width, height, txt + txtType);                  //"Gain Value:", "");
                    item.gain = EditorGUI.FloatField(new Rect(startX + spaceX, startY, widthS, height), item.gain);
                    startY   += spaceY;
                }

                if (item.UseGainList())
                {
                    if (item.gainList.Count < RscDB.GetCount())
                    {
                        item.gainList.Add(0);
                    }
                    if (item.gainList.Count > RscDB.GetCount())
                    {
                        item.gainList.Remove(item.gainList.Count - 1);
                    }

                    for (int i = 0; i < item.gainList.Count; i++)
                    {
                        TDE.DrawSprite(new Rect(startX, startY, height, height), RscDB.GetIcon(i));
                        TDE.Label(startX + height, startY, width - height, height, " - " + RscDB.GetName(i));                   //" - "+txtType, "");
                        item.gainList[i] = EditorGUI.FloatField(new Rect(startX + spaceX, startY, widthS, height), item.gainList[i]);
                        if (i < item.gainList.Count - 1)
                        {
                            startY += spaceY;
                        }
                    }
                }
                else
                {
                    startY -= spaceY;
                }
            }

            else if (item.UseStats())
            {
                string textItem = "";
                if (item.type == _PerkType.ModifyTower)
                {
                    textItem = "towers";
                }
                if (item.type == _PerkType.ModifyAbility)
                {
                    textItem = "abilities";
                }
                if (item.type == _PerkType.ModifyEffect)
                {
                    textItem = "effects";
                }

                TDE.Label(startX, startY, width, height, "Apply To All:", "Check to apply to all " + textItem);
                item.applyToAll = EditorGUI.Toggle(new Rect(startX + spaceX, startY, widthS, height), item.applyToAll);

                if (!item.applyToAll)
                {
                    startY += spaceY;
                    if (item.type == _PerkType.ModifyTower)
                    {
                        TDE.Label(startX, startY, width, height, "Target Tower:", "The target towers which this perk should be applied to");
                        for (int i = 0; i < item.towerPIDList.Count; i++)
                        {
                            if (item.towerPIDList[i] < 0)
                            {
                                item.towerPIDList.RemoveAt(i); i -= 1; continue;
                            }

                            int index = TowerDB.GetPrefabIndex(item.towerPIDList[i]);
                            index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, TowerDB.label);
                            int prefabID = TowerDB.GetItem(index).prefabID;
                            if (prefabID != item.prefabID && !item.towerPIDList.Contains(prefabID))
                            {
                                item.towerPIDList[i] = prefabID;
                            }

                            if (GUI.Button(new Rect(startX + spaceX + width + 10, startY, height, height), "-"))
                            {
                                item.towerPIDList.RemoveAt(i); i -= 1;
                            }

                            startY += spaceY;
                        }

                        int newIdx = -1;
                        newIdx = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), newIdx, TowerDB.label);
                        if (newIdx >= 0 && !item.towerPIDList.Contains(TowerDB.GetItem(newIdx).prefabID))
                        {
                            item.towerPIDList.Add(TowerDB.GetItem(newIdx).prefabID);
                        }
                    }
                    if (item.type == _PerkType.ModifyAbility)
                    {
                        TDE.Label(startX, startY, width, height, "Target Ability:", "The target abilities which this perk should be applied to");
                        for (int i = 0; i < item.abilityPIDList.Count; i++)
                        {
                            int index = AbilityDB.GetPrefabIndex(item.abilityPIDList[i]);
                            index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, AbilityDB.label);
                            int prefabID = AbilityDB.GetItem(index).prefabID;
                            if (prefabID != item.prefabID && !item.abilityPIDList.Contains(prefabID))
                            {
                                item.abilityPIDList[i] = prefabID;
                            }

                            if (GUI.Button(new Rect(startX + spaceX + width + 10, startY, height, height), "-"))
                            {
                                item.abilityPIDList.RemoveAt(i); i -= 1;
                            }

                            startY += spaceY;
                        }

                        int newIdx = -1;
                        newIdx = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), newIdx, AbilityDB.label);
                        if (newIdx >= 0 && !item.abilityPIDList.Contains(AbilityDB.GetItem(newIdx).prefabID))
                        {
                            item.abilityPIDList.Add(AbilityDB.GetItem(newIdx).prefabID);
                        }
                    }
                    if (item.type == _PerkType.ModifyEffect)
                    {
                        TDE.Label(startX, startY, width, height, "Target Effect:", "The target effects which this perk should be applied to");
                        for (int i = 0; i < item.effectPIDList.Count; i++)
                        {
                            int index = EffectDB.GetPrefabIndex(item.effectPIDList[i]);
                            index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, EffectDB.label);
                            int prefabID = EffectDB.GetItem(index).prefabID;

                            if (prefabID != item.prefabID && !item.effectPIDList.Contains(prefabID))
                            {
                                item.effectPIDList[i] = prefabID;
                            }

                            if (GUI.Button(new Rect(startX + spaceX + width + 10, startY, height, height), "-"))
                            {
                                item.effectPIDList.RemoveAt(i); i -= 1;
                            }

                            startY += spaceY;
                        }

                        int newIdx = -1;
                        newIdx = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), newIdx, EffectDB.label);
                        if (newIdx >= 0 && !item.effectPIDList.Contains(EffectDB.GetItem(newIdx).prefabID))
                        {
                            item.effectPIDList.Add(EffectDB.GetItem(newIdx).prefabID);
                        }
                    }
                }

                startY += spaceY + 10;

                startY = DrawEffectTypeSetting(startX, startY, item) - spaceY;

                startY += spaceY;

                _EType eType = _EType.PerkT;

                if (item.type == _PerkType.ModifyAbility)
                {
                    eType = _EType.PerkA;

                    TDE.Label(startX, startY, width, height, "Use Limit:", "Modify the use limit of the ability");
                    if (item.effType == Perk._EffType.Multiplier)
                    {
                        TDE.Label(startX + spaceX, startY, widthS, height, "-");
                    }
                    else
                    {
                        item.gain = EditorGUI.FloatField(new Rect(startX + spaceX, startY, widthS, height), item.gain);
                    }

                    TDE.Label(startX, startY += spaceY, width, height, "Cost:", "Modify/Multiply the activation cost of the ability");
                    item.costMul              = EditorGUI.FloatField(new Rect(startX + spaceX, startY, widthS, height), item.costMul);
                    startY += spaceY;
                }
                else if (item.type == _PerkType.ModifyEffect)
                {
                    eType = _EType.PerkE;

                    TDE.Label(startX, startY, width, height, "Duration:", "Modify the duration of the effect");
                    item.effect.duration = EditorGUI.FloatField(new Rect(startX + spaceX, startY, widthS, height), item.effect.duration);

                    TDE.Label(startX, startY += spaceY + 5, width, height, "Stun:", "Check to enable the effec to stun. This will only override the default value if it's set to true");
                    item.effect.stun          = EditorGUI.Toggle(new Rect(startX + spaceX, startY, height, height), item.effect.stun);
                    startY += spaceY;
                }

                startY = DrawStats(startX - 12, startY, item.effect.stats, eType) - spaceY;
            }

            else if (item.IsForPerk())
            {
                TDE.Label(startX, startY, width, height, "Apply To All:", "Check to apply to all perk");
                item.applyToAll = EditorGUI.Toggle(new Rect(startX + spaceX, startY, widthS, height), item.applyToAll);

                if (!item.applyToAll)
                {
                    TDE.Label(startX, startY += spaceY, width, height, "Target Perk:", "The target perk which this perk affect should be applied to");
                    for (int i = 0; i < item.perkPIDList.Count; i++)
                    {
                        int index = PerkDB.GetPrefabIndex(item.perkPIDList[i]);
                        index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, PerkDB.label);
                        int prefabID = PerkDB.GetItem(index).prefabID;
                        if (prefabID != item.prefabID && !item.perkPIDList.Contains(prefabID))
                        {
                            item.perkPIDList[i] = prefabID;
                        }

                        if (GUI.Button(new Rect(startX + spaceX + width + 10, startY, height, height), "-"))
                        {
                            item.perkPIDList.RemoveAt(i); i -= 1;
                        }

                        startY += spaceY;
                    }

                    int newID = -1;
                    newID = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), newID, PerkDB.label);
                    if (newID >= 0 && !item.perkPIDList.Contains(newID))
                    {
                        item.perkPIDList.Add(newID);
                    }
                    startY += spaceY + 10;
                }

                TDE.Label(startX, startY, width, height, "Perk Rsc Multiplier:", "Modify/Multiply the purchase cost of the ability");
                item.costMul = EditorGUI.FloatField(new Rect(startX + spaceX + 25, startY, widthS, height), item.costMul);

                if (item.gainList.Count < RscDB.GetCount())
                {
                    item.gainList.Add(0);
                }
                if (item.gainList.Count > RscDB.GetCount())
                {
                    item.gainList.Remove(item.gainList.Count - 1);
                }

                for (int i = 0; i < item.gainList.Count; i++)
                {
                    TDE.DrawSprite(new Rect(startX, startY += spaceY, height, height), RscDB.GetIcon(i));
                    TDE.Label(startX + height, startY, width - height, height, " - " + RscDB.GetName(i) + ":", "");
                    item.gainList[i] = EditorGUI.FloatField(new Rect(startX + spaceX + 25, startY, widthS, height), item.gainList[i]);
                }
            }

            return(startY + spaceY);
        }
Esempio n. 19
0
 public static void SetTowerDB(TowerDB db, List <int> IDList, string[] label)
 {
     towerDB     = db;
     towerIDList = IDList;
     towerLabel  = label;
 }
Esempio n. 20
0
 protected override void DeleteItem()
 {
     TowerDB.GetList().RemoveAt(deleteID);
     TowerDB.UpdateLabel();
 }
Esempio n. 21
0
        protected float DrawTowerStats(float startX, float startY, UnitTower unit)
        {
            string textF = "Tower Stats And Upgrade";          //+(!foldStats ? "(show)" : "(hide)");

            foldStats = EditorGUI.Foldout(new Rect(startX, startY += spaceY, spaceX, height), foldStats, textF, TDE.foldoutS);
            if (!foldStats)
            {
                return(startY);
            }

            startX += 15;

            TDE.Label(startX, startY += spaceY, width, height, "Next Upgrade:", "The tower prefab this tower can be upgraded to");
            for (int i = 0; i < unit.upgradeTowerList.Count; i++)
            {
                if (unit.upgradeTowerList[i] == null)
                {
                    unit.upgradeTowerList.RemoveAt(i);  i -= 1; continue;
                }

                TDE.Label(startX + spaceX - 20, startY, width, height, " - ", "");
                int idx = TowerDB.GetPrefabIndex(unit.upgradeTowerList[i]);
                idx = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), idx, TowerDB.label);
                if (TowerDB.GetItem(idx) != unit && !unit.upgradeTowerList.Contains(TowerDB.GetItem(idx)))
                {
                    unit.upgradeTowerList[i] = TowerDB.GetItem(idx);
                }

                if (GUI.Button(new Rect(startX + spaceX + width + 5, startY, height, height), "-"))
                {
                    unit.upgradeTowerList.RemoveAt(i);      i -= 1; continue;
                }

                startY += spaceY;
            }

            int newIdx = -1;

            if (unit.upgradeTowerList.Count > 0)
            {
                TDE.Label(startX + spaceX - 65, startY, width, height, " Add New:", "");
            }
            newIdx = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), newIdx, TowerDB.label);
            if (newIdx >= 0 && TowerDB.GetItem(newIdx) != unit && !unit.upgradeTowerList.Contains(TowerDB.GetItem(newIdx)))
            {
                Debug.Log("new index  " + newIdx + "     " + TowerDB.GetItem(newIdx));
                unit.upgradeTowerList.Add(TowerDB.GetItem(newIdx));
            }

            startY += 10;

            //~ if(GUI.Button(new Rect(startX+spaceX+15, startY, width, height), "Add Level")) {
            if (GUI.Button(new Rect(startX, startY + spaceY, width, height), "Add Level"))
            {
                unit.statsList.Add(new Stats());
                unit.statsList[unit.statsList.Count - 1].ResetAsBaseStat();
                foldStats = true;
            }

            startY += spaceY;

            blockWidth = spaceX + 2 * widthS + 26;

            float cachedX = startX;
            float cachedY = (startY += spaceY);

            for (int i = 0; i < unit.statsList.Count; i++)
            {
                GUI.Box(new Rect(startX, cachedY, blockWidth, blockHeight), "");

                EditorGUI.LabelField(new Rect(startX + 6, startY += 3, width, height), "Level " + (i + 1), TDE.headerS);

                GUI.color = new Color(1f, .25f, .25f, 1f);
                if (GUI.Button(new Rect(startX + blockWidth - 1.5f * widthS - 3, startY, widthS * 1.5f, 14), "remove"))
                {
                    if (unit.statsList.Count > 1)
                    {
                        unit.statsList.RemoveAt(i); i -= 1;
                    }
                }
                GUI.color = Color.white;

                _EType tType = _EType.TAOE;
                if (unit.IsTurret())
                {
                    tType = _EType.TTurret;
                }
                else if (unit.IsSupport())
                {
                    tType = _EType.TSupport;
                }
                else if (unit.IsResource())
                {
                    tType = _EType.TRsc;
                }
                else if (unit.IsMine())
                {
                    tType = _EType.TMine;
                }
                else if (unit.IsBlock())
                {
                    tType = _EType.TBlock;
                }


                blockHeight = DrawStats(startX, startY + spaceY + 3, unit.statsList[i], tType, true) - cachedY + 5;
                startY      = cachedY;

                startX += blockWidth + 10;

                maxX = startX;
            }
            startY += blockHeight;
            startX  = cachedX - 15;

            return(startY);
        }
Esempio n. 22
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

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

            GUI.changed = false;

            Undo.RecordObject(instance, "TowerManager");

            EditorGUILayout.Space();

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

            cont = new GUIContent("Auto Adjust Texture:", "Check to automatically adjust the texture on the platform to fit the grid");
            instance.autoAdjustTextureToGrid = EditorGUILayout.Toggle(cont, instance.autoAdjustTextureToGrid);

            EditorGUILayout.Space();

            cont = new GUIContent("Free Form Mode:", "Check to enable free form placement of tower, they can be placed anywhere in the world (not limited to platform) as long as the space is not occupied by other towers or obstacle\n\nOnly Applicable for DragNDrop mode");
            instance.freeFormMode = EditorGUILayout.Toggle(cont, instance.freeFormMode);

            cont = new GUIContent("Cast For Terrain:", "Check to have the raycast to get a position from terrain object in the scene when trying to look for a build pos.\n\nThis is only useful for DragNDrop mode when not using when the tower need to place on the terrain even there is no valid build point\nHowever you need to make sure the platform are not obstructed by the terrain collider\n\nThis is always true when using free-form mode");
            instance.raycastForTerrain = EditorGUILayout.Toggle(cont, instance.raycastForTerrain);

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MaxWidth(10));
            showList = EditorGUILayout.Foldout(showList, "Show Tower List");
            EditorGUILayout.EndHorizontal();
            if (showList)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("EnableAll") && !Application.isPlaying)
                {
                    instance.unavailablePrefabIDList = new List <int>();
                }
                if (GUILayout.Button("DisableAll") && !Application.isPlaying)
                {
                    instance.unavailablePrefabIDList = TowerDB.GetPrefabIDList();
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();


                List <UnitTower> towerList = TowerDB.GetList();
                for (int i = 0; i < towerList.Count; i++)
                {
                    if (towerList[i].hideInInspector)
                    {
                        continue;
                    }

                    UnitTower tower = towerList[i];

                    GUILayout.BeginHorizontal();

                    EditorGUILayout.Space();

                    GUILayout.Box("", GUILayout.Width(40), GUILayout.Height(40));
                    TDE.DrawSprite(GUILayoutUtility.GetLastRect(), tower.icon, tower.desp, false);

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

                    EditorGUI.BeginChangeCheck();
                    bool flag = !instance.unavailablePrefabIDList.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.unavailablePrefabIDList.Contains(tower.prefabID))
                        {
                            instance.unavailablePrefabIDList.Add(tower.prefabID);
                        }
                        else if (flag)
                        {
                            instance.unavailablePrefabIDList.Remove(tower.prefabID);
                        }
                    }

                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.Space();

            DefaultInspector();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }
Esempio n. 23
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

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

            GUI.changed = false;

            Undo.RecordObject(instance, "BuildPlatform");

            EditorGUILayout.Space();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MaxWidth(10));
            showList = EditorGUILayout.Foldout(showList, "Show Tower List");
            EditorGUILayout.EndHorizontal();
            if (showList)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("EnableAll") && !Application.isPlaying)
                {
                    instance.unavailablePrefabIDList = new List <int>();
                }
                if (GUILayout.Button("DisableAll") && !Application.isPlaying)
                {
                    instance.unavailablePrefabIDList = TowerDB.GetPrefabIDList();
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();


                List <UnitTower> towerList = TowerDB.GetList();
                for (int i = 0; i < towerList.Count; i++)
                {
                    if (towerList[i].hideInInspector)
                    {
                        continue;
                    }

                    UnitTower tower = towerList[i];

                    GUILayout.BeginHorizontal();

                    EditorGUILayout.Space();

                    GUILayout.Box("", GUILayout.Width(40), GUILayout.Height(40));
                    TDE.DrawSprite(GUILayoutUtility.GetLastRect(), tower.icon, tower.desp, false);

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

                    EditorGUI.BeginChangeCheck();
                    bool flag = !instance.unavailablePrefabIDList.Contains(tower.prefabID) ? true : false;
                    flag = EditorGUILayout.Toggle(new GUIContent(" - enabled: ", "check to enable the tower type to be build on this platform"), flag);

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

                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.Space();

            DefaultInspector();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }
Esempio n. 24
0
        public string _PurchasePerk(Perk perk, bool useRsc = true)
        {
            string text = perk.Purchase(useRsc);

            if (text != "")
            {
                return(text);
            }

            if (onPerkPurchasedE != null)
            {
                onPerkPurchasedE(perk);
            }

            //process the prereq for other perk
            for (int i = 0; i < perkList.Count; i++)
            {
                Perk perkTemp = perkList[i];
                if (perkTemp.purchased || perkTemp.prereq.Count == 0)
                {
                    continue;
                }
                perkTemp.prereq.Remove(perk.ID);
            }


            perkPoint += 1;
            if (onPerkPointE != null)
            {
                onPerkPointE(perkPoint);
            }

            if (perk.type == _PerkType.NewTower)
            {
                List <UnitTower> towerList = TowerDB.Load();
                for (int i = 0; i < towerList.Count; i++)
                {
                    if (towerList[i].prefabID == perk.itemIDList[0])
                    {
                        unlockedTower.Add(towerList[i]);
                        BuildManager.AddNewTower(towerList[i]);
                    }
                }
            }
            else if (perk.type == _PerkType.NewAbility)
            {
                List <Ability> abilityList = AbilityDB.Load();
                for (int i = 0; i < abilityList.Count; i++)
                {
                    if (abilityList[i].ID == perk.itemIDList[0])
                    {
                        unlockedAbility.Add(abilityList[i]);
                        AbilityManager.AddNewAbility(abilityList[i]);
                    }
                }
            }
            else if (perk.type == _PerkType.NewFPSWeapon)
            {
                List <FPSWeapon> FPSWeaponList = FPSWeaponDB.Load();
                for (int i = 0; i < FPSWeaponList.Count; i++)
                {
                    if (FPSWeaponList[i].prefabID == perk.itemIDList[0])
                    {
                        unlockedWeapon.Add(FPSWeaponList[i]);
                        FPSControl.AddNewWeapon(FPSWeaponList[i]);
                    }
                }
            }

            else if (perk.type == _PerkType.GainLife)
            {
                GameControl.GainLife((int)Random.Range(perk.value, perk.valueAlt));
            }
            else if (perk.type == _PerkType.LifeCap)
            {
                lifeCap += (int)perk.value; GameControl.GainLife(0);
            }
            else if (perk.type == _PerkType.LifeRegen)
            {
                lifeRegen += perk.value;
            }
            else if (perk.type == _PerkType.LifeWaveClearedBonus)
            {
                lifeWaveClearedBonus += (int)perk.value;
            }

            else if (perk.type == _PerkType.GainRsc)
            {
                List <int> valueList = new List <int>();
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    valueList.Add((int)perk.valueRscList[i]);
                }
                ResourceManager.GainResource(valueList, null, false);                   //dont pass multiplier and dont use multiplier
            }
            else if (perk.type == _PerkType.RscRegen)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscRegen[i] += perk.valueRscList[i];
                }
            }
            else if (perk.type == _PerkType.RscGain)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscGain[i] += perk.valueRscList[i];
                }
            }
            else if (perk.type == _PerkType.RscCreepKilledGain)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscCreepKilledGain[i] += perk.valueRscList[i];
                }
            }
            else if (perk.type == _PerkType.RscWaveClearedGain)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscWaveClearedGain[i] += perk.valueRscList[i];
                }
            }
            else if (perk.type == _PerkType.RscResourceTowerGain)
            {
                for (int i = 0; i < perk.valueRscList.Count; i++)
                {
                    rscRscTowerGain[i] += perk.valueRscList[i];
                }
            }

            else if (perk.type == _PerkType.Tower)
            {
                ModifyTowerModifier(globalTowerModifier, perk);
            }
            else if (perk.type == _PerkType.TowerSpecific)
            {
                for (int i = 0; i < perk.itemIDList.Count; i++)
                {
                    int ID = TowerModifierExist(perk.itemIDList[i]);
                    if (ID == -1)
                    {
                        PerkTowerModifier towerModifier = new PerkTowerModifier();
                        towerModifier.prefabID = perk.itemIDList[i];
                        towerModifierList.Add(towerModifier);
                        ID = towerModifierList.Count - 1;
                    }
                    ModifyTowerModifierInList(ID, perk);
                }
            }
            else if (perk.type == _PerkType.Ability)
            {
                ModifyAbilityModifier(globalAbilityModifier, perk);
            }
            else if (perk.type == _PerkType.AbilitySpecific)
            {
                for (int i = 0; i < perk.itemIDList.Count; i++)
                {
                    int ID = AbilityModifierExist(perk.itemIDList[i]);
                    if (ID == -1)
                    {
                        PerkAbilityModifier abilityModifier = new PerkAbilityModifier();
                        abilityModifier.abilityID = perk.itemIDList[i];
                        abilityModifierList.Add(abilityModifier);
                        ID = abilityModifierList.Count - 1;
                    }
                    ModifyAbilityModifierInList(ID, perk);
                }
            }
            else if (perk.type == _PerkType.FPSWeapon)
            {
                ModifyFPSWeaponModifier(globalFPSWeaponModifier, perk);
            }
            else if (perk.type == _PerkType.FPSWeaponSpecific)
            {
                for (int i = 0; i < perk.itemIDList.Count; i++)
                {
                    int ID = FPSWeaponModifierExist(perk.itemIDList[i]);
                    if (ID == -1)
                    {
                        PerkFPSWeaponModifier weaponModifier = new PerkFPSWeaponModifier();
                        weaponModifier.prefabID = perk.itemIDList[i];
                        FPSWeaponModifierList.Add(weaponModifier);
                        ID = FPSWeaponModifierList.Count - 1;
                    }
                    ModifyFPSWeaponModifierInList(ID, perk);
                }
            }

            else if (perk.type == _PerkType.EnergyRegen)
            {
                energyRegen += perk.value;
            }
            else if (perk.type == _PerkType.EnergyIncreaseCap)
            {
                energyCap += perk.value;
            }
            else if (perk.type == _PerkType.EnergyCreepKilledBonus)
            {
                energyCreepKilledBonus += perk.value;
            }
            else if (perk.type == _PerkType.EnergyWaveClearedBonus)
            {
                energyWaveClearedBonus += perk.value;
            }

            return("");
        }