示例#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 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);
    }
示例#4
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);
        }
    }