private void RectsPresets(Rect rect, Color color, int i, string title, string chunkTitle, string gameSpeedTitle) { EditorGUI.DrawRect(rect, color); Rect titleRect = new Rect(rect.x, rect.y, rect.width, rect.height * .5f); EditorGUI.LabelField(new Rect(titleRect.x, titleRect.y - titleRect.height * .5f, titleRect.width, titleRect.height), "Recommendations", levelHolder.titleStyle); EditorGUI.LabelField(titleRect, title, levelHolder.titleStyle); EditorGUI.LabelField(titleRect, chunkTitle, levelHolder.chunkStyle); EditorGUI.LabelField(titleRect, gameSpeedTitle, levelHolder.gameSpeedStyle); Rect levelChunkRect = new Rect(rect.x, rect.y + rect.height, rect.width, rect.height * .5f); levelHolder.levelChunks[i] = EditorGUI.ObjectField(levelChunkRect, levelHolder.levelChunks[i], typeof(LevelChunk)) as LevelChunk; Rect intRect = new Rect(rect.x, levelChunkRect.y + levelChunkRect.height, rect.width, rect.height * .22f); levelHolder.gameSpeedValues[i] = EditorGUI.IntSlider(intRect, levelHolder.gameSpeedValues[i], 1, 3); Rect createRect = new Rect(rect.x, intRect.y + intRect.height, rect.width, rect.height * .22f); if (GUI.Button(createRect, "Create New Level Chunk")) { Debug.Log("Hello"); LevelChunk newLevelChunk = new LevelChunk(); newLevelChunk.colorList = new List <Color>(); newLevelChunk.rectList = new List <Rect>(); newLevelChunk.presetValues = new List <int>(); newLevelChunk.spritesList = new List <Sprite>(); for (int j = 0; j < 135; j++) { newLevelChunk.colorList.Add(Color.black); newLevelChunk.rectList.Add(new Rect(0, 0, 0, 0)); newLevelChunk.presetValues.Add(0); newLevelChunk.spritesList.Add(Resources.Load <Sprite>("EmptySprite")); } newLevelChunk.emptySprite = Resources.Load <Sprite>("EmptySprite"); newLevelChunk.enemySprite = Resources.Load <Sprite>("EnemySprite"); newLevelChunk.obstacleSprite = Resources.Load <Sprite>("ObstacleSprite"); newLevelChunk.selectedSprite = Resources.Load <Sprite>("EmptySprite"); AssetDatabase.CreateAsset(newLevelChunk, "Assets/Features/Levels/Chunks/Level Chunk" + Random.Range(0, 100000) + ".asset"); EditorUtility.SetDirty(newLevelChunk); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); levelHolder.levelChunks[i] = EditorGUI.ObjectField(levelChunkRect, newLevelChunk, typeof(LevelChunk)) as LevelChunk; } Repaint(); EditorUtility.SetDirty(levelHolder); }
private void OnEnable() { levelChunk = target as LevelChunk; filledChunk = serializedObject.FindProperty(nameof(levelChunk.filledChunk)); colorList = serializedObject.FindProperty(nameof(levelChunk.colorList)); selectedColor = serializedObject.FindProperty(nameof(levelChunk.selectedColor)); rectList = serializedObject.FindProperty(nameof(levelChunk.rectList)); presetValues = serializedObject.FindProperty(nameof(levelChunk.presetValues)); difficulty = serializedObject.FindProperty(nameof(levelChunk.difficulty)); }