private void OnEnable() { targetChunkData = target as LevelChunkData; numberOfLinesProperty = serializedObject.FindProperty("numberOfLines"); numberOfColumns = targetChunkData.GetNumberOfColumn; prefabLibrary = targetChunkData.GetPrefabLibrary; ComposePrefabsDictionary(); if (prefabsDictionnary.ContainsKey(100)) { currentBrushType = LevelChunkBrushType.Obstacle; SetCurrentBrushIndex(100); } else if (prefabsDictionnary.ContainsKey(200)) { currentBrushType = LevelChunkBrushType.Enemy; SetCurrentBrushIndex(200); } }
public void SetCurrentBrushIndex(object newBrushIndex) { currentBrushIndex = (int)newBrushIndex; if (!prefabsDictionnary.ContainsKey(currentBrushIndex)) { currentBrushIndex = 0; return; } LevelPrefabInformations linkedInfos = prefabsDictionnary[currentBrushIndex]; if (currentBrushIndex >= 100 && currentBrushIndex < 200) { currentBrushType = LevelChunkBrushType.Obstacle; } else if (currentBrushIndex >= 200 && currentBrushIndex < 300) { currentBrushType = LevelChunkBrushType.Enemy; } }
public override void OnInspectorGUI() { showBrutGrid = EditorGUILayout.Toggle("Show Brut Grid", showBrutGrid); Color baseGUIColor = GUI.color; serializedObject.Update(); bool gridSizeChanged = false; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(numberOfLinesProperty); if (numberOfLinesProperty.intValue < 1) { numberOfLinesProperty.intValue = 1; } if (EditorGUI.EndChangeCheck()) { gridSizeChanged = true; } if (showBrutGrid) { ShowBrutChunkGrid(); } else { GUILayout.Space(12); GUIStyle style = new GUIStyle(); style.alignment = TextAnchor.MiddleCenter; style.fontStyle = FontStyle.Bold; GUILayout.Label("GRID PAINTING", style); GUILayout.Space(8); EditorGUI.BeginChangeCheck(); currentBrushType = (LevelChunkBrushType)EditorGUILayout.EnumPopup("Brush Type", currentBrushType); if (EditorGUI.EndChangeCheck()) { switch (currentBrushType) { case (LevelChunkBrushType.Obstacle): if (prefabsDictionnary.ContainsKey(100)) { currentBrushIndex = 100; } else { currentBrushIndex = 0; } break; case (LevelChunkBrushType.Enemy): if (prefabsDictionnary.ContainsKey(200)) { currentBrushIndex = 200; } else { currentBrushIndex = 0; } break; } } if (GUILayout.Button("Choose Brush")) { GenerateBrushChoiceMenu(); } LevelPrefabInformations selectedPrefab = null; if (prefabsDictionnary.ContainsKey(currentBrushIndex)) { selectedPrefab = prefabsDictionnary[currentBrushIndex]; } else { currentBrushIndex = 0; } EditorGUILayout.BeginHorizontal(); GUIStyle selectedBrushLabelStyle = new GUIStyle(); selectedBrushLabelStyle.normal.textColor = selectedPrefab != null ? selectedPrefab.elementAttributedColor : Color.grey; selectedBrushLabelStyle.fontStyle = FontStyle.Bold; selectedBrushLabelStyle.fontSize = 16; selectedBrushLabelStyle.alignment = TextAnchor.LowerCenter; EditorGUILayout.BeginVertical(); GUILayout.Space(12); GUILayout.Label(selectedPrefab != null ? "Selected Brush : " + selectedPrefab.elementName : "No brush selected", selectedBrushLabelStyle); EditorGUILayout.EndVertical(); GUILayout.Space(8); EditorGUILayout.HelpBox("Alt + Left Clic to copy a Brush", MessageType.Info); EditorGUILayout.EndHorizontal(); Vector2 gridStartPos = new Vector2(10, 180); ShowChunkGrid(gridStartPos); } serializedObject.ApplyModifiedProperties(); if (gridSizeChanged) { targetChunkData.UpdateGridSize(); } }