Base class to derive custom material property drawers from.
public void OnGUI(ref Rect position, MaterialProperty prop, string label, MaterialEditor editor) { float height = position.height; position.height = 0.0f; if (this.m_DecoratorDrawers != null) { using (List <MaterialPropertyDrawer> .Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator()) { while (enumerator.MoveNext()) { MaterialPropertyDrawer current = enumerator.Current; position.height = current.GetPropertyHeight(prop, label, editor); float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; current.OnGUI(position, prop, label, editor); EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; position.y += position.height; height -= position.height; } } } position.height = height; if (this.m_PropertyDrawer == null) { return; } float labelWidth1 = EditorGUIUtility.labelWidth; float fieldWidth1 = EditorGUIUtility.fieldWidth; this.m_PropertyDrawer.OnGUI(position, prop, label, editor); EditorGUIUtility.labelWidth = labelWidth1; EditorGUIUtility.fieldWidth = fieldWidth1; }
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); }
private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name) { string[] shaderPropertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name); if ((shaderPropertyAttributes == null) || (shaderPropertyAttributes.Length == 0)) { return(null); } MaterialPropertyHandler handler = new MaterialPropertyHandler(); foreach (string str in shaderPropertyAttributes) { bool flag; MaterialPropertyDrawer shaderPropertyDrawer = GetShaderPropertyDrawer(str, out flag); if (shaderPropertyDrawer != null) { if (flag) { if (handler.m_DecoratorDrawers == null) { handler.m_DecoratorDrawers = new List <MaterialPropertyDrawer>(); } handler.m_DecoratorDrawers.Add(shaderPropertyDrawer); } else { if (handler.m_PropertyDrawer != null) { Debug.LogWarning(string.Format("Shader property {0} already has a property drawer", name), shader); } handler.m_PropertyDrawer = shaderPropertyDrawer; } } } return(handler); }
private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name) { if (name == null) { return(null); } int propertyIndex = shader.FindPropertyIndex(name); if (propertyIndex < 0) { return(null); } string[] attribs = shader.GetPropertyAttributes(propertyIndex); if (attribs == null || attribs.Length == 0) { return(null); } var handler = new MaterialPropertyHandler(); foreach (var attr in attribs) { bool isDecorator; MaterialPropertyDrawer drawer = GetShaderPropertyDrawer(attr, out isDecorator); if (drawer != null) { if (isDecorator) { if (handler.m_DecoratorDrawers == null) { handler.m_DecoratorDrawers = new List <MaterialPropertyDrawer>(); } handler.m_DecoratorDrawers.Add(drawer); } else { if (handler.m_PropertyDrawer != null) { Debug.LogWarning(string.Format("Shader property {0} already has a property drawer", name), shader); } handler.m_PropertyDrawer = drawer; } } } return(handler); }
private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name) { string[] shaderPropertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name); MaterialPropertyHandler result; if (shaderPropertyAttributes == null || shaderPropertyAttributes.Length == 0) { result = null; } else { MaterialPropertyHandler materialPropertyHandler = new MaterialPropertyHandler(); string[] array = shaderPropertyAttributes; for (int i = 0; i < array.Length; i++) { string attrib = array[i]; bool flag; MaterialPropertyDrawer shaderPropertyDrawer = MaterialPropertyHandler.GetShaderPropertyDrawer(attrib, out flag); if (shaderPropertyDrawer != null) { if (flag) { if (materialPropertyHandler.m_DecoratorDrawers == null) { materialPropertyHandler.m_DecoratorDrawers = new List <MaterialPropertyDrawer>(); } materialPropertyHandler.m_DecoratorDrawers.Add(shaderPropertyDrawer); } else { if (materialPropertyHandler.m_PropertyDrawer != null) { Debug.LogWarning(string.Format("Shader property {0} already has a property drawer", name), shader); } materialPropertyHandler.m_PropertyDrawer = shaderPropertyDrawer; } } } result = materialPropertyHandler; } return(result); }
public float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { float num = 0.0f; if (this.m_DecoratorDrawers != null) { using (List <MaterialPropertyDrawer> .Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator()) { while (enumerator.MoveNext()) { MaterialPropertyDrawer current = enumerator.Current; num += current.GetPropertyHeight(prop, label, editor); } } } if (this.m_PropertyDrawer != null) { num += this.m_PropertyDrawer.GetPropertyHeight(prop, label, editor); } return(num); }
private static MaterialPropertyDrawer GetShaderPropertyDrawer(string attrib, out bool isDecorator) { isDecorator = false; string text = attrib; string text2 = string.Empty; Match match = Regex.Match(attrib, "(\\w+)\\s*\\((.*)\\)"); if (match.Success) { text = match.Groups[1].Value; text2 = match.Groups[2].Value.Trim(); } foreach (Type current in EditorAssemblies.SubclassesOf(typeof(MaterialPropertyDrawer))) { if (!(current.Name == text) && !(current.Name == text + "Drawer") && !(current.Name == "Material" + text + "Drawer") && !(current.Name == text + "Decorator")) { if (!(current.Name == "Material" + text + "Decorator")) { continue; } } try { isDecorator = current.Name.EndsWith("Decorator"); MaterialPropertyDrawer result = MaterialPropertyHandler.CreatePropertyDrawer(current, text2); return(result); } catch (Exception) { Debug.LogWarningFormat("Failed to create material drawer {0} with arguments '{1}'", new object[] { text, text2 }); MaterialPropertyDrawer result = null; return(result); } } return(null); }