예제 #1
0
    public static void LoadResources()
    {
        ChunkObject    = Resources.Load <GameObject>("Chunk");
        PackedMaterial = Resources.Load <Material>("SolidMaterial");
        var         n        = Resources.Load <TextAsset>("Blocks/Materials");
        XmlDocument document = new XmlDocument();

        document.LoadXml(n.text);

        List <Texture2D> textures = new List <Texture2D>();

        foreach (XmlElement i in document.DocumentElement.ChildNodes)
        {
            textures.Add(Resources.Load <Texture2D>("Textures/" + i.GetAttribute("texture")));
        }
        Texture2D packedTexture = new Texture2D(8192, 8192);
        var       rects         = packedTexture.PackTextures(textures.ToArray(), 4);

        packedTexture = packedTexture.ChangeFormat(TextureFormat.RGBA32);
        uPaddingBleed.BleedEdges(packedTexture, 4, rects, false);
        packedTexture.filterMode = FilterMode.Point;
        int index = 0;

        foreach (var rect in rects)
        {
            Textures.Add((document.DocumentElement.ChildNodes[index] as XmlElement).GetAttribute("name"), rect);
            index++;
        }

        PackedMaterial.SetTexture("_MainTex", packedTexture);

        foreach (var i in BlockTypes)
        {
            if (i.DefaultBlockState is BasicBlockState state)
            {
                state.SetBlockType(i);
            }
        }
    }