private static GetShaderPropertyDrawer ( string attrib, bool &isDecorator ) : |
||
attrib | string | |
isDecorator | bool | |
return |
private static MaterialPropertyDrawer GetShaderPropertyDrawer(string attrib, out bool isDecorator)
{
isDecorator = false;
string str = attrib;
string argsText = string.Empty;
Match match = Regex.Match(attrib, @"(\w+)\s*\((.*)\)");
if (match.Success)
{
str = match.Groups[1].Value;
argsText = match.Groups[2].Value.Trim();
}
foreach (Type type in EditorAssemblies.SubclassesOf(typeof(MaterialPropertyDrawer)))
{
if (((type.Name == str) || (type.Name == (str + "Drawer"))) || (((type.Name == ("Material" + str + "Drawer")) || (type.Name == (str + "Decorator"))) || (type.Name == ("Material" + str + "Decorator"))))
{
try
{
isDecorator = type.Name.EndsWith("Decorator");
return CreatePropertyDrawer(type, argsText);
}
catch (Exception)
{
object[] args = new object[] { str, argsText };
Debug.LogWarningFormat("Failed to create material drawer {0} with arguments '{1}'", args);
return null;
}
}
}
return null;
}
private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name) { string[] propertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name); if (propertyAttributes == null || propertyAttributes.Length == 0) { return((MaterialPropertyHandler)null); } MaterialPropertyHandler materialPropertyHandler = new MaterialPropertyHandler(); foreach (string attrib in propertyAttributes) { bool isDecorator; MaterialPropertyDrawer shaderPropertyDrawer = MaterialPropertyHandler.GetShaderPropertyDrawer(attrib, out isDecorator); if (shaderPropertyDrawer != null) { if (isDecorator) { if (materialPropertyHandler.m_DecoratorDrawers == null) { materialPropertyHandler.m_DecoratorDrawers = new List <MaterialPropertyDrawer>(); } materialPropertyHandler.m_DecoratorDrawers.Add(shaderPropertyDrawer); } else { if (materialPropertyHandler.m_PropertyDrawer != null) { Debug.LogWarning((object)string.Format("Shader property {0} already has a property drawer", (object)name), (UnityEngine.Object)shader); } materialPropertyHandler.m_PropertyDrawer = shaderPropertyDrawer; } } } return(materialPropertyHandler); }