Exemple #1
0
    /**
     * DrawBlockList draws the current BlockSet
     */
    private static int DrawBlockList(BlockSet blocks, int selected, ref Vector2 scrollPosition)
    {
        scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(200));

        GUIStyle normal = GUI.skin.button;
        GUIStyle active = new GUIStyle(normal);

        active.normal = active.active;

        for (int i = 0; i < blocks.GetCount(); i++)
        {
            Block block = blocks.GetBlock(i);
            if (i == selected)
            {
                GUI.skin.button = active;
            }
            if (GUILayout.Button(block.GetName()))
            {
                if (selected != i)
                {
                    GUIUtility.keyboardControl = 0;
                }
                selected = i;
            }
            GUI.skin.button = normal;
        }

        GUILayout.EndScrollView();
        return(selected);
    }
Exemple #2
0
 /**
  * DrawInventory draws the current Inventory and handles choosing the new selected block
  */
 private static Block DrawInventory(BlockSet blockSet, ref Vector2 scrollPosition, Block selected)
 {
     scrollPosition = GUILayout.BeginScrollView(scrollPosition);
     for (int index = 0, y = 0; index < blockSet.GetCount(); y++)
     {
         GUILayout.BeginHorizontal();
         for (int x = 0; x < 8; x++, index++)
         {
             Block block = blockSet.GetBlock(index);
             if (DrawBlock(block, block == selected && selected != null))
             {
                 selected = block;
             }
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndScrollView();
     return(selected);
 }
Exemple #3
0
    /**
     * DrawBlockSetEditor draws and handles the editing of the BlockSet
     */
    private static void DrawBlockSetEditor(BlockSet blockSet)
    {
        GUILayout.BeginVertical("box");
        selectedBlock = DrawBlockList(blockSet, selectedBlock, ref blockSetScrollPosition);
        EditorGUILayout.Separator();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Add Cube"))
        {
            selectedBlock = blockSet.Add(new Cube("new Cube"));
        }
        if (GUILayout.Button("Add Cross"))
        {
            selectedBlock = blockSet.Add(new Cross("new Cross"));
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("Remove") && blockSet.GetBlock(selectedBlock) != null)
        {
            Undo.RecordObject(blockSet, "Remove block");
            blockSet.Remove(selectedBlock);
            selectedBlock = Mathf.Clamp(selectedBlock, 0, blockSet.GetCount() - 1);
        }
        GUILayout.EndVertical();
    }