public static int SelectionGrid(BlockSet blockSet, int index, params GUILayoutOption[] options) { Container <Vector2> scroll = EditorGUIUtils.GetStateObject <Container <Vector2> >(blockSet.GetHashCode()); scroll.value = GUILayout.BeginScrollView(scroll, options); index = SelectionGrid(blockSet.GetBlocks(), blockSet.GetItems(), index); GUILayout.EndScrollView(); return(index); }
void OnGUI() { Rect rect = new Rect(Screen.width - 180, 0, 180, Screen.height); int oldIndex = index; index = DrawList(rect, index, blockSet.GetBlocks(), blockSet.GetItems(), ref scrollPosition); if (oldIndex != index && index < blockSet.GetBlockCount()) { BuildBlock(blockSet.GetBlock(index)); } else if (oldIndex != index && index > blockSet.GetBlockCount()) { BuildItem(blockSet.GetItem(index)); } }
public static void Import(BlockSet blockSet, string xml) { if (xml != null && xml.Length > 0) { XmlDocument document = new XmlDocument(); document.LoadXml(xml); ReadBlockSet(blockSet, document); } foreach (Block block in blockSet.GetBlocks()) { block.Init(blockSet); } foreach (Item item in blockSet.GetItems()) { item.Init(blockSet); } }
private static void WriteBlockSet(BlockSet blockSet, XmlDocument document) { XmlNode blockSetNode = document.CreateElement("BlockSet"); document.AppendChild(blockSetNode); XmlNode atlasListNode = WriteAtlasList(blockSet.GetAtlases(), document); blockSetNode.AppendChild(atlasListNode); XmlNode blockListNode = WriteBlockList(blockSet.GetBlocks(), document); blockSetNode.AppendChild(blockListNode); XmlNode itemListNode = WriteItemList(blockSet.GetItems(), document); blockSetNode.AppendChild(itemListNode); }
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(); }