Exemple #1
0
 public void ApplyMaterial(Mesh mesh, MeshRenderer meshRenderer, MaterialSlotType materialSlotType, Material newMaterial)
 {
     if (TryGetMapping(mesh, out var mapping))
     {
         var materialArray = meshRenderer.sharedMaterials;
         meshRenderer.sharedMaterials = ApplyMaterialToArray(materialArray, materialSlotType, newMaterial, mapping);
     }
 }
Exemple #2
0
        public Material[] ApplyMaterialToArray(Mesh mesh, Material[] materialArray, MaterialSlotType materialSlotType, Material newMaterial)
        {
            if (TryGetMapping(mesh, out var mapping))
            {
                return(ApplyMaterialToArray(materialArray, materialSlotType, newMaterial, mapping));
            }

            return(materialArray);
        }
Exemple #3
0
        private Material[] ApplyMaterialToArray(Material[] materialArray, MaterialSlotType slotType, Material newMaterial, MaterialSlotsDictionary mapping)
        {
            if (!mapping.TryGetValue(slotType, out var materialIndex))
            {
                Debug.LogWarning($"Material cannot be applied. Slot type '{slotType}' is not defined in mapping of given mesh.");
                return(materialArray);
            }

            if (materialIndex >= materialArray.Length)
            {
                Array.Resize(ref materialArray, materialIndex + 1);
            }

            materialArray[materialIndex] = newMaterial;

            return(materialArray);
        }