public static bool AddTower(int towerID) { if (buildManager != null) { foreach (UnitTower tower in buildManager.availableTowers) { if (tower.prefabID == towerID) { //~ Debug.Log("tower existed"); return(false); } } UnitTower newTower = null; GameObject prefabObj = Resources.Load("PrefabListTower", typeof(GameObject)) as GameObject; if (prefabObj != null) { TowerListPrefab prefab = prefabObj.GetComponent <TowerListPrefab>(); if (prefab != null) { for (int i = 0; i < prefab.towerList.Count; i++) { if (prefab.towerList[i].prefabID == towerID) { newTower = prefab.towerList[i]; } } } } if (newTower != null) { UnitTower[] towerList = new UnitTower[buildManager.availableTowers.Length + 1]; for (int i = 0; i < towerList.Length - 1; i++) { //~ towerList[i]=buildManager.towers[i]; towerList[i] = buildManager.availableTowers[i]; } towerList[towerList.Length - 1] = newTower; //~ buildManager.towers=towerList; buildManager.availableTowers = towerList; InitSampleTower(towerList.Length - 1); //~ foreach(PlatformTD platform in platforms){ //~ platform.AddTower //~ } return(true); } } return(false); }
static void GetTower() { towerList = new UnitTower[0]; //~ nameList=new string[0]; GameObject obj = Resources.Load("PrefabListTower", typeof(GameObject)) as GameObject; if (obj != null) { TowerListPrefab prefab = obj.GetComponent <TowerListPrefab>(); if (prefab != null) { for (int i = 0; i < prefab.towerList.Count; i++) { if (prefab.towerList[i] == null) { prefab.towerList.RemoveAt(i); i -= 1; } } towerList = new UnitTower[prefab.towerList.Count]; bm.towers = new UnitTower[prefab.towerList.Count]; //~ nameList=new string[prefab.towerList.Count]; for (int i = 0; i < prefab.towerList.Count; i++) { towerList[i] = prefab.towerList[i]; bm.towers[i] = prefab.towerList[i]; } } } List <TowerAvailability> tempAvaiList = new List <TowerAvailability>(); foreach (UnitTower tower in towerList) { bool match = false; foreach (TowerAvailability avai in bm.towerAvaiList) { if (avai.ID == tower.prefabID) { match = true; tempAvaiList.Add(avai); break; } } if (!match) { tempAvaiList.Add(new TowerAvailability(tower.prefabID)); } } bm.towerAvaiList = tempAvaiList; }
static void GetTower() { towerList = new UnitTower[0]; //~ nameList=new string[0]; GameObject obj = Resources.Load("PrefabListTower", typeof(GameObject)) as GameObject; if (obj != null) { TowerListPrefab prefab = obj.GetComponent <TowerListPrefab>(); if (prefab != null) { towerList = new UnitTower[prefab.towerList.Count]; //~ platform.towers=new UnitTower[prefab.towerList.Count]; //~ nameList=new string[prefab.towerList.Count]; for (int i = 0; i < prefab.towerList.Count; i++) { towerList[i] = prefab.towerList[i]; //~ platform.towers[i]=prefab.towerList[i]; } } } if (!EditorApplication.isPlaying) { List <TowerAvailability> tempAvaiList = new List <TowerAvailability>(); foreach (UnitTower tower in towerList) { bool match = false; foreach (TowerAvailability avai in platform.towerAvaiList) { if (avai.ID == tower.prefabID) { match = true; tempAvaiList.Add(avai); break; } } if (!match) { tempAvaiList.Add(new TowerAvailability(tower.prefabID)); } } platform.towerAvaiList = tempAvaiList; } //~ Debug.Log(towerList.Length+" "+platform.towerAvaiList.Count); }
static void LoadTower(){ GameObject obj=Resources.Load("PrefabListTower", typeof(GameObject)) as GameObject; if(obj!=null){ TowerListPrefab prefab=obj.GetComponent<TowerListPrefab>(); if(prefab!=null){ towerList=prefab.towerList; towerNameList=new string[towerList.Count]; towerIDMapList=new int[towerList.Count]; for(int i=0; i<towerList.Count; i++){ towerNameList[i]=towerList[i].unitName; towerIDMapList[i]=towerList[i].prefabID; } } } }
//~ private static List<Tower> towerList=new List<Resource>(); // Add menu named "PerkEditor" to the Window menu //[MenuItem ("TDTK/PerkEditor")] public static void Init() { // Get existing open window or if none, make a new one: window = (TowerManager)EditorWindow.GetWindow(typeof(TowerManager)); window.minSize = new Vector2(375, 449); window.maxSize = new Vector2(375, 800); GameObject obj = Resources.Load("PrefabListTower", typeof(GameObject)) as GameObject; if (obj == null) { obj = CreatePrefab(); } prefab = obj.GetComponent <TowerListPrefab>(); if (prefab == null) { prefab = obj.AddComponent <TowerListPrefab>(); } towerList = prefab.towerList; for (int i = 0; i < towerList.Count; i++) { //~ towerList[i].prefabID=i; if (towerList[i] != null) { towerIDList.Add(towerList[i].prefabID); } else { towerList.RemoveAt(i); i -= 1; } } //~ resourceList.Add(new Resource()); //~ Load(); //AssetDatabase.GetAssetPath //~ for(int i=0; i<towerList.Count; i++) EditorUtility.SetDirty(towerList[i]); }
public void InitTower() { GameObject obj = Resources.Load("PrefabListTower", typeof(GameObject)) as GameObject; if (obj != null) { TowerListPrefab prefab = obj.GetComponent <TowerListPrefab>(); if (prefab != null) { for (int i = 0; i < prefab.towerList.Count; i++) { if (prefab.towerList[i] == null) { prefab.towerList.RemoveAt(i); i -= 1; } } List <UnitTower> tempList = new List <UnitTower>(); towers = new UnitTower[prefab.towerList.Count]; for (int i = 0; i < prefab.towerList.Count; i++) { towers[i] = prefab.towerList[i]; } if (towerAvaiList.Count > 0) { for (int i = 0; i < prefab.towerList.Count; i++) { UnitTower tower = prefab.towerList[i]; tower.thisObj = tower.gameObject; bool match = false; foreach (TowerAvailability avai in towerAvaiList) { if (avai.ID == tower.prefabID) { match = true; if (avai.enabledInLvl && !tempList.Contains(tower)) { tempList.Add(tower); } break; } } if (!match) { towerAvaiList.Add(new TowerAvailability(tower.prefabID)); tempList.Add(tower); } } availableTowers = new UnitTower[tempList.Count]; for (int i = 0; i < availableTowers.Length; i++) { availableTowers[i] = tempList[i]; } } else { availableTowers = new UnitTower[prefab.towerList.Count]; for (int i = 0; i < prefab.towerList.Count; i++) { availableTowers[i] = prefab.towerList[i]; towerAvaiList.Add(new TowerAvailability(prefab.towerList[i].prefabID)); } } } } }