void EditSet(object obj) { EnemyWaveSet set = (EnemyWaveSet)obj; EnemyWaveSetEditor w = EditorWindow.GetWindow(typeof(EnemyWaveSetEditor), true) as EnemyWaveSetEditor; w.SetEditor(set); }
void OnGUI() { if (manager != null) { float unit = EditorGUIUtility.singleLineHeight; float fix = unit * 1.25f; Rect r = new Rect(0, 0, position.width, position.height); float elementHeight = r.height - unit; if (managerWaveSet.arraySize > 3) { elementHeight = ((managerWaveSet.arraySize) * fix) + 8f; } #region StaticToolbar GUI.Box(new Rect(0, 0, position.width, position.height), GUIContent.none); GUI.Box(new Rect(0, 0, position.width, unit), GUIContent.none, EditorStyles.toolbar); if (GUI.Button(new Rect(position.width - 26, 0, 26, unit), EditorGUIUtility.FindTexture("d_Toolbar Plus"), EditorStyles.toolbarButton)) { managerWaveSet.InsertArrayElementAtIndex(managerWaveSet.arraySize); } #endregion #region ScrollView slider = GUI.BeginScrollView(new Rect(0, unit + 2, r.width, r.height), slider, new Rect(0, 0, r.width, elementHeight), false, true); r.y += 4; for (int l = 0; l < managerWaveSet.arraySize; l++) { float y = r.y + (l * fix); if (l % 2 == 0) { EditorGUI.DrawRect(new Rect(r.x, y - 2, r.width, fix), new Color(0.23f, 0.56f, 0.5f, 1f)); } else { EditorGUI.DrawRect(new Rect(r.x, y - 2, r.width, fix), new Color(0.23f, 0.56f, 0.5f, .8f)); } GUI.BeginGroup(new Rect(r.x, y, r.width, unit)); #region Menu if (new Rect(0, 0, r.width, unit).Contains(Event.current.mousePosition) && Event.current.type == EventType.mouseDown && Event.current.button == 1) { selectedSetIndex = l; GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Edit"), false, EditSet, manager.waveSequence[waveIndex].waveSet[l]); menu.AddSeparator(string.Empty); menu.AddItem(new GUIContent("Add"), false, AddSet, managerWaveSet); menu.AddItem(new GUIContent("Remove"), false, RemoveSet, managerWaveSet); menu.ShowAsContext(); } #endregion if (GUI.Button(new Rect(5, 0, 40, unit), "Edit", EditorStyles.miniButton)) { EnemyWaveSetEditor w = EditorWindow.GetWindow(typeof(EnemyWaveSetEditor), true) as EnemyWaveSetEditor; //w.minSize = new Vector2(300, 300); w.SetEditor(manager.waveSequence[waveIndex].waveSet[l]); } if (managerWaveSet.GetArrayElementAtIndex(l).FindPropertyRelative("name").stringValue == string.Empty) { managerWaveSet.GetArrayElementAtIndex(l).FindPropertyRelative("name").stringValue = "New Set"; } EditorGUI.LabelField(new Rect(50, 0, r.width * .4f + 10, unit), managerWaveSet.GetArrayElementAtIndex(l).FindPropertyRelative("name").stringValue, EditorStyles.miniBoldLabel); GUI.color = Color.red; if (GUI.Button(new Rect(r.width - 44, 0, 24, unit), EditorGUIUtility.FindTexture("d_Toolbar Minus"), EditorStyles.miniButton)) { managerWaveSet.DeleteArrayElementAtIndex(l); return; } GUI.color = Color.white; GUI.EndGroup(); } GUI.EndScrollView(); #endregion managerWaveSet.serializedObject.ApplyModifiedProperties(); } }
private void DrawWaveManager() { rolist.DoLayoutList(); rolist.drawHeaderCallback = (Rect r) => { EditorGUI.LabelField(r, "Wave Sequence Manager"); }; rolist.drawElementCallback = (Rect r, int i, bool a, bool f) => { r.y += 2f; var unit = EditorGUIUtility.singleLineHeight; var e = rolist.serializedProperty.GetArrayElementAtIndex(i); var managerName = e.FindPropertyRelative("name"); //var managerSpawnPointID = e.FindPropertyRelative("spawnPointID"); var managerWaveSet = e.FindPropertyRelative("waveSet"); //var waveSetCount = managerWaveSet.arraySize; bool error = false; if (!CheckSpawnPointArray(me.waveSequence[i].selectedSpawnPoints)) { #if (DEBUG) Debug.LogError("Error at index " + i); #endif error = true; //drawHandles = false; //me.waveSequence[i].selectedSpawnPoints = ReconstructSpawnPointArray(me.waveSequence[i].selectedSpawnPoints); } float margin = unit * .1f; //r.y += margin; GUI.BeginGroup(new Rect(r.x, r.y - 1, r.width, unit), EditorStyles.toolbar); #region DrawWaveSequence EditorGUI.LabelField(new Rect(3f, 0, 30, unit), "#" + i, EditorStyles.miniLabel); managerName.stringValue = EditorGUI.TextField(new Rect(3f + 30, 2f, r.width * .4f - 30, unit), managerName.stringValue, EditorStyles.toolbarTextField); //managerSpawnPointID.intValue = EditorGUI.Popup(new Rect(5f + r.width * .4f + unit, 0, r.width * .4f, unit), managerSpawnPointID.intValue, spawnerName, EditorStyles.toolbarPopup); if (error) { GUI.color = Color.red; } if (GUI.Button(new Rect(5f + r.width * .4f, 0, 80, unit), "Spwan Point", EditorStyles.toolbarDropDown)) { Vector2 gsp = GUIUtility.GUIToScreenPoint(new Vector2(r.x + 5f + (r.width * .4f) - unit, 0)); if (error) { me.waveSequence[i].selectedSpawnPoints = ReconstructSpawnPointArray(me.waveSequence[i].selectedSpawnPoints); } SpawnPointDropDownMenu w = CreateInstance <SpawnPointDropDownMenu>(); w.SetMenu(me.waveSequence[i], me.childSpawnPoints, me.waveSequence[i].selectedSpawnPoints); float height = 45; float width = r.width * .4f; if (me.childSpawnPoints.Length > 0) { height = (me.childSpawnPoints.Length * unit) * 1.25f; } if (me.childSpawnPoints.Length == 0) { width = r.width * .5f; height = 47; } w.ShowAsDropDown(new Rect(gsp.x, gsp.y, r.width * .4f, unit), new Vector2(width, height)); } if (error) { GUI.color = Color.white; GUI.DrawTexture(new Rect(7f + r.width * .4f, 1f, unit, unit), EditorGUIUtility.FindTexture("console.warnicon")); } #if UNITY_5_3 if (GUI.Button(new Rect(r.width - 26, 0, 26, unit), EditorGUIUtility.FindTexture("d_Toolbar Plus"), EditorStyles.toolbarButton)) { managerWaveSet.InsertArrayElementAtIndex(managerWaveSet.arraySize); //me.waveSequence[i].waveSet.Add(new EnemyWaveSet()); } #else if (GUI.Button(new Rect(5f + r.width * .4f + 100, 0, 90, unit), "Edit Wave Set", EditorStyles.toolbarDropDown)) { Vector2 gsp = GUIUtility.GUIToScreenPoint(new Vector2(r.x + 5f + (r.width * .4f) - unit, 0)); WaveSetEditor w = CreateInstance <WaveSetEditor>(); w.SetMenu(me, managerWaveSet, i); float height = 4 * (unit * 1.25f); //if (managerWaveSet.arraySize > 3) // height = (managerWaveSet.arraySize + 1) * (unit * 1.25f); //w.ShowUtility(); //w.minSize = new Vector2(r.width * .5f, height + 10); //w.position = new Rect(gsp.x, gsp.y+ height + 10, r.width * .5f, height + 10); w.ShowAsDropDown(new Rect(gsp.x, gsp.y, r.width * .5f, unit), new Vector2(r.width * .5f, height + 10)); } #endif #endregion GUI.EndGroup(); r.y += unit + (margin * 2); #region DrawEachWaveSet #if UNITY_5_3 for (int l = 0; l < managerWaveSet.arraySize; l++) { float y = r.y + (l * (unit * 1.25f)); GUI.BeginGroup(new Rect(r.x, y, r.width, unit)); GUI.color = Color.red; //GUIStyle remove = new GUIStyle(EditorStyles.miniButtonLeft); //remove.normal.textColor = Color.white; if (new Rect(0, 0, r.width, unit).Contains(Event.current.mousePosition) && Event.current.type == EventType.mouseDown && Event.current.button == 1) { selectedSetIndex = l; GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Edit"), false, EditSet, me.waveSequence[i].waveSet[l]); menu.AddSeparator(string.Empty); menu.AddItem(new GUIContent("Add"), false, AddSet, managerWaveSet); menu.AddItem(new GUIContent("Remove"), false, RemoveSet, managerWaveSet); menu.ShowAsContext(); } if (GUI.Button(new Rect(r.width - 24, 0, 24, unit), EditorGUIUtility.FindTexture("d_Toolbar Minus"), EditorStyles.miniButton)) { managerWaveSet.DeleteArrayElementAtIndex(l); return; } GUI.color = Color.white; if (GUI.Button(new Rect(0, 0, 40, unit), "Edit", EditorStyles.miniButton)) { EnemyWaveSetEditor w = EditorWindow.GetWindow(typeof(EnemyWaveSetEditor), true) as EnemyWaveSetEditor; //w.minSize = new Vector2(300, 300); w.SetEditor(me.waveSequence[i].waveSet[l]); } EditorGUI.LabelField(new Rect(45, 0, r.width * .4f, unit), managerWaveSet.GetArrayElementAtIndex(l).FindPropertyRelative("name").stringValue, EditorStyles.miniLabel); //GUI.Box(new Rect(r.width * .5f + 35f, 0, 30, unit), Resources.Load("Dice") as Texture, EditorStyles.miniButtonLeft); //GUI.Box(new Rect(r.width * .5f + 65f, 0, r.width - (r.width * .5f) - 70, unit), GUIContent.none, EditorStyles.miniButtonRight); //EditorGUI.IntSlider(new Rect(r.width * .4f + 65, 0, r.width - (r.width * .4f) - 65, unit), managerWaveSet.GetArrayElementAtIndex(l).FindPropertyRelative("chance"), 0, 100, GUIContent.none); GUI.EndGroup(); } #endif #endregion }; #if UNITY_5_3 rolist.elementHeightCallback = (int i) => { Repaint(); float height; var c = rolist.serializedProperty.GetArrayElementAtIndex(i).FindPropertyRelative("waveSet").arraySize; height = (c + 1) * (EditorGUIUtility.singleLineHeight * 1.25f); return(height); }; rolist.drawElementBackgroundCallback = (Rect r, int i, bool a, bool f) => { var c = rolist.serializedProperty.GetArrayElementAtIndex(i).FindPropertyRelative("waveSet").arraySize; //r.height = (c + 1) * (EditorGUIUtility.singleLineHeight * 1.25f); r.x += 1f; r.width -= 3f; for (int l = 0; l <= c; l++) { if (a) { if (l % 2 == 0) { EditorGUI.DrawRect(new Rect(r.x, r.y + (l * (EditorGUIUtility.singleLineHeight * 1.25f)), r.width, EditorGUIUtility.singleLineHeight * 1.25f), new Color(0.23f, 0.56f, 0.5f, 1f)); } else { EditorGUI.DrawRect(new Rect(r.x, r.y + (l * (EditorGUIUtility.singleLineHeight * 1.25f)), r.width, EditorGUIUtility.singleLineHeight * 1.25f), new Color(0.23f, 0.56f, 0.5f, .8f)); } } } //if (a) // EditorGUI.DrawRect(r, new Color(0.23f, 0.56f, 0.5f, 1f)); }; #endif rolist.onSelectCallback = (ReorderableList l) => { onSelectedIndex = l.index; if (!CheckSpawnPointArray(me.waveSequence[onSelectedIndex].selectedSpawnPoints)) { drawHandles = false; } else { drawHandles = true; } }; rolist.onAddDropdownCallback = (Rect r, ReorderableList l) => { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Create New"), false, CreateWaveSequence, null); if (l.index >= 0) { menu.AddSeparator(string.Empty); menu.AddItem(new GUIContent("Duplicate"), false, DuplicateWaveSequence, l.index); } menu.ShowAsContext(); }; }