private static void DrawAtlasesList(BlockSet blockSet)
    {
        Atlas[] list = blockSet.GetAtlases();
        GUILayout.BeginVertical(GUI.skin.box, GUILayout.ExpandWidth(true));
        {
            selectedAtlas = EditorGUIUtils.DrawList(selectedAtlas, list);
            EditorGUILayout.Separator();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Add"))
            {
                ArrayUtility.Add <Atlas>(ref list, new Atlas());
                selectedAtlas = list.Length - 1;
                GUI.changed   = true;
            }
            if (GUILayout.Button("Remove") && selectedAtlas != -1)
            {
                Undo.RegisterUndo(blockSet, "Remove atlas");
                ArrayUtility.RemoveAt <Atlas>(ref list, selectedAtlas);
                selectedAtlas = Mathf.Clamp(selectedAtlas, 0, list.Length - 1);
                GUI.changed   = true;
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();
        blockSet.SetAtlases(list);
    }
Exemple #2
0
    public static void DrawBlockEditor(Block block, BlockSet blockSet)
    {
        GUILayout.BeginVertical(GUI.skin.box);
        {
            string name = EditorGUILayout.TextField("Name", block.GetName());
            block.SetName(FixNameString(name));

            int atlas = EditorGUIUtils.Popup("Atlas", block.GetAtlasID(), blockSet.GetAtlases());
            block.SetAtlasID(atlas);

            int light = EditorGUILayout.IntField("Light", block.GetLight());
            block.SetLight(light);
        }
        GUILayout.EndVertical();

        Texture texture = block.GetTexture();

        if (texture != null)
        {
            FieldInfo field = DrawFacesList(block, texture);
            int       face  = (int)field.GetValue(block);
            DrawFaceEditor(ref face, block.GetAtlas(), ref atlasMatrix);
            field.SetValue(block, face);
        }
    }
Exemple #3
0
    }                                                  //Public accessible means of getting blockId

    /**
     * This method initializes a Block from an initial blockSet and the Block's index in that blockSet
     */
    public void Init(BlockSet blockSet, int blockId)
    {
        if (atlas != null)
        {
            alpha = atlas.IsAlpha();
        }
        atlasId      = Array.IndexOf(blockSet.GetAtlases(), atlas);
        this.blockId = blockId;
    }
Exemple #4
0
    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);
    }
Exemple #5
0
    /**
     * DrawBlockEditor draws and handles editing a single block
     */
    private static void DrawBlockEditor(Block block, BlockSet blockSet)
    {
        string name = EditorGUILayout.TextField("Name", block.GetName());

        block.SetName(name);

        Atlas[]  atlases    = blockSet.GetAtlases();
        string[] atlasNames = new string[atlases.Length];
        for (int i = 0; i < atlasNames.Length; i++)
        {
            Atlas tAtlas = atlases[i];
            atlasNames[i] = tAtlas != null ? tAtlas.name : "null";
        }
        int index = ArrayUtility.IndexOf(atlases, block.GetAtlas());

        index = EditorGUILayout.Popup("Atlas", index, atlasNames);
        block.SetAtlas(SafeGet(atlases, index));

        /**
         * For now all blocks have the same light values as a default
         * int light = EditorGUILayout.IntField("Light", block.GetLight());
         * light = Mathf.Clamp(light, 0, 15);
         * block.SetLight((byte)light);
         */

        bool breakable = EditorGUILayout.Toggle("Breakable", block.IsBreakable());

        block.SetBreakable(breakable);

        Atlas atlas = block.GetAtlas();

        if (atlas == null || atlas.GetMaterial() == null || atlas.GetMaterial().mainTexture == null)
        {
            return;
        }
        if (block is Cube)
        {
            DrawCubeBlockEditor((Cube)block, atlas);
        }
        if (block is Cross)
        {
            DrawCrossBlockEditor((Cross)block, atlas);
        }
    }
Exemple #6
0
    /**
     * OnInspectorGUI defines what the BlockSet looks like in the unity editor
     */
    public override void OnInspectorGUI()
    {
        Atlas[] list = DrawAtlasesEditor(blockSet.GetAtlases());
        blockSet.SetAtlases(list);
        EditorGUILayout.Separator();

        DrawBlockSetEditor(blockSet);
        EditorGUILayout.Separator();

        if (blockSet.GetBlock(selectedBlock) != null)
        {
            DrawBlockEditor(blockSet.GetBlock(selectedBlock), blockSet);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(blockSet);
            Repaint();
        }
    }