public SpawnGraph(MyEditorPanel graphP, int totalTime) { totalTimeToCount = totalTime; graphPanel = graphP; maxUnits = (int)SpawnTypes.GetMaximunNumberOfUnits(totalTimeToCount); totalUnitsAndUnitsPerSecForAllTypes = SpawnTypes.GetUnitsPerSec(totalTimeToCount); // Set up color array with random colors if (unitTypesColors == null) { SavedUnitTypeColorsArray savedCollorArrayObject = JsonLib.LoadGameData(); if (savedCollorArrayObject != null && savedCollorArrayObject.colorArray.Length > 0) { //Debug.Log("Unit types graph colors loaded from previous session"); unitTypesColors = savedCollorArrayObject.colorArray; } else { //Debug.Log("No unit types graph colors loaded from previous session"); unitTypesColors = new Color[150]; for (int i = 0; i != unitTypesColors.Length; i++) { unitTypesColors[i] = new Color(Random.Range(0, 0.9f), Random.Range(0, 0.9f), Random.Range(0, 0.9f), Random.Range(0, 0.9f)); unitTypesColors[i].a = 1; } } JsonLib.SaveGameData(new SavedUnitTypeColorsArray(unitTypesColors)); } }
// Draws spawners by grouping them depending on the unit type they spawn // Draws serialized properties (Spawner.transform, UntiToSpawnPrefab, SpawnFrequency, TotalUnitsToSpawn) public static void DrawFormatedSpawnerFields() { // if there are serialized properties to show if (propertiesPerSpawner.Keys.Count > 0) { bool foldout = false; EditorGUILayout.BeginVertical(); int unitTypeIndex = 0; foreach (string unitType in SpawnTypes.GetAllTypes()) { foldout = EditorGUILayout.Foldout(whichSpawnersGroupPerTypeToFoldout[unitTypeIndex], "Show spawners with unit types: " + unitType); int totalUnitsPerType = 0; foreach (SerializedObject obj in propertiesPerSpawner.Keys) { // check if this spawner.unitType is spawning now if (unitType == ((Spawner)obj.targetObject).GetUnitToSpawn().name) { // an other spawner with that unit type totalUnitsPerType++; // if foldout for this spawner's unit type is true if (whichSpawnersGroupPerTypeToFoldout[unitTypeIndex]) { EditorGUILayout.BeginHorizontal(); // Draw serialized properties of current serialized <Spawn> object foreach (SerializedProperty property in propertiesPerSpawner[obj]) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(property, new GUIContent(""), GUILayout.Width(150)); // Chack if any changes have been made by the user and inform the valus in the target <Spawner> script if (EditorGUI.EndChangeCheck()) { ChangeSerializedPropertyValue(property); } } EditorGUILayout.EndHorizontal(); } } } // Check if user clicked on any foldout field and respond ActivateUnitTypeFoldout(foldout, unitTypeIndex, totalUnitsPerType); unitTypeIndex++; } EditorGUILayout.EndVertical(); } }
private void DrawUnitTypeList(Rect graphPanel) { for (int line = 0; line != SpawnTypes.GetAllTypes().Count; line++) { Rect rect = new Rect(graphPanel); rect.position = rect.position + new Vector2(-wavePanelXOffsetFromUnitTypes, line * collumAndLineSize); rect.width = unitTypesListWidth; rect.height = unitTypesListHeight; EditorGUI.LabelField(rect, SpawnTypes.GetAllTypes()[line]); rect.x += unitTypesListWidth; rect.width = 50; rect.height = 10; EditorGUI.BeginChangeCheck(); unitTypesColors[line] = EditorGUI.ColorField(rect, unitTypesColors[line]); if (EditorGUI.EndChangeCheck()) { Debug.Log("Color of unit type: " + SpawnTypes.GetAllTypes()[line] + " changed to " + unitTypesColors[line].ToString()); JsonLib.SaveGameData(new SavedUnitTypeColorsArray(unitTypesColors)); } } }
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); } }