private void DrawBlockSet(BlockSet blockSet) { GUILayout.BeginVertical(GUI.skin.box); int oldSelectedBlock = selectedBlock; selectedBlock = BlockSetViewer.SelectionGrid(blockSet, selectedBlock, GUILayout.MinHeight(200), GUILayout.MaxHeight(300)); if (selectedBlock != oldSelectedBlock) { GUIUtility.keyboardControl = 0; } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); foreach (Type type in blockTypes) { string name = type.ToString(); if (name.EndsWith("Block")) { name = name.Substring(0, name.Length - 5); } if (GUILayout.Button(name)) { Block newBlock = (Block)System.Activator.CreateInstance(type); newBlock.SetName("New " + type.ToString()); newBlock.Init(blockSet); Block[] blocks = blockSet.GetBlocks(); ArrayUtility.Add <Block>(ref blocks, newBlock); blockSet.SetBlocks(blocks); selectedBlock = blocks.Length - 1; EditorGUIUtility.keyboardControl = 0; GUI.changed = true; } } GUILayout.EndHorizontal(); if (GUILayout.Button("Remove")) { Block[] blocks = blockSet.GetBlocks(); ArrayUtility.RemoveAt <Block>(ref blocks, selectedBlock); blockSet.SetBlocks(blocks); selectedBlock = Mathf.Clamp(selectedBlock, 0, blocks.Length - 1); GUI.changed = true; } GUILayout.EndVertical(); }
private void DrawBlockSet(BlockSet blockSet) { GUILayout.BeginVertical(GUI.skin.box); Block oldSelectedBlock = selectedBlock; selectedBlock = BlockSetViewer.SelectionGrid(blockSet, selectedBlock, GUILayout.MinHeight(200), GUILayout.MaxHeight(300)); if (selectedBlock != oldSelectedBlock) { GUIUtility.keyboardControl = 0; } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); if (GUILayout.Button("New Block")) { Block newBlock = (Block)Activator.CreateInstance(typeof(Block)); newBlock.Name = "NewBlock"; blockSet.Blocks.Add(newBlock); EditorGUIUtility.keyboardControl = 0; GUI.changed = true; } GUILayout.EndHorizontal(); if (GUILayout.Button("Remove")) { blockSet.Blocks.Remove(selectedBlock); GUI.changed = true; } if (GUILayout.Button("Force Save")) { EditorUtility.SetDirty(blockSet); } GUILayout.EndVertical(); }
private void DrawBlockSet(BlockSet blockSet) { if (GUILayout.Button("Refresh Indexes")) { Block[] blocks = blockSet.GetBlocks(); for (int i = 0; i < blocks.Length; ++i) { blocks[i].Index = i; } blockSet.SetBlocks(blocks); } GUILayout.BeginVertical(GUI.skin.box); int oldSelectedBlock = selectedBlock; selectedBlock = BlockSetViewer.SelectionGrid(blockSet, selectedBlock, GUILayout.MinHeight(200), GUILayout.MaxHeight(300)); if (selectedBlock != oldSelectedBlock) { GUIUtility.keyboardControl = 0; } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); foreach (Type type in blockTypes) { string name = type.ToString(); if (name.EndsWith("Block")) { name = name.Substring(0, name.Length - 5); if (GUILayout.Button(name)) { Block newBlock = (Block)System.Activator.CreateInstance(type); newBlock.SetName("New " + type.ToString()); newBlock.Init(blockSet); Block[] blocks = blockSet.GetBlocks(); newBlock.Index = blocks.Length; ArrayUtility.Add <Block>(ref blocks, newBlock); blockSet.SetBlocks(blocks); selectedBlock = blocks.Length - 1; EditorGUIUtility.keyboardControl = 0; GUI.changed = true; } } else if (name.EndsWith("Item")) { name = name.Substring(0, name.Length - 5); if (GUILayout.Button(name)) { Item newItem = (Item)System.Activator.CreateInstance(type); newItem.SetName("New " + type.ToString()); newItem.Init(blockSet); Item[] items = blockSet.GetItems(); newItem.Index = blockSet.GetBlockCount() + items.Length; ArrayUtility.Add <Item>(ref items, newItem); blockSet.SetItems(items); selectedBlock = items.Length - 1 + blockSet.GetBlockCount(); EditorGUIUtility.keyboardControl = 0; GUI.changed = true; } } } GUILayout.EndHorizontal(); if (GUILayout.Button("Remove")) { if (selectedBlock < blockSet.GetBlockCount()) { Block[] blocks = blockSet.GetBlocks(); ArrayUtility.RemoveAt <Block>(ref blocks, selectedBlock); blockSet.SetBlocks(blocks); selectedBlock = Mathf.Clamp(selectedBlock, 0, blocks.Length - 1); GUI.changed = true; } else if (selectedBlock >= blockSet.GetBlockCount()) { Item[] items = blockSet.GetItems(); ArrayUtility.RemoveAt <Item>(ref items, selectedBlock - blockSet.GetBlockCount()); blockSet.SetItems(items); selectedBlock = Mathf.Clamp(selectedBlock, 0, items.Length - 1 + blockSet.GetBlockCount()); GUI.changed = true; } } GUILayout.EndVertical(); }