public static Dictionary <string, float[]> GetUnitsPerSec(int totalTime) { Dictionary <string, float[]> unitsPerType = new Dictionary <string, float[]>(); #region FindTotalUnitsPerType Spawner[] totalSpawners = SpawnersToolWindow.GetSpawners(); // for each group of spawners with the same tag foreach (Spawner spawner in totalSpawners) { // if dictionary has already defined this unit type if (unitsPerType.ContainsKey(spawner.GetUnitToSpawn().name)) { // get this spawner's unit / sec activity float[] unitsPerSec = FindUnitsPerSec(spawner.numberOfUnitsToSpawn, spawner.spawningFrequency, totalTime); for (int time = 0; time < totalTime; time++) { unitsPerType[spawner.GetUnitToSpawn().name][time] += unitsPerSec[time]; } } else { unitsPerType.Add(spawner.GetUnitToSpawn().name, FindUnitsPerSec(spawner.numberOfUnitsToSpawn, spawner.spawningFrequency, totalTime)); } } #endregion return(unitsPerType); }
// Set active or not a unit type foldout field. Increases or decreases the Y position of the graph panel accordingly private static void ActivateUnitTypeFoldout(bool should, int typeIndex, int totalUnitsPerType) { if (should != whichSpawnersGroupPerTypeToFoldout[typeIndex]) { if (should) { SpawnersToolWindow.IncDecGraphPanelRect(0, 20 * totalUnitsPerType, 0, 0); } else { SpawnersToolWindow.IncDecGraphPanelRect(0, -20 * totalUnitsPerType, 0, 0); } whichSpawnersGroupPerTypeToFoldout[typeIndex] = should; } }
static void Init() { // Get existing open window or if none, make a new one: activeWindow = (SpawnersToolWindow)EditorWindow.GetWindow(typeof(SpawnersToolWindow)); activeWindow.Show(); }