public override void OnGUI(Rect area, SerializedProperty property, GUIContent label) { EditorUI.Reset(); float singleLine = EditorGUIUtility.singleLineHeight; area = area.SetHeight(singleLine); bool expanded = EditorPref.Get <bool>("layerDistancesExpanded"); expanded = EditorGUI.Foldout(area, expanded, "Layer Cull Distances"); EditorPref.Set <bool>("layerDistancesExpanded", expanded); if (expanded) { EditorGUI.indentLevel += 1; this.drawn = 0; float[] values = property.FindPropertyRelative("values").GetObject <float[]>(); for (int index = 0; index < 32; index++) { string layerName = LayerMask.LayerToName(index); //if(layerName.IsEmpty()){layerName = "[Unnamed]";} if (!layerName.IsEmpty()) { area = area.AddY(singleLine + 2); values[index] = values[index].Draw(area, new GUIContent(layerName)); this.drawn += 1; } } EditorGUI.indentLevel -= 1; } }
public static void Main() { GUIContent fastInspectorHelp = new GUIContent("Turbo Inspector (Experimental)"); GUIContent alwaysUpdateShadersHelp = new GUIContent("Always Update Shaders"); GUIContent alwaysUpdateParticlesHelp = new GUIContent("Always Update Particles"); GUIContent particleUpdateRangeHelp = new GUIContent("Always Update Particles (Range)"); fastInspectorHelp.tooltip = "Prevents offscreen attributes/components from being drawn in inspectors. "; fastInspectorHelp.tooltip += "Currently has issues with multiple inspectors visible and erratic nudging position offset issues while scrolling."; alwaysUpdateShadersHelp.tooltip = "Forces the scene view to repaint every frame. Huge performance cost, but will allow shaders based on time to update in realtime."; alwaysUpdateParticlesHelp.tooltip = "Forces the scene view to repaint every frame. Huge performance cost, but will continually ensure particles are simulated."; particleUpdateRangeHelp.tooltip = "Range at which editor-updated particles will simulate. Higher values will cost more performance."; if ("Other".ToLabel().DrawFoldout("Zios.Preferences.Other")) { EditorGUI.indentLevel += 1; bool fastInspector = EditorPref.Get <bool>("MonoBehaviourEditor-FastInspector").Draw(fastInspectorHelp); bool alwaysUpdateShaders = EditorPref.Get <bool>("EditorSettings-AlwaysUpdateShaders").Draw(alwaysUpdateShadersHelp); bool alwaysUpdateParticles = EditorPref.Get <bool>("EditorSettings-AlwaysUpdateParticles").Draw(alwaysUpdateParticlesHelp); float particleUpdateRange = EditorPref.Get <float>("EditorSettings-ParticleUpdateRange", 100).Draw(particleUpdateRangeHelp); if (GUI.changed) { EditorPref.Set <bool>("MonoBehaviourEditor-FastInspector", fastInspector); EditorPref.Set <bool>("EditorSettings-AlwaysUpdateShaders", alwaysUpdateShaders); EditorPref.Set <bool>("EditorSettings-AlwaysUpdateParticles", alwaysUpdateParticles); EditorPref.Set <float>("EditorSettings-ParticleUpdateRange", particleUpdateRange); } EditorGUI.indentLevel -= 1; } }
public static void RecordPref <Type>(string name, Type value) { var current = EditorPref.Get <Type>(name, value); if (!current.IsNull() && !current.Equals(value)) { Undo.snapshotPrefs[name] = current; } EditorPref.Set <Type>(name, value); }
public override void Clicked(int button) { if (button == 0) { int mode = (EditorPref.Get <int>("StateWindow-Mode", 2) + 1) % 3; EditorPref.Set <int>("StateWindow-Mode", mode); this.row.table.ShowAll(); StateWindow.Get().Repaint(); return; } }
public void Export(string path = null) { var theme = Theme.active; var targetPath = path ?? Theme.storagePath; var targetName = theme.name + "-Variant"; path = path.IsEmpty() ? EditorUtility.SaveFilePanel("Save Theme", targetPath, targetName, "unitytheme") : path; if (path.Length > 0) { var file = File.Create(path); file.Write(this.Serialize()); EditorPref.Set <string>("Zios.Theme" + Theme.suffix, theme.name); Theme.needsSetup = true; } }
public static void Draw(this GUIStyle current, string key, bool compact = false, bool grouped = false, bool headers = false) { EditorGUILayout.BeginVertical(); var styleKey = key + "." + current.name; var styleFoldout = current.name.ToLabel().DrawFoldout(styleKey); if (styleFoldout) { var labelWidth = compact ? 140 : 0; EditorGUI.indentLevel += 1; EditorUI.SetFieldSize(-1, labelWidth, false); current.name = current.name.Draw("Name".ToLabel()); EditorPref.Set <bool>(key + "." + current.name, true); if (compact && headers) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(140); EditorUI.SetLayout(120); "Text".ToLabel().DrawLabel(EditorStyles.boldLabel, false); "Background".ToLabel().DrawLabel(EditorStyles.boldLabel, false); EditorGUILayout.EndHorizontal(); } foreach (var state in current.GetNamedStates()) { state.Value.Draw(state.Key, compact, styleKey + "." + state.Key); } current.border.Draw("Border", compact, key + ".Border"); current.margin.Draw("Margin", compact, key + ".Margin"); current.padding.Draw("Padding", compact, key + ".Padding"); current.overflow.Draw("Overflow", compact, key + ".Overflow"); if (!grouped || "Text".ToTitleCase().ToLabel().DrawFoldout(key + "Text")) { current.DrawTextSettings(compact); } if (!grouped || "Position & Size".ToTitleCase().ToLabel().DrawFoldout(key + "Area")) { current.imagePosition = current.imagePosition.Draw("Image Position").As <ImagePosition>(); current.contentOffset = current.contentOffset.DrawVector2("Content Offset"); current.fixedWidth = current.fixedWidth.Draw("Fixed Width"); current.fixedHeight = current.fixedHeight.Draw("Fixed Height"); current.stretchWidth = current.stretchWidth.Draw("Stretch Width"); current.stretchHeight = current.stretchHeight.Draw("Stretch Height"); } EditorUI.ResetFieldSize(); EditorGUI.indentLevel -= 1; } EditorGUILayout.EndVertical(); }
public void Export(string path = null) { var theme = Theme.active; var savePath = path ?? Theme.storagePath + "Fontsets"; var saveName = theme.fontset.name + "-Variant"; path = path.IsEmpty() ? ProxyEditor.SaveFilePanel("Save Theme [Fonts]", savePath.GetAssetPath(), saveName, "unityfontset") : path; if (path.Length > 0) { var file = File.Create(path); file.Write(this.Serialize()); ProxyEditor.ImportAsset(path.GetAssetPath()); EditorPref.Set <string>("Zios.Theme.Fontset" + Theme.suffix, path.GetFileName()); Theme.Reset(); } }
public virtual void DrawGroup(GUIContent label, bool drawAdvanced = true) { Rect labelRect = this.labelRect.AddX(12); EditorGUIUtility.AddCursorRect(this.fullRect, MouseCursor.ArrowPlus); bool formulaExpanded = EditorPref.Get <bool>(this.attribute.info.fullPath + "FormulaExpanded"); if (this.labelRect.AddX(16).Clicked(0) || this.valueRect.Clicked(0)) { this.dirty = true; formulaExpanded = !formulaExpanded; } formulaExpanded = EditorGUI.Foldout(labelRect, formulaExpanded, label, this.skin.GetStyle("IconFormula")); EditorPref.Set <bool>(this.attribute.info.fullPath + "FormulaExpanded", formulaExpanded); if (formulaExpanded) { float lineHeight = EditorGUIUtility.singleLineHeight + 2; this.SetupAreas(this.fullRect.SetX(45).AddWidth(-55)); for (int index = 0; index < this.attribute.data.Length; ++index) { AttributeData currentData = this.attribute.data[index]; if (currentData == null) { continue; } this.DrawGroupRow(currentData, index, drawAdvanced); } this.SetupAreas(this.fullRect.AddY(lineHeight)); this.drawer.overallHeight += lineHeight; if (GUI.Button(this.labelRect.SetWidth(100), "Add Attribute")) { if (this.attribute.GetFormulaTypes().Length > 1) { this.DrawAddMenu(); return; } this.attribute.Add <DataType>(); this.dirty = true; } } else { string message = "[expand for details]"; message.ToLabel().DrawLabel(this.valueRect, this.skin.GetStyle("WarningLabel")); } }
public bool DrawInputMode(string fallback = "Search", string splitBy = " ", string endSymbol = "+") { EditorGUILayout.BeginHorizontal(); var color = EditorStyles.textField.normal.textColor.SetAlpha(0.5f); var baseStyle = EditorStyles.textField.Alignment("MiddleCenter"); var symbolStyle = baseStyle.FixedWidth(24).FontSize(16).TextColor(color); var inputStyle = baseStyle.FontStyle("BoldAndItalic"); EditorUI.SetLayout(-1, 30); if ("*".ToLabel().DrawButton(symbolStyle.ContentOffset(1, 0).Overflow(0, 3, 0, 0), false)) { var menu = new EditorMenu(); Action clear = () => this.queue = ""; menu.Add("Search", this.inputMode == 0, (() => { this.inputMode = 0; }) + clear); //menu.Add("Split",this.inputMode==1,(()=>{this.inputMode=1;})+clear); menu.Draw(); } var filter = this.inputTerms.Join(splitBy).Replace("~", " ").Draw(null, inputStyle); var inputChanged = EditorUI.lastChanged; EditorUI.lastChanged = false; endSymbol.ToLabel().DrawButton(symbolStyle.ContentOffset(-2, 0).Overflow(3, 0, 0, 0), false); EditorUI.SetLayout(-1, 0); EditorGUILayout.EndHorizontal(); bool open = false; var output = new StringBuilder(); foreach (var symbol in filter) { if (symbol == '[') { open = true; } if (symbol == ']') { open = false; } output.Append(symbol == ' ' && open ? '~' : symbol); } this.queue = this.queue ?? (output.ToString().Trim().IsEmpty() ? fallback : output.ToString()); this.queueSplit = splitBy; EditorPref.Set <string>("GUISkin-" + fallback + "-" + this.hash, this.inputTerms.Join(splitBy)); GUI.changed = false; return(inputChanged); }
public void DrawMenu() { GenericMenu menu = new GenericMenu(); MenuFunction toggleAdvanced = () => EditorPref.Toggle("MonoBehaviourEditor-Advanced"); MenuFunction toggleInternal = () => EditorPref.Toggle("MonoBehaviourEditor-Internal"); MenuFunction toggleDictionary = () => EditorPref.Toggle("MonoBehaviourEditor-Dictionary"); MenuFunction hideAllDefaults = () => EditorPref.Toggle("MonoBehaviourEditor-HideAllDefault"); MenuFunction hideLocalDefaults = () => { this.hideDefault = !this.hideDefault; EditorPref.Set <bool>("MonoBehaviourEditor-" + this.target.GetInstanceID() + "HideDefault", this.hideDefault); }; menu.AddItem(new GUIContent("Advanced"), EditorPref.Get <bool>("MonoBehaviourEditor-Advanced"), toggleAdvanced); menu.AddItem(new GUIContent("Internal"), EditorPref.Get <bool>("MonoBehaviourEditor-Internal"), toggleInternal); menu.AddItem(new GUIContent("Dictionary"), EditorPref.Get <bool>("MonoBehaviourEditor-Dictionary"), toggleDictionary); menu.AddSeparator(""); menu.AddItem(new GUIContent("Defaults/Hide All"), EditorPref.Get <bool>("MonoBehaviourEditor-HideAllDefault"), hideAllDefaults); menu.AddItem(new GUIContent("Defaults/Hide Local"), this.hideDefault, hideLocalDefaults); if (this.hidden.Count > 0) { MenuFunction unhideAll = () => { foreach (var property in this.hidden) { string path = "MonoBehaviourEditor-PropertyHide-" + this.target.GetInstanceID() + "-" + property.propertyPath; EditorPref.Set <bool>(path, false); } this.hidden.Clear(); }; menu.AddSeparator(""); menu.AddItem(new GUIContent("Unhide/All"), false, unhideAll); foreach (var property in this.hidden) { SerializedProperty target = property; MenuFunction unhide = () => { string path = "MonoBehaviourEditor-PropertyHide-" + this.target.GetInstanceID() + "-" + property.propertyPath; EditorPref.Set <bool>(path, false); this.hidden.Remove(target); }; menu.AddItem(new GUIContent("Unhide/" + property.displayName), false, unhide); } } menu.ShowAsContext(); Event.current.Use(); }
public void DrawViewMode() { var term = "Default"; this.viewMode = EditorPref.Get <int>("GUISkin-Mode", 0); if (this.viewMode == 1) { term = "Replica"; } if (this.viewMode == 2) { term = "Compact"; } if (term.ToLabel().Layout(0, 30).DrawButton()) { this.viewMode = (this.viewMode + 1) % 3; EditorPref.Set <int>("GUISkin-Mode", this.viewMode); EditorUI.foldoutChanged = true; } }
public static void Handle(string data) { var items = data.Split("&&&"); Reflection.ResetCache(); foreach (var change in items) { if (change.Trim().IsEmpty()) { continue; } if (change.Contains("###")) { var path = change.Split("###")[0]; var field = change.Split("###")[1].Split("|||")[0]; var value = change.Split("###")[1].Split("|||")[1]; var scope = Reflection.GetType(path); var type = scope.GetVariableType(field); if (type == typeof(string)) { scope.SetVariable(field, value); } else if (type == typeof(int)) { scope.SetVariable(field, value.ToInt()); } else if (type == typeof(float)) { scope.SetVariable(field, value.ToFloat()); } else if (type == typeof(bool)) { scope.SetVariable(field, value.ToBool()); } else if (type.IsEnum) { scope.SetVariable(field, Enum.Parse(type, value)); } Undo.snapshot.Remove(scope); } else { var key = change.Split("|||")[0]; var type = change.Split("|||")[1].Split("---")[0]; var value = change.Split("|||")[1].Split("---")[1]; if (type.Contains("Bool")) { EditorPref.Set <bool>(key, value.ToBool()); } else if (type.Contains("Int")) { EditorPref.Set <int>(key, value.ToInt()); } else if (type.Contains("String")) { EditorPref.Set <string>(key, value); } else if (type.Contains("Float")) { EditorPref.Set <float>(key, value.ToFloat()); } } } Undo.snapshotPrefs.Clear(); }
public override void OnInspectorGUI() { EditorUI.Reset(); ProxyEditor.GetInspector(this).SetTitle(this.title); ProxyEditor.GetInspectors().ForEach(x => x.wantsMouseMove = true); if (!Event.current.IsUseful()) { return; } if (this.target is MonoBehaviour && this.target.As <MonoBehaviour>().InPrefabFile()) { return; } this.BeginArea(); bool fastInspector = EditorPref.Get <bool>("MonoBehaviourEditor-FastInspector"); /*if(fastInspector && MonoBehaviourEditor.offScreen.ContainsKey(this)){ * GUILayout.Space(this.area.height); * this.CheckChanges(); * return; * }*/ if (Event.current.type == EventType.MouseMove) { Call.Delay(ProxyEditor.RepaintInspectors, 0.1f); } bool hideAllDefault = EditorPref.Get <bool>("MonoBehaviourEditor-HideAllDefault", false); this.hideDefault = EditorPref.Get <bool>("MonoBehaviourEditor-" + this.target.GetInstanceID() + "HideDefault", false); bool hideDefault = hideAllDefault || this.hideDefault; if (hideDefault) { this.SortDefaults(); } this.serializedObject.Update(); this.SortProperties(); this.Setup(); Type type = this.target.GetType(); this.changed = false; bool showAdvanced = EditorPref.Get <bool>("MonoBehaviourEditor-Advanced"); bool showInternal = EditorPref.Get <bool>("MonoBehaviourEditor-Internal"); bool showDictionary = EditorPref.Get <bool>("MonoBehaviourEditor-Dictionary"); EditorGUILayout.BeginVertical(); foreach (var property in this.properties) { string[] attributes = this.serializedObject.targetObject.ListAttributes(property.name).Select(x => x.GetType().Name).ToArray(); bool isInternal = attributes.Contains("InternalAttribute"); bool isAdvanced = attributes.Contains("AdvancedAttribute"); bool isReadOnly = isInternal || attributes.Contains("ReadOnlyAttribute"); bool isHidden = !this.showAll && this.hidden.Contains(property); if (isAdvanced && !showAdvanced) { isHidden = true; } if (isInternal && !showInternal) { isHidden = true; } object currentValue = property.GetObject <object>(); bool hasDefault = MonoBehaviourEditor.defaults.ContainsKey(type) && MonoBehaviourEditor.defaults[type].ContainsKey(property.name); if (!this.showAll && hideDefault && hasDefault) { object defaultValue = MonoBehaviourEditor.defaults[type][property.name]; if (defaultValue.IsNull()) { continue; } bool isDefault = defaultValue.Equals(currentValue); if (isDefault) { isHidden = true; } } if (!isHidden) { bool hasArea = this.propertyArea.ContainsKey(property); if (hasArea) { if (Event.current.shift) { bool canHide = (this.properties.Count - this.hidden.Count) > 1; if (this.propertyArea[property].Clicked(0) && canHide) { string path = "MonoBehaviourEditor-PropertyHide-" + this.target.GetInstanceID() + "-" + property.propertyPath; EditorPref.Set <bool>(path, true); this.hidden.Add(property); } if (this.propertyArea[property].Clicked(1)) { this.DrawMenu(); } } if (fastInspector && this.propertyVisible.ContainsKey(property) && !this.propertyVisible[property]) { GUILayout.Space(this.propertyArea[property].height); continue; } } string propertyName = null; if (isReadOnly) { GUI.enabled = false; } GUI.changed = false; EditorGUILayout.BeginVertical(); if (hasArea) { EditorGUI.BeginProperty(this.propertyArea[property], new GUIContent(property.displayName), property); } property.Draw(propertyName); if (hasArea) { EditorGUI.EndProperty(); } EditorGUILayout.EndVertical(); this.changed = this.changed || GUI.changed; if (isReadOnly) { GUI.enabled = true; } if (Proxy.IsRepainting()) { Rect area = GUILayoutUtility.GetLastRect(); if (!area.IsEmpty()) { this.propertyArea[property] = area.AddHeight(2); } } } } if (showDictionary) { GUI.enabled = false; foreach (var item in this.dictionaries) { item.Value.DrawAuto(item.Key, null, true); } GUI.enabled = true; } EditorGUILayout.EndVertical(); this.EndArea(); if (this.changed) { this.serializedObject.ApplyModifiedProperties(); //this.serializedObject.targetObject.CallMethod("OnValidate"); ProxyEditor.SetDirty(this.serializedObject.targetObject, false, true); } this.CheckChanges(); if (Proxy.IsRepainting()) { ProxyEditor.GetInspector(this).SetTitle("Inspector"); } }
public override void OnInspectorGUI() { if (!Event.current.IsUseful()) { return; } EditorUI.Reset(); this.Setup(true); if (this.isVisible && MaterialBuffer.active != null) { Material material = MaterialBuffer.material; this.stateChanged = ""; this.titleChanged = ""; string unsaved = MaterialBuffer.unsaved ? "*" : ""; MaterialBuffer.options["ShaderUnity"] = this.DrawTitle("Unity Shader" + unsaved, MaterialBuffer.options["ShaderUnity"]); if (MaterialBuffer.options["ShaderUnity"]) { this.drawn = -2; bool isPreview = MaterialBuffer.active.menuPath.Contains("Hidden/Preview/"); bool isBranch = MaterialBuffer.active.fileName.Contains("#"); bool exists = Shader.Find(MaterialBuffer.active.menuPath) != null; EditorGUIUtility.labelWidth = Screen.width - 207; EditorGUILayout.BeginHorizontal(); if (!isBranch && GUILayout.Button("Save")) { string warning = "Saving will overwrite the original shader and effect all materials that use it."; warning += " It is advised to instead use the Save As or Branch option."; bool confirm = EditorUI.DrawDialog("Are you sure?", warning, "Save", "Cancel"); if (confirm) { this.EndPreview(); MaterialBuffer.unsaved = false; MaterialBuffer.material.shader = MaterialBuffer.active.Save(); Log.Show("[ExtendedMaterial] Shader saved -- " + MaterialBuffer.active.path); return; } } if (GUILayout.Button("Save As")) { if (exists && !isPreview) { GUI.FocusControl("Menu"); this.warning = "Menu path must be unique for shader."; } else { this.EndPreview(); MaterialBuffer.unsaved = false; string path = EditorUtility.SaveFilePanel("Save Shader", MaterialBuffer.active.path, MaterialBuffer.active.fileName, "shader"); MaterialBuffer.material.shader = MaterialBuffer.active.Save(path); Log.Show("[ExtendedMaterial] Shader saved -- " + path); return; } } if ((MaterialBuffer.unsaved || isPreview) && GUILayout.Button("Revert")) { string warning = "Changes will be lost."; bool confirm = EditorUI.DrawDialog("Revert shader to defaults?", warning, "Revert", "Cancel"); if (confirm) { ProxyEditor.RegisterUndo(MaterialBuffer.material, "Shader Edit - Revert"); this.EndPreview(); this.FixPreviewShader(true); return; } } if (GUILayout.Button("Branch")) { this.EndPreview(); MaterialBuffer.unsaved = false; MaterialBuffer.active.Branch(); Log.Show("[ExtendedMaterial] Shader branched -- " + MaterialBuffer.active.path); return; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); MaterialBuffer.options["ShowDefault"] = this.DrawToggleButton("Show Default", MaterialBuffer.options["ShowDefault"]); MaterialBuffer.options["ShowPreview"] = this.DrawToggleButton("Show Preview", MaterialBuffer.options["ShowPreview"]); EditorGUILayout.EndHorizontal(); if (this.warning != "") { EditorGUILayout.HelpBox(this.warning, MessageType.Warning); } EditorGUI.BeginDisabledGroup(true); MaterialBuffer.active.fileName = (string)this.Draw("File", MaterialBuffer.active.fileName.Remove("-Preview")); EditorGUI.EndDisabledGroup(); string pathPrefix = isPreview ? "Hidden/Preview/" : ""; MaterialBuffer.active.menuPath = pathPrefix + (string)this.Draw("Menu", MaterialBuffer.active.menuPath.Remove("\\", "Hidden/Preview/")); MaterialBuffer.active.fallback = (string)this.Draw("Fallback", MaterialBuffer.active.fallback, ""); MaterialBuffer.active.editor = (string)this.Draw("Editor", MaterialBuffer.active.editor, ""); MaterialBuffer.options["Properties"] = this.DrawFold("Properties", MaterialBuffer.options["Properties"]); if (MaterialBuffer.options["Properties"]) { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("\t", GUILayout.Width(10)); EditorGUILayout.LabelField("Variable", GUILayout.Width(100)); EditorGUILayout.LabelField("Type", GUILayout.Width(60)); EditorGUILayout.LabelField("Name", GUILayout.Width(100)); EditorGUILayout.LabelField("Default", GUILayout.Width(100)); EditorGUILayout.EndHorizontal(); foreach (var item in MaterialBuffer.active.properties) { EditorGUILayout.BeginHorizontal(); Property property = item.Value; string type = property.type.ToString(); EditorGUILayout.LabelField("", GUILayout.Width(10)); property.variable = EditorGUILayout.TextField(property.variable, GUILayout.Width(100)); property.type = (PropertyType)EditorGUILayout.EnumPopup(property.type, GUILayout.Width(60)); property.name = EditorGUILayout.TextField(property.name, GUILayout.Width(100)); if (type != property.type.ToString()) { property.SetDefault(); continue; } if (type == "Range") { property.minimum = EditorGUILayout.FloatField(property.minimum, GUILayout.Width(30)); property.maximum = EditorGUILayout.FloatField(property.maximum, GUILayout.Width(30)); property.defaultValue = EditorGUILayout.FloatField((float)property.defaultValue, GUILayout.Width(64)); } else if (type == "Color") { property.defaultValue = EditorGUILayout.ColorField((Color)property.defaultValue, GUILayout.Width(128)); } else if (type == "Texture" || type == "Rect" || type == "Cube") { property.texgenMode = (TexGen)EditorGUILayout.EnumPopup(property.texgenMode, GUILayout.Width(64)); property.defaultValue = (TextureDefault)EditorGUILayout.EnumPopup((Enum)property.defaultValue, GUILayout.Width(64)); } else { property.defaultValue = EditorGUILayout.TextField(property.defaultValue.ToString(), GUILayout.Width(132)); } EditorGUILayout.EndHorizontal(); this.hoverObject = this.CheckHover() ? property : this.hoverObject; } bool changes = EditorGUI.EndChangeCheck(); if (GUILayout.Button("Add Property", this.UI.button, GUILayout.Width(115))) { //ProxyEditor.RegisterUndo(Buffer.active,"Shader - Add Property"); MaterialBuffer.active.AddProperty(); this.stateChanged = "Event-AddProperty"; } this.stateChanged = changes ? "Property" : this.stateChanged; MaterialBuffer.branchable = !changes; } int shaderIndex = 0; int passIndex = 0; foreach (SubShader subShader in MaterialBuffer.active.subShaders) { shaderIndex += 1; string hash = "Sub" + shaderIndex; bool showSubShaders = MaterialBuffer.active.subShaders.Count > 0; if (!MaterialBuffer.options.ContainsKey(hash)) { continue; } int passAmount = subShader.passes.Count; string passInfo = passAmount > 1 ? " [" + passAmount + " passes]" : " [1 pass]"; if (showSubShaders) { MaterialBuffer.options[hash] = this.DrawFold("SubShader" + passInfo, MaterialBuffer.options[hash]); } this.hoverObject = this.CheckHover() ? subShader : this.hoverObject; if (showSubShaders && !MaterialBuffer.options[hash]) { continue; } if (showSubShaders) { ++EditorGUI.indentLevel; } this.DrawCommon(subShader); bool hideTags = !MaterialBuffer.options["ShowDefault"] && subShader.tags.IsDefault(); if (!hideTags) { MaterialBuffer.options[hash + "Tags"] = this.DrawFold("Tags", MaterialBuffer.options[hash + "Tags"]); if (MaterialBuffer.options[hash + "Tags"]) { ++EditorGUI.indentLevel; subShader.tags.lightMode = (LightMode)this.Draw("Light Mode", subShader.tags.lightMode); subShader.tags.require = (Require)this.Draw("Require", subShader.tags.require); subShader.tags.renderQueue = (RenderQueue)this.Draw("Render Queue", subShader.tags.renderQueue); if (subShader.tags.renderQueue != RenderQueue.Default) { ++EditorGUI.indentLevel; subShader.tags.renderQueueOffset = (int)this.Draw("Offset", subShader.tags.renderQueueOffset); --EditorGUI.indentLevel; } subShader.tags.renderType = (RenderType)this.Draw("Render Type", subShader.tags.renderType); subShader.tags.ignoreProjector = (bool)this.Draw("Ignore Projector", subShader.tags.ignoreProjector, false); subShader.tags.forceNoShadowCasting = (bool)this.Draw("No Shadow Casting", subShader.tags.forceNoShadowCasting, false); --EditorGUI.indentLevel; } } this.DrawFog(subShader.fog, hash); string resetPass = ""; PassType resetType = PassType.Normal; foreach (var item in subShader.passes) { passIndex += 1; Pass pass = item.Value; string passHash = "Pass" + passIndex; string passName = pass.name != "" && !pass.name.Contains("!") ? "Pass [" + pass.name + "]" : "Pass"; if (pass.type == PassType.Use) { passName = "UsePass"; } if (pass.type == PassType.Grab) { passName = "GrabPass"; } MaterialBuffer.options[passHash] = this.DrawFold(passName, MaterialBuffer.options[passHash]); this.hoverObject = this.CheckHover() ? new object[] { subShader, pass } : this.hoverObject; if (!MaterialBuffer.options[passHash]) { continue; } ++EditorGUI.indentLevel; PassType passType = pass.type; pass.type = (PassType)this.Draw("Type", pass.type); if (pass.type != passType) { resetPass = item.Key; resetType = pass.type; continue; } if (pass.type == PassType.Normal) { pass.name = (string)this.Draw("Name", pass.name, ""); this.DrawCommon(pass); bool hidePassTags = !MaterialBuffer.options["ShowDefault"] && pass.tags.IsDefault(); if (!hidePassTags) { MaterialBuffer.options[passHash + "Tags"] = this.DrawFold("Tags", MaterialBuffer.options[passHash + "Tags"]); if (MaterialBuffer.options[passHash + "Tags"]) { ++EditorGUI.indentLevel; pass.tags.lightMode = (LightMode)this.Draw("Light Mode", pass.tags.lightMode); pass.tags.require = (Require)this.Draw("Require", pass.tags.require); --EditorGUI.indentLevel; } } this.DrawFog(pass.fog, passHash); bool hideGPUShader = !MaterialBuffer.options["ShowDefault"] && pass.gpuShader == ""; if (!hideGPUShader) { EditorGUI.BeginChangeCheck(); pass.gpuShader = EditorGUILayout.TextArea(pass.gpuShader, GUILayout.Width(Screen.width - 45)); this.stateChanged = EditorGUI.EndChangeCheck() ? "TextArea" : this.stateChanged; } } else if (pass.type == PassType.Use) { pass.usePass = (string)this.Draw("Shader", pass.usePass); } else if (pass.type == PassType.Grab) { pass.grabPass = (string)this.Draw("Texture", pass.grabPass, ""); } --EditorGUI.indentLevel; } if (resetPass != "") { subShader.passes[resetPass] = new Pass(); subShader.passes[resetPass].type = resetType; } if (GUILayout.Button("Add Pass", this.UI.button, GUILayout.Width(115))) { //ProxyEditor.RegisterUndo(Buffer.active,"Shader - Add Pass"); subShader.AddPass(); this.LoadSettings(); this.stateChanged = "Event-AddPass"; } if (showSubShaders) { --EditorGUI.indentLevel; } } if (GUILayout.Button("Add SubShader", GUILayout.Width(115))) { //ProxyEditor.RegisterUndo(Buffer.active,"Shader - Add SubShader"); MaterialBuffer.active.AddSubShader(); this.LoadSettings(); this.stateChanged = "Event-AddSubShader"; } } //Buffer.options["ShaderGPU"] = this.DrawTitle("GPU Shader",Buffer.options["ShaderGPU"]); MaterialBuffer.options["Material"] = this.DrawTitle("Material", MaterialBuffer.options["Material"]); if (MaterialBuffer.options["Material"]) { EditorGUIUtility.labelWidth = Screen.width - 84; base.OnInspectorGUI(); } if (this.stateChanged != "" || this.titleChanged != "") { foreach (var item in MaterialBuffer.options) { string key = item.Key; int value = item.Value.ToInt(); string settingPrefix = key.ContainsAny("ShowDefault", "ShowPreview") ? "ExtendedMaterial-" : MaterialBuffer.material.name + "-"; EditorPref.Set <int>(settingPrefix + key, value); } this.warning = ""; ProxyEditor.SetDirty(material); } if (this.titleChanged != "" || this.stateChanged.Contains("ToggleButton")) { GUI.FocusControl("Menu"); } if (this.stateChanged != "") { MaterialBuffer.unsaved = true; if (MaterialBuffer.options["ShowPreview"]) { MaterialBuffer.buildDelay = Time.Get(); MaterialBuffer.buildPreview = true; } if (this.stateChanged.Contains("TextArea")) { MaterialBuffer.buildDelay += 2.0f; } if (this.stateChanged.Contains("Field")) { MaterialBuffer.buildDelay += 1.5f; } if (this.stateChanged.Contains("Color")) { MaterialBuffer.buildDelay += 0.5f; } //Log.Show("[ExtendedMaterial] Value changed -- " + this.stateChanged); } } this.CheckContext(); }
public virtual void DrawContext(AttributeData data, bool showRemove = false, bool isRoot = true) { if (this.labelRect.AddWidth(20).Clicked(1)) { this.contextOpen = true; GenericMenu menu = new GenericMenu(); AttributeMode mode = this.attribute.info.mode; AttributeUsage usage = data.usage; bool advanced = EditorPref.Get <bool>(data.path + "Advanced"); MenuFunction toggleAdvanced = () => { EditorPref.Set <bool>(data.path + "Advanced", !advanced); }; MenuFunction removeAttribute = () => { this.attribute.Remove(data); }; MenuFunction modeNormal = () => { this.attribute.info.mode = AttributeMode.Normal; }; MenuFunction modeLinked = () => { this.attribute.info.mode = AttributeMode.Linked; }; MenuFunction modeFormula = () => { this.attribute.info.mode = AttributeMode.Formula; }; MenuFunction modeGroup = () => { this.attribute.info.mode = AttributeMode.Group; }; MenuFunction usageDirect = () => { data.usage = AttributeUsage.Direct; data.referencePath = ""; data.referenceID = ""; data.reference = null; }; MenuFunction usageShaped = () => { data.usage = AttributeUsage.Shaped; }; MenuFunction fixType = () => { this.SwapType(0, typeof(DataType), this.attribute.defaultSet); }; bool normal = this.attribute.info.mode == AttributeMode.Normal; if (this.attribute.locked) { menu.AddDisabledItem(new GUIContent("Attribute Locked")); menu.ShowAsContext(); return; } if (isRoot || mode.Matches("Normal", "Linked")) { if (mode.Matches("Normal", "Linked") && usage.Matches("Shaped") && this.attribute.canAdvanced) { menu.AddItem(new GUIContent("Advanced"), advanced, toggleAdvanced); menu.AddSeparator("/"); } if (this.attribute.canDirect) { menu.AddItem(new GUIContent("Direct"), normal && (usage == AttributeUsage.Direct), fixType + modeNormal + usageDirect); } if (this.attribute.canShape) { menu.AddItem(new GUIContent("Shaped"), normal && (usage == AttributeUsage.Shaped), fixType + modeNormal + usageShaped); } if (this.attribute.canLink) { menu.AddItem(new GUIContent("Linked"), (mode == AttributeMode.Linked), fixType + modeLinked + usageShaped); } menu.AddSeparator("/"); if (this.attribute.canFormula) { menu.AddItem(new GUIContent("Formula"), (mode == AttributeMode.Formula), modeFormula); } if (this.attribute.canGroup) { menu.AddItem(new GUIContent("Group"), (mode == AttributeMode.Group), modeGroup); } } else if (mode.Matches("Formula")) { menu.AddItem(new GUIContent("Advanced"), advanced, toggleAdvanced); this.DrawTypeMenu(data, menu); menu.AddSeparator("/"); if (this.attribute.canDirect) { menu.AddItem(new GUIContent("Direct"), usage == AttributeUsage.Direct, usageDirect); } if (this.attribute.canShape) { menu.AddItem(new GUIContent("Shaped"), usage == AttributeUsage.Shaped, usageShaped); } } if (showRemove) { if (!mode.Matches("Group")) { menu.AddSeparator("/"); } menu.AddItem(new GUIContent("Remove"), false, removeAttribute); } menu.ShowAsContext(); } if (this.contextOpen && Event.current.button == 0) { this.dirty = true; this.contextOpen = false; } }