예제 #1
0
 public void SetBlockSet(BlockSet blockSet)
 {
     this.blockSet = blockSet;
     index         = Mathf.Clamp(index, 0, blockSet.GetBlockCount() + blockSet.GetItemCount());
     if (index < blockSet.GetBlockCount())
     {
         BuildBlock(blockSet.GetBlock(index));
     }
     if (index > blockSet.GetBlockCount())
     {
         BuildItem(blockSet.GetItem(index - blockSet.GetBlockCount()));
     }
 }
예제 #2
0
    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));
        }
    }
예제 #3
0
 private static Block DrawInventory(BlockSet blockSet, ref Vector2 scrollPosition, Block selected)
 {
     scrollPosition = GUILayout.BeginScrollView(scrollPosition);
     for (int i = 0, y = 0; i < blockSet.GetBlockCount(); y++)
     {
         GUILayout.BeginHorizontal();
         for (int x = 0; x < 8; x++, i++)
         {
             Block block = blockSet.GetBlock(i);
             if (DrawBlock(block, block == selected && selected != null))
             {
                 selected = block;
             }
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndScrollView();
     return(selected);
 }
예제 #4
0
    private static Entity DrawInventory(BlockSet blockSet, ref Vector2 scrollPosition, Entity selected)
    {
        scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        int y = 0;

        for (int i = 0; i < blockSet.GetBlockCount(); y++)
        {
            GUILayout.BeginHorizontal();
            for (int x = 0; x < 8; x++, i++)
            {
                Block block = blockSet.GetBlock(i);
                if (DrawBlock(block, block == BlockUnderSelection && BlockUnderSelection != null))
                {
                    selected = block;
                    IsBlockUnderSelection = true;
                }
            }
            GUILayout.EndHorizontal();
        }
        for (int i = 0; i < blockSet.GetItemCount(); y++)
        {
            GUILayout.BeginHorizontal();
            for (int x = 0; x < 8; x++, i++)
            {
                Item item = blockSet.GetItem(i);
                if (DrawBlock(item, item == ItemUnderSelection && ItemUnderSelection != null))
                {
                    selected             = item;
                    IsItemUnderSelection = true;
                }
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndScrollView();
        return(selected);
    }
예제 #5
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        Mode oldMode = mode;

        mode = (Mode)EditorGUIUtils.Toolbar(mode);
        EditorGUILayout.Separator();
        if (mode != oldMode)
        {
            EditorGUIUtility.keyboardControl = 0;
        }

        if (mode == Mode.AtlasSet)
        {
            DrawAtlasesList(blockSet);
            if (blockSet.GetAtlas(selectedAtlas) != null)
            {
                DrawAtlasEditor(blockSet.GetAtlas(selectedAtlas));
            }
        }
        if (mode == Mode.BlockSet)
        {
            DrawBlockSet(blockSet);
            EditorGUILayout.Separator();

            if (selectedBlock < blockSet.GetBlockCount() && blockSet.GetBlock(selectedBlock) != null)
            {
                BlockEditor.DrawBlockEditor(blockSet.GetBlock(selectedBlock), blockSet);
            }
            if (selectedBlock >= blockSet.GetBlockCount() && blockSet.GetItem(selectedBlock - blockSet.GetBlockCount()) != null)
            {
                BlockEditor.DrawItemEditor(blockSet.GetItem(selectedBlock - blockSet.GetBlockCount()), blockSet);
            }
        }
        if (mode == Mode.XML)
        {
            if (oldMode != mode)
            {
                xml = blockSet.GetData();
            }

            xmlScrollPosition = GUILayout.BeginScrollView(xmlScrollPosition);
            GUIStyle style = new GUIStyle(GUI.skin.box);
            style.alignment = TextAnchor.UpperLeft;
            xml             = EditorGUILayout.TextArea(xml, GUILayout.ExpandWidth(true));
            blockSet.SetData(xml);
            GUILayout.EndScrollView();

            if (GUILayout.Button("Import"))
            {
                BlockSetImport.Import(blockSet, blockSet.GetData());
                GUI.changed = true;
            }
        }

        if (GUI.changed)
        {
            string data = BlockSetExport.Export(blockSet);
            blockSet.SetData(data);
            EditorUtility.SetDirty(blockSet);
        }
    }
예제 #6
0
    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();
    }
예제 #7
0
 public void SetBlockSet(BlockSet blockSet)
 {
     this.blockSet = blockSet;
     index         = Mathf.Clamp(index, 0, blockSet.GetBlockCount());
     BuildBlock(blockSet.GetBlock(index));
 }