public static void drawSmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties) { Rect thumbnailPos = position; thumbnailPos.x += hasFoldoutProperties ? 20 : 0; editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, (hasFoldoutProperties ? "Click here for extra properties" : "") + (label.tooltip != "" ? " | " : "") + label.tooltip); if (hasFoldoutProperties && DrawingData.currentTexProperty != null) { //draw dropdown triangle thumbnailPos.x += DrawingData.currentTexProperty.xOffset * 15; if (Event.current.type == EventType.Repaint) { EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.currentTexProperty.showFoldoutProperties, false); } if (DrawingData.is_enabled) { //test click and draw scale/offset if (DrawingData.currentTexProperty.showFoldoutProperties) { if (DrawingData.currentTexProperty.hasScaleOffset) { ThryEditor.currentlyDrawing.editor.TextureScaleOffsetProperty(prop); } PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ThryEditor.currentlyDrawing.propertyDictionary[r_property]; EditorGUIUtility.labelWidth += EditorGUI.indentLevel * 15; EditorGUI.indentLevel *= 2; ThryEditor.currentlyDrawing.editor.ShaderProperty(property.materialProperty, property.content); EditorGUI.indentLevel /= 2; EditorGUIUtility.labelWidth -= EditorGUI.indentLevel * 15; } } } if (ThryEditor.input.MouseClick && position.Contains(Event.current.mousePosition)) { DrawingData.currentTexProperty.showFoldoutProperties = !DrawingData.currentTexProperty.showFoldoutProperties; editor.Repaint(); } } } DrawingData.lastGuiObjectHeaderRect = position; Rect object_rect = new Rect(position); object_rect.height = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height; DrawingData.lastGuiObjectRect = object_rect; }
private void LoadLocales() { MaterialProperty locales_property = GetMaterialProperty(PROPERTY_NAME_LOCALE); Locale = null; if (locales_property != null) { string displayName = locales_property.displayName; PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName); Locale = new Locale(options.file_name); Locale.selected_locale_index = (int)locales_property.floatValue; } }
public void Foldout(int xOffset, GUIContent content, ThryEditor gui) { var style = new GUIStyle(Styles.Get().dropDownHeader); style.margin.left = 30 * xOffset; var rect = GUILayoutUtility.GetRect(16f + 20f, 22f, style); DrawingData.lastGuiObjectRect = rect; //rect with text GUI.Box(rect, content, style); PropertyOptions options = ThryEditor.currentlyDrawing.currentProperty.options; if (options.button_right != null && options.button_right.condition_show.Test()) { Rect buttonRect = new Rect(rect); GUIContent buttoncontent = new GUIContent(options.button_right.text, options.button_right.hover); float width = Styles.Get().dropDownHeaderButton.CalcSize(buttoncontent).x; width = width < rect.width / 3 ? rect.width / 3 : width; buttonRect.x += buttonRect.width - width - 10; buttonRect.y += 2; buttonRect.width = width; if (GUI.Button(buttonRect, buttoncontent, Styles.Get().dropDownHeaderButton)) { if (options.button_right.action != null) { options.button_right.action.Perform(); } } EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link); } var e = Event.current; var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f); if (e.type == EventType.Repaint) { //small arrow EditorStyles.foldout.Draw(toggleRect, false, false, getState(), false); } if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition) && !e.alt) { this.Toggle(); e.Use(); } }
private void DrawHelpButton(Rect rect, PropertyOptions options, Event e) { ButtonData button = this.button != null ? this.button : options.button_help; if (button != null && button.condition_show.Test()) { if (GuiHelper.Button(rect, Styles.icon_style_help)) { ShaderEditor.input.Use(); if (button.action != null) { button.action.Perform(); } } } }
private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options) { if (options.reference_property != null && ShaderEditor.active.propertyDictionary.ContainsKey(options.reference_property)) { GUI.Box(rect, new GUIContent(" " + content.text, content.tooltip), Styles.dropDownHeader); DrawIcons(rect, e); DrawButton(rect, options, e); Rect togglePropertyRect = new Rect(rect); togglePropertyRect.x += 5; togglePropertyRect.y += 2; togglePropertyRect.height -= 4; togglePropertyRect.width = GUI.skin.font.fontSize * 3; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUIUtility.fieldWidth = 20; ShaderProperty prop = ShaderEditor.active.propertyDictionary[options.reference_property]; int xOffset = prop.xOffset; prop.xOffset = 0; prop.Draw(new CRect(togglePropertyRect), new GUIContent(), isInHeader: true); prop.xOffset = xOffset; EditorGUIUtility.fieldWidth = fieldWidth; } else if (keyword != null) { GUI.Box(rect, " " + content.text, Styles.dropDownHeader); DrawIcons(rect, e); DrawButton(rect, options, e); Rect togglePropertyRect = new Rect(rect); togglePropertyRect.x += 20; togglePropertyRect.width = 20; EditorGUI.BeginChangeCheck(); bool keywordOn = EditorGUI.Toggle(togglePropertyRect, "", ShaderEditor.active.materials[0].IsKeywordEnabled(keyword)); if (EditorGUI.EndChangeCheck()) { MaterialHelper.ToggleKeyword(ShaderEditor.active.materials, keyword, keywordOn); } } else { GUI.Box(rect, content, Styles.dropDownHeader); DrawIcons(rect, e); DrawButton(rect, options, e); } }
/// <summary> /// Draws the icons for ShaderEditor features like linking and copying /// </summary> /// <param name="rect"></param> /// <param name="e"></param> private void DrawIcons(Rect rect, PropertyOptions options, Event e) { Rect buttonRect = new Rect(rect); buttonRect.y += 1; buttonRect.height -= 4; buttonRect.width = buttonRect.height; float right = rect.x + rect.width; buttonRect.x = right - 56; DrawHelpButton(buttonRect, options, e); buttonRect.x = right - 38; DrawLinkSettings(buttonRect, e); buttonRect.x = right - 20; DrawDowdownSettings(buttonRect, e); }
public void Foldout(int xOffset, GUIContent content, ThryEditor gui) { PropertyOptions options = ThryEditor.currentlyDrawing.currentProperty.options; Event e = Event.current; GUIStyle style = new GUIStyle(Styles.dropDownHeader); style.margin.left = 15 * xOffset + 15; Rect rect = GUILayoutUtility.GetRect(16f + 20f, 22f, style); DrawingData.lastGuiObjectHeaderRect = rect; DrawBoxAndContent(rect, e, content, options, style); DrawSmallArrow(rect, e); HandleToggleInput(e, rect); }
public ShaderPart(MaterialProperty prop, int xOffset, string displayName, PropertyOptions options) { this.materialProperty = prop; this.xOffset = xOffset; this.options = options; this.content = new GUIContent(displayName, options.tooltip); this.reference_properties_exist = options.reference_properties != null && options.reference_properties.Length > 0; this.reference_property_exists = options.reference_property != null; if (prop == null) { return; } this.kaj_isAnimatedProperty = ShaderEditor.FindProperty(ShaderEditor.currentlyDrawing.properties, prop.name + "Animated"); this.is_animatable = kaj_isAnimatedProperty != null; this.is_animated = is_animatable && kaj_isAnimatedProperty.floatValue > 0; this.is_renaming = is_animatable && kaj_isAnimatedProperty.floatValue == 2; }
public bool has_not_searchedFor = false; //used for property search public ShaderPart(ShaderEditor shaderEditor, MaterialProperty prop, int xOffset, string displayName, PropertyOptions options) { this.shaderEditor = shaderEditor; this.materialProperty = prop; this.xOffset = xOffset; this.options = options; this.content = new GUIContent(displayName); this.tooltip = new BetterTooltips.Tooltip(options.tooltip); this.reference_properties_exist = options.reference_properties != null && options.reference_properties.Length > 0; this.reference_property_exists = options.reference_property != null; this.is_preset = shaderEditor._isPresetEditor && Presets.IsPreset(shaderEditor.materials[0], prop); if (prop == null) { return; } bool propHasDuplicate = shaderEditor.GetMaterialProperty(prop.name + "_" + shaderEditor.animPropertySuffix) != null; string tag = null; //If prop is og, but is duplicated (locked) dont have it animateable if (propHasDuplicate) { this.is_animatable = false; } else { //if prop is a duplicated or renamed get og property to check for animted status if (prop.name.Contains(shaderEditor.animPropertySuffix)) { string ogName = prop.name.Substring(0, prop.name.Length - shaderEditor.animPropertySuffix.Length - 1); tag = ShaderOptimizer.GetAnimatedTag(materialProperty.targets[0] as Material, ogName); } else { tag = ShaderOptimizer.GetAnimatedTag(materialProperty); } this.is_animatable = true; } this.is_animated = is_animatable && tag != ""; this.is_renaming = is_animatable && tag == "2"; }
private void LoadLocales() { MaterialProperty locales_property = null; locale = null; foreach (MaterialProperty m in editorData.properties) { if (m.name == PROPERTY_NAME_LOCALE) { locales_property = m; } } if (locales_property != null) { string displayName = locales_property.displayName; PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName); locale = new Locale(options.file_name); locale.selected_locale_index = (int)locales_property.floatValue; } }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { this.property = prop; this.expanded = prop.floatValue == 1; PropertyOptions options = ShaderEditor.active.currentProperty.options; Event e = Event.current; int offset = 15 * xOffset + 15; position.width -= offset - position.x; position.x = offset; DrawingData.lastGuiObjectHeaderRect = position; DrawBoxAndContent(position, e, label, options); DrawSmallArrow(position, e); HandleToggleInput(e, position); }
private void DrawHelpButton(Rect rect, PropertyOptions options, Event e) { ButtonData button = this.button != null ? this.button : options.button_help; if (button != null && button.condition_show.Test()) { Rect buttonRect = new Rect(rect); buttonRect.width = 20; buttonRect.x += rect.width - 65; buttonRect.y += 1; buttonRect.height -= 4; if (GUI.Button(buttonRect, Styles.icon_help, EditorStyles.largeLabel)) { e.Use(); if (button.action != null) { button.action.Perform(); } } } }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { if (this.property == null) { this.property = prop; this._isExpanded = prop.floatValue == 1; } PropertyOptions options = ShaderEditor.Active.CurrentProperty.Options; Event e = Event.current; position.width -= p_xOffset_total - position.x; position.x = p_xOffset_total; DrawingData.LastGuiObjectHeaderRect = position; DrawBoxAndContent(position, e, label, options); DrawSmallArrow(position, e); HandleToggleInput(position); }
private PropertyOptions ExtractExtraOptionsFromDisplayName(ref string displayName) { if (displayName.Contains(EXTRA_OPTIONS_PREFIX)) { string[] parts = displayName.Split(new string[] { EXTRA_OPTIONS_PREFIX }, 2, System.StringSplitOptions.None); displayName = parts[0]; PropertyOptions options = Parser.ParseToObject <PropertyOptions>(parts[1]); if (options != null) { if (options.condition_showS != null) { options.condition_show = DefineableCondition.Parse(options.condition_showS); } if (options.on_value != null) { options.on_value_actions = PropertyValueAction.ParseToArray(options.on_value); } return(options); } } return(new PropertyOptions()); }
private void DrawButton(Rect rect, PropertyOptions options, Event e, GUIStyle style) { if (options.button_right != null && options.button_right.condition_show.Test()) { Rect buttonRect = new Rect(rect); GUIContent buttoncontent = new GUIContent(options.button_right.text, options.button_right.hover); float width = Styles.dropDownHeaderButton.CalcSize(buttoncontent).x; width = width < rect.width / 3 ? rect.width / 3 : width; buttonRect.x += buttonRect.width - width - 50; buttonRect.y += 2; buttonRect.width = width; if (GUI.Button(buttonRect, buttoncontent, Styles.dropDownHeaderButton)) { e.Use(); if (options.button_right.action != null) { options.button_right.action.Perform(); } } EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link); } }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { if (!is_init) { Init(prop); } EditorGUI.BeginChangeCheck(); GuiHelper.drawSmallTextureProperty(position, prop, label, editor, DrawingData.currentTexProperty.hasFoldoutProperties); if (EditorGUI.EndChangeCheck()) { Init(prop); } UpdateRects(position); GradientField(); if (Event.current.type == EventType.MouseDown && border_position.Contains(Event.current.mousePosition)) { PropertyOptions options = ThryEditor.currentlyDrawing.currentProperty.options; GradientEditor.Open(data, prop, options.texture, options.force_texture_options, !options.force_texture_options); } }
public ShaderPart(MaterialProperty prop, int xOffset, string displayName, PropertyOptions options) { this.materialProperty = prop; this.xOffset = xOffset; this.options = options; this.content = new GUIContent(displayName, options.tooltip); this.reference_properties_exist = options.reference_properties != null && options.reference_properties.Length > 0; this.reference_property_exists = options.reference_property != null; if (prop == null) { return; } bool propHasDuplicate = ShaderEditor.active.GetMaterialProperty(prop.name + "_" + ShaderEditor.currentlyDrawing.animPropertySuffix) != null; if (propHasDuplicate) { this.kaj_isAnimatedProperty = null; } else { this.kaj_isAnimatedProperty = ShaderEditor.active.GetMaterialProperty(prop.name + "Animated"); if (prop.name.Contains(ShaderEditor.currentlyDrawing.animPropertySuffix)) { string ogNameAnimated = prop.name.Substring(0, prop.name.Length - ShaderEditor.currentlyDrawing.animPropertySuffix.Length - 1) + "Animated"; MaterialProperty p = ShaderEditor.active.GetMaterialProperty(ogNameAnimated); if (p != null) { this.kaj_isAnimatedProperty = p; } } } this.is_animatable = this.kaj_isAnimatedProperty != null; this.is_animated = is_animatable && kaj_isAnimatedProperty.floatValue > 0; this.is_renaming = is_animatable && kaj_isAnimatedProperty.floatValue == 2; }
//finds all properties and headers and stores them in correct order private void CollectAllProperties() { //load display names from file if it exists MaterialProperty[] props = properties; Dictionary <string, string> labels = LoadDisplayNamesFromFile(); LoadLocales(); propertyDictionary = new Dictionary <string, ShaderProperty>(); shaderParts = new List <ShaderPart>(); mainHeader = new ShaderHeader(this); //init top object that all Shader Objects are childs of Stack <ShaderGroup> headerStack = new Stack <ShaderGroup>(); //header stack. used to keep track if editorData header to parent new objects to headerStack.Push(mainHeader); //add top object as top object to stack headerStack.Push(mainHeader); //add top object a second time, because it get's popped with first actual header item footers = new List <FooterButton>(); //init footer list int headerCount = 0; for (int i = 0; i < props.Length; i++) { DrawingData.ResetLastDrawerData(); editor.GetPropertyHeight(props[i]); string displayName = props[i].displayName; //Load from label file if (labels.ContainsKey(props[i].name)) { displayName = labels[props[i].name]; } //Check for locale if (locale != null) { if (displayName.Contains("locale::")) { Match m = Regex.Match(displayName, @"locale::(\d\w)+d"); if (m.Success) { string key = m.Value.Substring(8, m.Value.Length - 8); if (locale.Constains(key)) { displayName = displayName.Replace("locale::" + locale.Get(key), ""); } } } } displayName = displayName.Replace("''", "\""); //extract json data from display name PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName); int offset = options.offset + headerCount; ThryPropertyType type = GetPropertyType(props[i], options); switch (type) { case ThryPropertyType.header: headerStack.Pop(); break; case ThryPropertyType.legacy_header: headerStack.Pop(); break; case ThryPropertyType.headerWithEnd: case ThryPropertyType.legacy_header_start: offset = options.offset + ++headerCount; break; case ThryPropertyType.legacy_header_end: headerStack.Pop(); headerCount--; break; case ThryPropertyType.on_swap_to: on_swap_to_actions = options.actions; break; } ShaderProperty newPorperty = null; ShaderPart newPart = null; switch (type) { case ThryPropertyType.master_label: shaderHeader = new ShaderHeaderProperty(this, props[i], displayName, 0, options, false); break; case ThryPropertyType.footer: footers.Add(new FooterButton(Parser.ParseToObject <ButtonData>(displayName))); break; case ThryPropertyType.header: case ThryPropertyType.headerWithEnd: case ThryPropertyType.legacy_header: case ThryPropertyType.legacy_header_start: if (options.is_hideable) { show_HeaderHider = true; } ShaderHeader newHeader = new ShaderHeader(this, props[i], editor, displayName, offset, options); headerStack.Peek().addPart(newHeader); headerStack.Push(newHeader); HeaderHider.InitHidden(newHeader); newPart = newHeader; break; case ThryPropertyType.group_start: ShaderGroup new_group = new ShaderGroup(this, options); headerStack.Peek().addPart(new_group); headerStack.Push(new_group); newPart = new_group; break; case ThryPropertyType.group_end: headerStack.Pop(); break; case ThryPropertyType.none: case ThryPropertyType.property: bool forceOneLine = props[i].type == MaterialProperty.PropType.Vector && !DrawingData.lastPropertyUsedCustomDrawer; if (props[i].type == MaterialProperty.PropType.Texture) { newPorperty = new TextureProperty(this, props[i], displayName, offset, options, props[i].flags.HasFlag(MaterialProperty.PropFlags.NoScaleOffset) == false, !DrawingData.lastPropertyUsedCustomDrawer); } else { newPorperty = new ShaderProperty(this, props[i], displayName, offset, options, forceOneLine); } break; case ThryPropertyType.lightmap_flags: newPorperty = new GIProperty(this, props[i], displayName, offset, options, false); break; case ThryPropertyType.dsgi: newPorperty = new DSGIProperty(this, props[i], displayName, offset, options, false); break; case ThryPropertyType.instancing: newPorperty = new InstancingProperty(this, props[i], displayName, offset, options, false); break; case ThryPropertyType.locale: newPorperty = new LocaleProperty(this, props[i], displayName, offset, options, false); break; case ThryPropertyType.shader_optimizer: use_ShaderOptimizer = true; newPorperty = new ShaderProperty(this, props[i], displayName, offset, options, false); break; } if (newPorperty != null) { newPart = newPorperty; if (propertyDictionary.ContainsKey(props[i].name)) { continue; } propertyDictionary.Add(props[i].name, newPorperty); //Debug.Log(newPorperty.materialProperty.name + ":" + headerStack.Count); if (type != ThryPropertyType.none && type != ThryPropertyType.shader_optimizer) { headerStack.Peek().addPart(newPorperty); } } //if new header is at end property if (headerStack.Peek() is ShaderHeader && (headerStack.Peek() as ShaderHeader).GetEndProperty() == props[i].name) { headerStack.Pop(); headerCount--; } if (newPart != null) { shaderParts.Add(newPart); DrawingData.lastInitiatedPart = newPart; editor.GetPropertyHeight(props[i]); DrawingData.lastInitiatedPart = null; } } }
public LocaleProperty(MaterialProperty materialProperty, string displayName, int xOffset, PropertyOptions options, bool forceOneLine) : base(materialProperty, displayName, xOffset, options, forceOneLine) { drawDefault = true; }
public TextureProperty(MaterialProperty materialProperty, string displayName, int xOffset, PropertyOptions options, bool hasScaleOffset, bool forceThryUI) : base(materialProperty, displayName, xOffset, options, false) { drawDefault = forceThryUI; this.hasScaleOffset = hasScaleOffset; this.hasFoldoutProperties = hasScaleOffset || reference_properties_exist || reference_property_exists; }
public ShaderProperty(MaterialProperty materialProperty, string displayName, int xOffset, PropertyOptions options, bool forceOneLine) : base(materialProperty, xOffset, displayName, options) { drawDefault = false; this.forceOneLine = forceOneLine; property_index = System.Array.IndexOf(ShaderEditor.currentlyDrawing.properties, materialProperty); }
public ShaderHeader(MaterialProperty prop, MaterialEditor materialEditor, string displayName, int xOffset, PropertyOptions options) : base(prop, materialEditor, displayName, xOffset, options) { this.guiElement = new ShaderEditorHeader(prop); }
public ShaderGroup(MaterialProperty prop, MaterialEditor materialEditor, string displayName, int xOffset, PropertyOptions options) : base(prop, xOffset, displayName, options) { }
public ShaderGroup(PropertyOptions options) : base(null, 0, "", new PropertyOptions()) { this.options = options; }
private ThryPropertyType GetPropertyType(MaterialProperty p, PropertyOptions options) { string name = p.name; MaterialProperty.PropFlags flags = p.flags; if (name.StartsWith("footer_") && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.footer); } if (name.StartsWith("m_end") && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.header_end); } if (name.StartsWith("m_start") && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.header_start); } if (name.StartsWith("m_") && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.header); } if (name.StartsWith("g_start") && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.group_start); } if (name.StartsWith("g_end") && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.group_end); } if (Regex.Match(name.ToLower(), @"^space\d*$").Success) { return(ThryPropertyType.space); } if (name == PROPERTY_NAME_MASTER_LABEL) { return(ThryPropertyType.master_label); } if (name == PROPERTY_NAME_ON_SWAP_TO_ACTIONS) { return(ThryPropertyType.on_swap_to); } if (name.Replace(" ", "") == "Instancing" && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.instancing); } if (name.Replace(" ", "") == "DSGI" && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.dsgi); } if (name.Replace(" ", "") == "LightmapFlags" && flags == MaterialProperty.PropFlags.HideInInspector) { return(ThryPropertyType.lightmap_flags); } if (name.Replace(" ", "") == PROPERTY_NAME_LOCALE) { return(ThryPropertyType.locale); } if (name == "_ShaderOptimizerEnabled") { return(ThryPropertyType.shader_optimizer); } if (flags != MaterialProperty.PropFlags.HideInInspector && !options.hide_in_inspector) { return(ThryPropertyType.property); } return(ThryPropertyType.none); }
//finds all properties and headers and stores them in correct order private void CollectAllProperties() { //load display names from file if it exists MaterialProperty[] props = editorData.properties; Dictionary <string, string> labels = LoadDisplayNamesFromFile(); LoadLocales(); editorData.propertyDictionary = new Dictionary <string, ShaderProperty>(); editorData.shaderParts = new List <ShaderPart>(); shaderparts = new ShaderHeader(); //init top object that all Shader Objects are childs of Stack <ShaderGroup> headerStack = new Stack <ShaderGroup>(); //header stack. used to keep track if editorData header to parent new objects to headerStack.Push(shaderparts); //add top object as top object to stack headerStack.Push(shaderparts); //add top object a second time, because it get's popped with first actual header item footer = new List <ButtonData>(); //init footer list int headerCount = 0; Type materialPropertyDrawerType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.MaterialPropertyHandler"); MethodInfo getPropertyHandlerMethod = materialPropertyDrawerType.GetMethod("GetShaderPropertyHandler", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); PropertyInfo drawerProperty = materialPropertyDrawerType.GetProperty("propertyDrawer"); Type materialToggleDrawerType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.MaterialToggleDrawer"); FieldInfo keyWordField = materialToggleDrawerType.GetField("keyword", BindingFlags.Instance | BindingFlags.NonPublic); for (int i = 0; i < props.Length; i++) { string displayName = props[i].displayName; if (locale != null) { foreach (string key in locale.GetAllKeys()) { if (displayName.Contains("locale::" + key)) { displayName = displayName.Replace("locale::" + key, locale.Get(key)); } } } displayName = Regex.Replace(displayName, @"''", "\""); if (labels.ContainsKey(props[i].name)) { displayName = labels[props[i].name]; } PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName); int offset = options.offset + headerCount; //Handle keywords object propertyHandler = getPropertyHandlerMethod.Invoke(null, new object[] { editorData.shader, props[i].name }); //if has custom drawer if (propertyHandler != null) { object propertyDrawer = drawerProperty.GetValue(propertyHandler, null); //if custom drawer exists if (propertyDrawer != null) { if (propertyDrawer.GetType().ToString() == "UnityEditor.MaterialToggleDrawer") { object keyword = keyWordField.GetValue(propertyDrawer); if (keyword != null) { foreach (Material m in editorData.materials) { if (m.GetFloat(props[i].name) == 1) { m.EnableKeyword((string)keyword); } else { m.DisableKeyword((string)keyword); } } } } } } ThryPropertyType type = GetPropertyType(props[i], options); switch (type) { case ThryPropertyType.header: headerStack.Pop(); break; case ThryPropertyType.header_start: offset = options.offset + ++headerCount; break; case ThryPropertyType.header_end: headerStack.Pop(); headerCount--; break; case ThryPropertyType.on_swap_to: on_swap_to_actions = options.actions; break; } ShaderProperty newPorperty = null; ShaderPart newPart = null; switch (type) { case ThryPropertyType.master_label: masterLabelText = displayName; break; case ThryPropertyType.footer: footer.Add(Parser.ParseToObject <ButtonData>(displayName)); break; case ThryPropertyType.header: case ThryPropertyType.header_start: if (options.is_hideable) { editorData.show_HeaderHider = true; } ShaderHeader newHeader = new ShaderHeader(props[i], editorData.editor, displayName, offset, options); headerStack.Peek().addPart(newHeader); headerStack.Push(newHeader); HeaderHider.InitHidden(newHeader); newPart = newHeader; break; case ThryPropertyType.group_start: ShaderGroup new_group = new ShaderGroup(options); headerStack.Peek().addPart(new_group); headerStack.Push(new_group); newPart = new_group; break; case ThryPropertyType.group_end: headerStack.Pop(); break; case ThryPropertyType.none: case ThryPropertyType.property: DrawingData.lastPropertyUsedCustomDrawer = false; editorData.editor.GetPropertyHeight(props[i]); bool forceOneLine = props[i].type == MaterialProperty.PropType.Vector && !DrawingData.lastPropertyUsedCustomDrawer; if (props[i].type == MaterialProperty.PropType.Texture) { newPorperty = new TextureProperty(props[i], displayName, offset, options, props[i].flags.HasFlag(MaterialProperty.PropFlags.NoScaleOffset) == false, !DrawingData.lastPropertyUsedCustomDrawer); } else { newPorperty = new ShaderProperty(props[i], displayName, offset, options, forceOneLine); } break; case ThryPropertyType.lightmap_flags: newPorperty = new GIProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.dsgi: newPorperty = new DSGIProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.instancing: newPorperty = new InstancingProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.locale: newPorperty = new LocaleProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.shader_optimizer: editorData.use_ShaderOptimizer = true; newPorperty = new ShaderProperty(props[i], displayName, offset, options, false); break; } if (newPorperty != null) { newPart = newPorperty; if (editorData.propertyDictionary.ContainsKey(props[i].name)) { continue; } editorData.propertyDictionary.Add(props[i].name, newPorperty); if (type != ThryPropertyType.none && type != ThryPropertyType.shader_optimizer) { headerStack.Peek().addPart(newPorperty); } } if (newPart != null) { editorData.shaderParts.Add(newPart); } } }
private ThryPropertyType GetPropertyType(MaterialProperty p, PropertyOptions options) { string name = p.name; MaterialProperty.PropFlags flags = p.flags; if (DrawingData.lastPropertyDrawerType == DrawerType.Header) { return((DrawingData.lastPropertyDrawer as ThryHeaderDrawer).GetEndProperty() != null ? ThryPropertyType.headerWithEnd : ThryPropertyType.header); } if (name == PROPERTY_NAME_MASTER_LABEL) { return(ThryPropertyType.master_label); } if (name == PROPERTY_NAME_ON_SWAP_TO_ACTIONS) { return(ThryPropertyType.on_swap_to); } if (name == "_ShaderOptimizerEnabled") { return(ThryPropertyType.shader_optimizer); } if (flags == MaterialProperty.PropFlags.HideInInspector) { if (name.StartsWith("m_start")) { return(ThryPropertyType.legacy_header_start); } if (name.StartsWith("m_end")) { return(ThryPropertyType.legacy_header_end); } if (name.StartsWith("m_")) { return(ThryPropertyType.legacy_header); } if (name.StartsWith("g_start")) { return(ThryPropertyType.group_start); } if (name.StartsWith("g_end")) { return(ThryPropertyType.group_end); } if (name.StartsWith("footer_")) { return(ThryPropertyType.footer); } string noWhiteSpaces = name.Replace(" ", ""); if (noWhiteSpaces == "Instancing") { return(ThryPropertyType.instancing); } if (noWhiteSpaces == "DSGI") { return(ThryPropertyType.dsgi); } if (noWhiteSpaces == "LightmapFlags") { return(ThryPropertyType.lightmap_flags); } if (noWhiteSpaces == PROPERTY_NAME_LOCALE) { return(ThryPropertyType.locale); } if (Regex.Match(name.ToLower(), @"^space\d*$").Success) { return(ThryPropertyType.space); } } else if (flags.HasFlag(MaterialProperty.PropFlags.HideInInspector) == false) { if (!options.hide_in_inspector) { return(ThryPropertyType.property); } } return(ThryPropertyType.none); }
public static void drawSmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties) { Rect thumbnailPos = position; Rect foloutClickCheck = position; thumbnailPos.x += hasFoldoutProperties ? 20 : 0; editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, label.tooltip); if (DrawingData.currentTexProperty.reference_property_exists) { ShaderProperty property = ShaderEditor.active.propertyDictionary[DrawingData.currentTexProperty.options.reference_property]; Rect r = position; r.x += EditorGUIUtility.labelWidth - CurrentIndentWidth(); r.width -= EditorGUIUtility.labelWidth - CurrentIndentWidth(); foloutClickCheck.width -= r.width; property.Draw(new CRect(r), new GUIContent()); property.tooltip.ConditionalDraw(r); } if (hasFoldoutProperties && DrawingData.currentTexProperty != null) { //draw dropdown triangle thumbnailPos.x += DrawingData.currentTexProperty.xOffset * 15; //This is an invisible button with zero functionality. But it needs to be here so that the triangle click reacts fast if (GUI.Button(thumbnailPos, "", GUIStyle.none)) { } if (Event.current.type == EventType.Repaint) { EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.currentTexProperty.showFoldoutProperties, false); } if (DrawingData.is_enabled) { //test click and draw scale/offset if (DrawingData.currentTexProperty.showFoldoutProperties) { EditorGUI.indentLevel += 2; if (DrawingData.currentTexProperty.hasScaleOffset) { ShaderEditor.active.editor.TextureScaleOffsetProperty(prop); } PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ShaderEditor.active.propertyDictionary[r_property]; property.Draw(useEditorIndent: true); } } EditorGUI.indentLevel -= 2; } if (ShaderEditor.input.LeftClick_IgnoreUnityUses && foloutClickCheck.Contains(Event.current.mousePosition)) { ShaderEditor.input.Use(); DrawingData.currentTexProperty.showFoldoutProperties = !DrawingData.currentTexProperty.showFoldoutProperties; } } } Rect object_rect = new Rect(position); object_rect.height = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height; DrawingData.lastGuiObjectRect = object_rect; DrawingData.tooltipCheckRect = position; }
public static void drawStylizedBigTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties, bool skip_drag_and_drop_handling = false) { position.x += (EditorGUI.indentLevel) * 15; position.width -= (EditorGUI.indentLevel) * 15; Rect rect = GUILayoutUtility.GetRect(label, Styles.bigTextureStyle); rect.x += (EditorGUI.indentLevel) * 15; rect.width -= (EditorGUI.indentLevel) * 15; Rect border = new Rect(rect); border.position = new Vector2(border.x, border.y - position.height); border.height += position.height; if (DrawingData.currentTexProperty.reference_properties_exist) { border.height += 8; foreach (string r_property in DrawingData.currentTexProperty.options.reference_properties) { border.height += editor.GetPropertyHeight(ShaderEditor.active.propertyDictionary[r_property].materialProperty); } } if (DrawingData.currentTexProperty.reference_property_exists) { border.height += 8; border.height += editor.GetPropertyHeight(ShaderEditor.active.propertyDictionary[DrawingData.currentTexProperty.options.reference_property].materialProperty); } //background //GUI.DrawTexture(border, Styles.rounded_texture, ScaleMode.StretchToFill, true, 0, Styles.COLOR_BACKGROUND_1, 0, 0); Color prevC = GUI.color; GUI.color = Styles.COLOR_BACKGROUND_1; GUI.DrawTexture(border, Styles.rounded_texture, ScaleMode.StretchToFill, true); Rect quad = new Rect(border); quad.width = quad.height / 2; GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0, 0, 0.5f, 1), true); quad.x += border.width - quad.width; GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0.5f, 0, 0.5f, 1), true); GUI.color = prevC; quad.width = border.height - 4; quad.height = quad.width; quad.x = border.x + border.width - quad.width - 1; quad.y += 2; Rect preview_rect_border = new Rect(position); preview_rect_border.height = rect.height + position.height - 6; preview_rect_border.width = preview_rect_border.height; preview_rect_border.y += 3; preview_rect_border.x += position.width - preview_rect_border.width - 3; Rect preview_rect = new Rect(preview_rect_border); preview_rect.height -= 6; preview_rect.width -= 6; preview_rect.x += 3; preview_rect.y += 3; if (prop.hasMixedValue) { Rect mixedRect = new Rect(preview_rect); mixedRect.y -= 5; mixedRect.x += mixedRect.width / 2 - 4; GUI.Label(mixedRect, "_"); } else if (prop.textureValue != null) { GUI.DrawTexture(preview_rect, prop.textureValue); } GUI.DrawTexture(preview_rect_border, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 0, Color.grey, 3, 5); //selection button and pinging Rect select_rect = new Rect(preview_rect); select_rect.height = 12; select_rect.y += preview_rect.height - 12; if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow && texturePickerWindowProperty.name == prop.name) { prop.textureValue = (Texture)EditorGUIUtility.GetObjectPickerObject(); ShaderEditor.Repaint(); } if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow) { texturePickerWindow = -1; texturePickerWindowProperty = null; } if (GUI.Button(select_rect, "Select", EditorStyles.miniButton)) { EditorGUIUtility.ShowObjectPicker <Texture>(prop.textureValue, false, "", 0); texturePickerWindow = EditorGUIUtility.GetObjectPickerControlID(); texturePickerWindowProperty = prop; } else if (Event.current.type == EventType.MouseDown && preview_rect.Contains(Event.current.mousePosition)) { EditorGUIUtility.PingObject(prop.textureValue); } if (!skip_drag_and_drop_handling) { if ((ShaderEditor.input.is_drag_drop_event) && preview_rect.Contains(ShaderEditor.input.mouse_position) && DragAndDrop.objectReferences[0] is Texture) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (ShaderEditor.input.is_drop_event) { DragAndDrop.AcceptDrag(); prop.textureValue = (Texture)DragAndDrop.objectReferences[0]; } } } //scale offset rect if (hasFoldoutProperties || DrawingData.currentTexProperty.options.reference_property != null) { EditorGUI.indentLevel += 2; if (DrawingData.currentTexProperty.hasScaleOffset) { Rect scale_offset_rect = new Rect(position); scale_offset_rect.y += 37; scale_offset_rect.width -= 2 + preview_rect.width + 10 + 30; scale_offset_rect.x += 30; editor.TextureScaleOffsetProperty(scale_offset_rect, prop); } float oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 128; PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_property != null) { ShaderProperty property = ShaderEditor.active.propertyDictionary[options.reference_property]; property.Draw(useEditorIndent: true); } if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ShaderEditor.active.propertyDictionary[r_property]; property.Draw(useEditorIndent: true); } } EditorGUIUtility.labelWidth = oldLabelWidth; EditorGUI.indentLevel -= 2; } Rect label_rect = new Rect(position); label_rect.x += 2; label_rect.y += 2; GUI.Label(label_rect, label); GUILayoutUtility.GetRect(0, 5); DrawingData.lastGuiObjectRect = border; DrawingData.tooltipCheckRect = border; }
public ShaderProperty(MaterialProperty materialProperty, string displayName, int xOffset, PropertyOptions options, bool forceOneLine) : base(materialProperty, xOffset, displayName, options) { drawDefault = false; this.forceOneLine = forceOneLine; }