예제 #1
0
    public virtual void LoadTextures(Voxelmetric vm)
    {
        var resourceTextures = Resources.LoadAll <Texture2D>(pathToTextureResources);
        var atlas            = new ImmutableTextureAtlas(resourceTextures, 8192);

        for (int i = 0; i < resourceTextures.Length; i++)
        {
            var textureName = resourceTextures[i].name;
            var nameLength  = textureName.Length;
            if (!string.IsNullOrEmpty(textureName))
            {
                var rootTextureName = textureName;
                var openIndex       = textureName.IndexOf('[');
                if (openIndex > 0 && openIndex < textureName.Length - 2 && textureName.IndexOf(']') == textureName.Length - 1)
                {
                    // TODO: Direction-based texture naming, like this:
                    // var dir = textureName.Substring(openIndex + 1, textureName.Length - (openIndex + 2));
                    rootTextureName = textureName.Substring(0, openIndex);
                }
                TextureSet tex;
                if (textureSets.ContainsKey(rootTextureName))
                {
                    tex = textureSets[rootTextureName];
                    tex.AddTexture(atlas.GetTextureRect(rootTextureName));;
                }
                else
                {
                    tex = new TextureSet(rootTextureName);
                    tex.AddTexture(atlas.GetTextureRect(rootTextureName));
                    AddTexture(tex);
                }
            }
        }


        mainAtlas            = atlas;
        material.mainTexture = (Texture2D)atlas;
        #if UNITY_EDITOR
        Debug.Log(string.Format("Voxelmetric Texture Set Loader loaded {0} textures into {1} texture sets.", resourceTextures.Length, textureSets.Keys.Count));
        #endif
    }
예제 #2
0
    public virtual void LoadTextures(Voxelmetric vm)
    {
        var       resourceTextures = Resources.LoadAll <Texture2D>(pathToTextureResources);
        Texture2D packedTextures   = new Texture2D(64, 64)
        {
            filterMode = FilterMode.Point
        };

        Rect[] rects = packedTextures.PackTextures(resourceTextures, 0, 8192, false);

        for (int i = 0; i < resourceTextures.Length; i++)
        {
            TextureSet tex = new TextureSet(resourceTextures[i].name);
            tex.AddTexture(rects[i]);
            AddTexture(tex);
        }

        tilesheet            = packedTextures;
        material.mainTexture = packedTextures;

        Debug.Log(string.Format("Voxelmetric Texture Set Loader loaded {0} textures into {1} texture sets.", rects.Length, textureSets.Keys.Count));
    }