private void DrawSearchSpawnersButton() { if (GUILayout.Button("Search spawners", GUILayout.MaxWidth(120), GUILayout.MinWidth(100))) { // if and gameobjects with component <Spawner> found hasSearchedForSpawners = SearchForSpawners(); if (hasSearchedForSpawners) { // there are spawners to initialize searchButtonPressed = true; // if all spawners properties have not been identifined if (!SpawnerFields.SetUpSerializedProperties(totalSpawners)) { // dont continue to initilization, data is missing hasSearchedForSpawners = false; searchButtonPressed = false; } } } }
void OnGUI() { // Draw "search" button and check if clicked DrawSearchSpawnersButton(); // if initialized if (hasSearchedForSpawners) { if (searchButtonPressed) { // if button pressed - re-initialize everything graphPanel = SetUpGraphPanel(); SpawnTypes.SetAllTypes(totalSpawners); numberOfTotalTypes = SpawnTypes.GetAllTypes().Count; spawnGraph = new SpawnGraph(graphPanel, totalTime + 1); IncDecGraphPanelRect(0, 20 * numberOfTotalTypes, 0, 0); SpawnerFields.SetTotalFoldoutsPerUnitType(numberOfTotalTypes); searchButtonPressed = false; } // if show spawners data == true showSpawners = EditorGUILayout.Foldout(showSpawners, "Show spawners", EditorStyles.foldout); if (showSpawners && numberOfTotalTypes > 0) { // Draw spawners and properties SpawnerFields.DrawFormatedSpawnerFields(); // Draw graph's background EditorGUI.DrawRect(graphPanel.GetRect(), graphPanelBackgroundColor); // Draw the graph spawnGraph.DrawUnitsPerSecGraph(graphPanel.GetRect()); } } else { EditorGUILayout.LabelField("Press: Search spawners first!", EditorStyles.miniLabel); } }