public void Draw(CRect rect = null, GUIContent content = null, bool useEditorIndent = false, bool isInHeader = false) { if (ShaderEditor.active.show_search_bar && !has_searchedFor) { return; } if (HeaderHider.IsHeaderHidden(this)) { return; } bool addDisableGroup = options.condition_enable != null && DrawingData.is_enabled; if (addDisableGroup) { DrawingData.is_enabled = options.condition_enable.Test(); EditorGUI.BeginDisabledGroup(!DrawingData.is_enabled); } if (options.condition_show.Test()) { PerformDraw(content, rect, useEditorIndent, isInHeader); } if (addDisableGroup) { DrawingData.is_enabled = true; EditorGUI.EndDisabledGroup(); } }
private void GUIComplexity() { //Visibility menu if (show_HeaderHider) { HeaderHider.HeaderHiderGUI(active); } }
private void GUIComplexity() { //Visibility menu if (editorData.show_HeaderHider) { HeaderHider.HeaderHiderGUI(editorData); } }
public void Draw(CRect rect = null, GUIContent content = null, bool useEditorIndent = false) { if (HeaderHider.IsHeaderHidden(this)) { return; } bool is_enabled = DrawingData.is_enabled; if (options.condition_enable != null && is_enabled) { DrawingData.is_enabled = options.condition_enable.Test(); EditorGUI.BeginDisabledGroup(!DrawingData.is_enabled); } if (options.condition_show.Test()) { PerformDraw(content, rect, useEditorIndent); } if (options.condition_enable != null && is_enabled) { DrawingData.is_enabled = true; EditorGUI.EndDisabledGroup(); } }
//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; } } }
//-------------Main Function-------------- public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { if (firstOnGUICall || (reloadNextDraw && Event.current.type == EventType.Layout)) { editorData = new EditorData(); editorData.editor = materialEditor; editorData.gui = this; editorData.textureArrayProperties = new List <ShaderProperty>(); editorData.firstCall = true; } editorData.properties = props; CheckInAnimationRecordMode(); m_RenderersForAnimationMode = MaterialEditor.PrepareMaterialPropertiesForAnimationMode(props, GUI.enabled); UpdateEvents(); //first time call inits if (firstOnGUICall || (reloadNextDraw && Event.current.type == EventType.Layout)) { OnOpen(); } editorData.shader = editorData.materials[0].shader; currentlyDrawing = editorData; active = this; //sync shader and get preset handler Config config = Config.Get(); if (editorData.materials != null) { Mediator.SetActiveShader(editorData.materials[0].shader); } //TOP Bar Rect mainHeaderRect = EditorGUILayout.BeginHorizontal(); //draw editor settings button if (GUILayout.Button(new GUIContent("", Styles.settings_icon), EditorStyles.largeLabel, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20))) { Thry.Settings window = Thry.Settings.getInstance(); window.Show(); window.Focus(); } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); if (GUILayout.Button(Styles.search_icon, EditorStyles.largeLabel, GUILayout.MaxHeight(20))) { show_search_bar = !show_search_bar; } //draw master label if exists if (masterLabelText != null) { GuiHelper.DrawMasterLabel(masterLabelText, mainHeaderRect); } //GUILayout.Label("Thryrallo",GUILayout.ExpandWidth(true)); GUILayout.Label("@UI by Thryrallo", Styles.made_by_style, GUILayout.Height(25), GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); if (show_search_bar) { header_search_term = EditorGUILayout.TextField(header_search_term); } //Visibility menu if (editorData.show_HeaderHider) { HeaderHider.HeaderHiderGUI(editorData); } bool isMaterialLocked = editorData.use_ShaderOptimizer && editorData.propertyDictionary["_ShaderOptimizerEnabled"].materialProperty.floatValue == 1; if (editorData.use_ShaderOptimizer) { editorData.propertyDictionary["_ShaderOptimizerEnabled"].Draw(); } EditorGUI.BeginDisabledGroup(isMaterialLocked); //PROPERTIES if (header_search_term == "" || show_search_bar == false) { foreach (ShaderPart part in shaderparts.parts) { part.Draw(); } } else { foreach (ShaderPart part in editorData.propertyDictionary.Values) { if (IsSearchedFor(part, header_search_term)) { part.Draw(); } } } EditorGUI.EndDisabledGroup(); //Render Queue selection if (config.showRenderQueue) { materialEditor.RenderQueueField(); } //footer GuiHelper.drawFooters(footer); if (GUILayout.Button("@UI Made by Thryrallo", Styles.made_by_style)) { Application.OpenURL("https://www.twitter.com/thryrallo"); } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); Event e = Event.current; bool isUndo = (e.type == EventType.ExecuteCommand || e.type == EventType.ValidateCommand) && e.commandName == "UndoRedoPerformed"; if (reloadNextDraw && Event.current.type == EventType.Layout) { reloadNextDraw = false; } if (isUndo) { reloadNextDraw = true; } //on swap if (on_swap_to_actions != null && swapped_to_shader) { foreach (DefineableAction a in on_swap_to_actions) { a.Perform(); } on_swap_to_actions = null; swapped_to_shader = false; } //test if material has been reset if (wasUsed && e.type == EventType.Repaint) { if (editorData.materials[0].HasProperty("shader_is_using_thry_editor") && editorData.materials[0].GetFloat("shader_is_using_thry_editor") != 69) { reloadNextDraw = true; HandleReset(); wasUsed = true; } } if (e.type == EventType.Used) { wasUsed = true; } if (input.HadMouseDownRepaint) { input.HadMouseDown = false; } input.HadMouseDownRepaint = false; editorData.firstCall = false; }
//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); } } }