using System.Collections.Generic; namespace eDriven.TextureUtilities { /// /// The class that sets textures on materials of the renderer /// /// Coded by Danko Kozar public class TextureArranger { #region Members private readonly Dictionary _textureDescriptors = new Dictionary(); /// /// Texture descriptors /// public Dictionary TextureDescriptors { get { return _textureDescriptors; } } private readonly UnityEngine.Renderer _renderer; public UnityEngine.Renderer Renderer { get { return _renderer; } } #endregion /// /// Constructor /// /// A renderer to arrange textures to public TextureArranger(UnityEngine.Renderer renderer) { _renderer = renderer; } /// /// Is this position occupied? /// /// /// public bool HasTexture(int index) { return _textureDescriptors.ContainsKey(index); } /// /// Adds a texture to the material specified by index /// /// /// public void AddTexture(int index, TextureDescriptor descriptor) { _textureDescriptors.Add(index, descriptor); // add descriptor _renderer.materials[index].mainTexture = descriptor.Texture; // set texture _renderer.materials[index].mainTexture.name = descriptor.Path; // name the texture } } }