/// <summary> /// Applies this texture set to the input root transform, using the specified inclusions/exclusions from config. /// Does not update any recoloring data. Must also call 'applyRecoloring' in order to update recoloring properties. /// </summary> /// <param name="root"></param> /// <param name="userColors"></param> public void enable(Transform root, bool isIcon = false) { bool updateMode = string.Equals(mode, "update", StringComparison.CurrentCultureIgnoreCase); Transform[] trs = TextureSet.findApplicableTransforms(root, meshNames, excludedMeshes); int len = trs.Length; Renderer render; Log.debug("enabling TSMD.." + root + " updateMode: " + updateMode); if (updateMode) { Material material; for (int i = 0; i < len; i++) { render = trs[i].GetComponent <Renderer>(); if (render != null) { material = render.material; apply(material, isIcon); render.material = material; } } } else//create mode - creates new materials for renders to use, applying only those properties specified in the texture set, with optional inheritance of properties from the old material { Material newMaterial = createMaterial();//create a new material for this TSMD Material origMaterial = null; for (int i = 0; i < len; i++) { render = trs[i].GetComponent <Renderer>(); if (render != null) { //only inherit properties a single time, from the first render/transform/material found if (origMaterial == null) { origMaterial = render.sharedMaterial; if (origMaterial != null) { //if there was no shared material, this will be null; //TODO -- use std material ref if no shared mat exists? newMaterial.name = origMaterial.name; inheritProperties(newMaterial, origMaterial); } } render.sharedMaterial = newMaterial; Log.replacement("Updated material properties on transform: " + trs[i].name + "\n" + Debug.getMaterialPropertiesDebug(newMaterial)); } } } }
/// <summary> /// Applies this texture set to the input root transform, using the specified inclusions/exclusions from config. /// Does not update any recoloring data. Must also call 'applyRecoloring' in order to update recoloring properties. /// </summary> /// <param name="root"></param> /// <param name="userColors"></param> public void enable(Transform root) { bool updateMode = string.Equals(mode, "update", StringComparison.CurrentCultureIgnoreCase); Transform[] trs = TextureSet.findApplicableTransforms(root, meshNames, excludedMeshes); int len = trs.Length; Renderer render; if (updateMode) { Material material; for (int i = 0; i < len; i++) { render = trs[i].GetComponent <Renderer>(); if (render != null) { material = render.material; apply(material); render.material = material; } } } else//create mode - creates new materials for renders to use, applying only those properties specified in the texture set, with optional inheritance of properties from the old material { Material newMaterial = createMaterial();//create a new material for this TSMD Material origMaterial = null; for (int i = 0; i < len; i++) { render = trs[i].GetComponent <Renderer>(); if (render != null) { //only inherit properties a single time, from the first render/transform/material found if (origMaterial == null) { origMaterial = render.sharedMaterial; inheritProperties(newMaterial, origMaterial); } render.sharedMaterial = newMaterial; } } } }