static MaterialEditor() { var type = typeof(IMaterialDescriptor); var types = Reflection.GetAssignableFromTypes(type); m_propertySelectors = new Dictionary <string, IMaterialDescriptor>(); foreach (Type t in types) { IMaterialDescriptor selector = (IMaterialDescriptor)Activator.CreateInstance(t); if (selector == null) { Debug.LogWarningFormat("Unable to instantiate selector of type " + t.FullName); continue; } if (selector.ShaderName == null) { Debug.LogWarningFormat("ComponentType is null. Selector ShaderName is null {0}", t.FullName); continue; } if (m_propertySelectors.ContainsKey(selector.ShaderName)) { Debug.LogWarningFormat("Duplicate component selector for {0} found. Type name {1}. Using {2} instead", selector.ShaderName, selector.GetType().FullName, m_propertySelectors[selector.ShaderName].GetType().FullName); } else { m_propertySelectors.Add(selector.ShaderName, selector); } } }
static MaterialEditor() { var type = typeof(IMaterialDescriptor); var types = Reflection.GetAssignableFromTypes(type); MaterialDescriptors = new Dictionary <string, IMaterialDescriptor>(); foreach (Type t in types) { IMaterialDescriptor descriptor = (IMaterialDescriptor)Activator.CreateInstance(t); if (descriptor == null) { Debug.LogWarningFormat("Unable to instantiate descriptor of type " + t.FullName); continue; } if (descriptor.ShaderName == null) { Debug.LogWarningFormat("ComponentType is null. ShaderName is null {0}", t.FullName); continue; } if (MaterialDescriptors.ContainsKey(descriptor.ShaderName)) { IMaterialDescriptor alreadyAddedMaterialDescriptor = MaterialDescriptors[descriptor.ShaderName]; if (IsBulitIn(alreadyAddedMaterialDescriptor.GetType())) { //Overwrite built-in material descriptor MaterialDescriptors[descriptor.ShaderName] = descriptor; } else if (!IsBulitIn(descriptor.GetType())) { Debug.LogWarningFormat("Duplicate component descriptor for {0} found. Type name {1}. Using {2} instead", descriptor.ShaderName, descriptor.GetType().FullName, MaterialDescriptors[descriptor.ShaderName].GetType().FullName); } } else { MaterialDescriptors.Add(descriptor.ShaderName, descriptor); } } }
/// <summary> /// Push a material for processing. /// </summary> /// <param name="materialDescriptor">The material descriptor.</param> /// <param name="materialName">Friendly name of the material.</param> /// <returns><c>true</c> if the material is valid and can be visited, <c>false</c> otherwise.</returns> /// <exception cref="System.ArgumentNullException">materialDescriptor</exception> public bool PushMaterial(IMaterialDescriptor materialDescriptor, string materialName) { if (materialDescriptor == null) { throw new ArgumentNullException(nameof(materialDescriptor)); } bool hasErrors = false; foreach (var previousMaterial in materialStack) { if (ReferenceEquals(previousMaterial, materialDescriptor) || previousMaterial.MaterialId == materialDescriptor.MaterialId) { Log.Error("The material [{0}] cannot be used recursively.", materialName); hasErrors = true; } } if (!hasErrors) { materialStack.Push(materialDescriptor); } return(!hasErrors); }
public void PushMaterialDescriptor(IMaterialDescriptor descriptor) { materialDescriptorStack.Push(descriptor); }