//not in used void ConfigureSpawnItemList() { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Spawn Item List:", ""), GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); if (GUILayout.Button("+", GUILayout.Width(40), GUILayout.MaxHeight(14))) { instance.spawnItemList.Add(new CollectibleSpawnInfo()); } if (GUILayout.Button("-", GUILayout.Width(40), GUILayout.MaxHeight(14))) { instance.spawnItemList.RemoveAt(instance.spawnItemList.Count - 1); } EditorGUILayout.EndHorizontal(); //~ EditorGUILayout.BeginHorizontal(); //~ SpaceH(20); //~ EditorGUILayout.LabelField("Item", GUILayout.Width(130)); //~ EditorGUILayout.LabelField("chance", GUILayout.Width(50)); //~ EditorGUILayout.LabelField("cd:", GUILayout.Width(30)); //~ EditorGUILayout.EndHorizontal(); for (int i = 0; i < instance.spawnItemList.Count; i++) { CollectibleSpawnInfo spInfo = instance.spawnItemList[i]; EditorGUILayout.BeginHorizontal(); //~ EditorGUILayout.LabelField(" -", GUILayout.MaxWidth(25)); SpaceH(10); int itemIdx = spInfo.item != null?TDSEditor.GetCollectibleIndex(spInfo.item.ID) : 0; EditorGUILayout.LabelField("-", GUILayout.MaxWidth(10)); itemIdx = EditorGUILayout.Popup(itemIdx, collectibleLabel, GUILayout.Width(130)); if (itemIdx == 0) { spInfo.item = null; } else if (itemIdx > 0) { spInfo.item = collectibleDB.collectibleList[itemIdx - 1]; } spInfo.chance = EditorGUILayout.FloatField(spInfo.chance, GUILayout.Width(30)); //SpaceH(10); spInfo.cooldown = EditorGUILayout.FloatField(spInfo.cooldown, GUILayout.Width(30)); //~ spInfo.currentCD=EditorGUILayout.FloatField(spInfo.currentCD, GUILayout.Width(30)); EditorGUILayout.EndHorizontal(); } }
Vector2 DrawSpawnerConfigurator(float startX, float startY, CollectibleSpawner spawner) { startY += 10; cont = new GUIContent("Spawn Area:", "The area which the unit should be spawn in\nIf unspecified, the unit will simply be spawned at the position of the spawner"); EditorGUI.LabelField(new Rect(startX, startY, width, height), cont); spawner.spawnArea = (TDSArea)EditorGUI.ObjectField(new Rect(startX + spaceX, startY, width, height), spawner.spawnArea, typeof(TDSArea), true); startY += 10; if (GUI.Button(new Rect(startX + spaceX + width + 20, startY, 80, height), "Assign Self")) { TDSArea area = spawner.gameObject.GetComponent <TDSArea>(); if (area == null) { area = spawner.gameObject.AddComponent <TDSArea>(); } spawner.spawnArea = area; } cont = new GUIContent("Spawn Upon Start:", "Check to have the spawner start spawning as soon as the game start"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); spawner.spawnUponStart = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), spawner.spawnUponStart); cont = new GUIContent("Start Delay:", "Delay (in second) before the spawning start"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); //if(spawner.spawnUponStart) spawner.startDelay = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), spawner.startDelay); //else // EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); startY += 10; cont = new GUIContent("Spawn Cooldown:", "The cooldown between each spawn attempt"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); spawner.spawnCD = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), spawner.spawnCD); cont = new GUIContent("Max Item Count:", "The maximum amount of active item in the game allowed by this spawner at any given item"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); spawner.maxItemCount = EditorGUI.DelayedIntField(new Rect(startX + spaceX, startY, 40, height), spawner.maxItemCount); cont = new GUIContent("Spawn Chance:", "The chance to successfully spawn an item during each cooldown cycle. Takes value from 0-1 with 0.3 being 30% to successfully spawn an item"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); spawner.spawnChance = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), spawner.spawnChance); cont = new GUIContent("Fail Modifier:", "A modifier to the spawn chance should a spawn attempt fail (to prevent the attempt fail too many time in a row). ie if modifier is set as 0.1, each fail attempt will increase the spawn chance by 10%"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); spawner.failModifier = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), spawner.failModifier); startY += 10; cont = new GUIContent("Spawn Item:", "The collectible item available to this spawner"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont, headerStyle); int enabledCount = 0; for (int i = 0; i < collectibleDB.collectibleList.Count; i++) { Collectible colt = collectibleDB.collectibleList[i]; CollectibleSpawnInfo spawnInfo = null; bool enabled = false; for (int n = 0; n < spawner.spawnItemList.Count; n++) { enabled = spawner.spawnItemList[n].item == colt; if (enabled) { spawnInfo = spawner.spawnItemList[n]; break; } } bool enabledCached = enabled; float cachedX = startX; TDSEditorUtility.DrawSprite(new Rect(startX + 10, startY += spaceY, 30, 30), colt.icon, colt.desp); cont = new GUIContent(colt.collectibleName, colt.desp); EditorGUI.LabelField(new Rect(startX + 50, startY += 10, width, height), cont); enabled = EditorGUI.Toggle(new Rect(startX += (width), startY, 20, height), enabled); if (spawnInfo != null) { cont = new GUIContent("Chance:", "Chance to spawn this item.\nThe way it works is a check against the individual item chance.\nA final candidate is then chosen over all item that pass the check.\nTakes value from 0-1 with 0.3 being 30% to pass the check"); EditorGUI.LabelField(new Rect(startX += 35, startY, width, height), cont); spawnInfo.chance = EditorGUI.DelayedFloatField(new Rect(startX + 55, startY, 40, height), spawnInfo.chance); cont = new GUIContent("Cooldown:", "The duration (in second) in which the item will be made unavailable after a successful spawn"); EditorGUI.LabelField(new Rect(startX += 120, startY, width, height), cont); spawnInfo.cooldown = EditorGUI.DelayedFloatField(new Rect(startX + 65, startY, 40, height), spawnInfo.cooldown); } if (enabled != enabledCached) { if (enabled) { spawnInfo = new CollectibleSpawnInfo(); spawnInfo.item = colt; spawner.spawnItemList.Insert(enabledCount, spawnInfo); } else { spawner.spawnItemList.Remove(spawnInfo); } } if (enabled) { enabledCount += 1; } startY += 4; startX = cachedX; } return(new Vector2(startX, startY + (1.5f * spaceY))); }
Vector2 DrawSpawnerConfigurator(float startX, float startY, CollectibleSpawner spawner) { startY+=10; cont=new GUIContent("Spawn Area:", "The area which the unit should be spawn in\nIf unspecified, the unit will simply be spawned at the position of the spawner"); EditorGUI.LabelField(new Rect(startX, startY, width, height), cont); spawner.spawnArea=(TDSArea)EditorGUI.ObjectField(new Rect(startX+spaceX, startY, width, height), spawner.spawnArea, typeof(TDSArea), true); startY+=10; if(GUI.Button(new Rect(startX+spaceX+width+20, startY, 80, height), "Assign Self")){ TDSArea area=spawner.gameObject.GetComponent<TDSArea>(); if(area==null) area=spawner.gameObject.AddComponent<TDSArea>(); spawner.spawnArea=area; } cont=new GUIContent("Spawn Upon Start:", "Check to have the spawner start spawning as soon as the game start"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); spawner.spawnUponStart=EditorGUI.Toggle(new Rect(startX+spaceX, startY, width, height), spawner.spawnUponStart); cont=new GUIContent("Start Delay:", "Delay (in second) before the spawning start"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); //if(spawner.spawnUponStart) spawner.startDelay=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), spawner.startDelay); //else // EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); startY+=10; cont=new GUIContent("Spawn Cooldown:", "The cooldown between each spawn attempt"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); spawner.spawnCD=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), spawner.spawnCD); cont=new GUIContent("Max Item Count:", "The maximum amount of active item in the game allowed by this spawner at any given item"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); spawner.maxItemCount=EditorGUI.IntField(new Rect(startX+spaceX, startY, 40, height), spawner.maxItemCount); cont=new GUIContent("Spawn Chance:", "The chance to successfully spawn an item during each cooldown cycle. Takes value from 0-1 with 0.3 being 30% to successfully spawn an item"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); spawner.spawnChance=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), spawner.spawnChance); cont=new GUIContent("Fail Modifier:", "A modifier to the spawn chance should a spawn attempt fail (to prevent the attempt fail too many time in a row). ie if modifier is set as 0.1, each fail attempt will increase the spawn chance by 10%"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); spawner.failModifier=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), spawner.failModifier); startY+=10; cont=new GUIContent("Spawn Item:", "The collectible item available to this spawner"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont, headerStyle); int enabledCount=0; for(int i=0; i<collectibleDB.collectibleList.Count; i++){ Collectible colt=collectibleDB.collectibleList[i]; CollectibleSpawnInfo spawnInfo=null; bool enabled=false; for(int n=0; n<spawner.spawnItemList.Count; n++){ enabled=spawner.spawnItemList[n].item==colt; if(enabled){ spawnInfo=spawner.spawnItemList[n]; break; } } bool enabledCached=enabled; float cachedX=startX; TDSEditorUtility.DrawSprite(new Rect(startX+10, startY+=spaceY, 30, 30), colt.icon, colt.desp); cont=new GUIContent(colt.collectibleName, colt.desp); EditorGUI.LabelField(new Rect(startX+50, startY+=10, width, height), cont); enabled=EditorGUI.Toggle(new Rect(startX+=(width), startY, 20, height), enabled); if(spawnInfo!=null){ cont=new GUIContent("Chance:", "Chance to spawn this item.\nThe way it works is a check against the individual item chance.\nA final candidate is then chosen over all item that pass the check.\nTakes value from 0-1 with 0.3 being 30% to pass the check"); EditorGUI.LabelField(new Rect(startX+=35, startY, width, height), cont); spawnInfo.chance=EditorGUI.FloatField(new Rect(startX+55, startY, 40, height), spawnInfo.chance); cont=new GUIContent("Cooldown:", "The duration (in second) in which the item will be made unavailable after a successful spawn"); EditorGUI.LabelField(new Rect(startX+=120, startY, width, height), cont); spawnInfo.cooldown=EditorGUI.FloatField(new Rect(startX+65, startY, 40, height), spawnInfo.cooldown); } if(enabled!=enabledCached){ if(enabled){ spawnInfo=new CollectibleSpawnInfo(); spawnInfo.item=colt; spawner.spawnItemList.Insert(enabledCount, spawnInfo); } else spawner.spawnItemList.Remove(spawnInfo); } if(enabled) enabledCount+=1; startY+=4; startX=cachedX; } return new Vector2(startX, startY+(1.5f*spaceY)); }