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)); }
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; cont = new GUIContent("Building Effect:", "The effect object to be spawned when the tower start a building process\nThis is entirely optional"); EditorGUI.LabelField(new Rect(startX, startY, width, height), cont); tower.buildingEffect = (GameObject)EditorGUI.ObjectField(new Rect(startX + spaceX, startY, width, height), tower.buildingEffect, typeof(GameObject), false); startY += 20; cont = new GUIContent("Built Effect:", "The effect object to be spawned when the tower has finish a build process\nThis is entirely optional"); EditorGUI.LabelField(new Rect(startX, startY, width, height), cont); tower.builtEffect = (GameObject)EditorGUI.ObjectField(new Rect(startX + spaceX, startY, width, height), tower.builtEffect, typeof(GameObject), false); startY += 40; 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, 48, 15), "Select")) { 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, 15), "-1")) { if (tower.stats.Count > 1) { tower.stats.RemoveAt(tower.stats.Count - 1); } } if (GUI.Button(new Rect(startX + 165, startY, 50, 15), "+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, 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, 48, 15), "Select")) { 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, 48, 15), "Select")) { 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, 460); startX = cachedX; float maxHeight = 0; float maxContentHeight = 0; minimiseStat = EditorGUI.Foldout(new Rect(startX, startY, 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, 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)); }