public override void DrawStyle() { var window = StateWindow.Get(); var row = this.row.target.As <StateRow>(); var script = row.target; bool darkSkin = EditorGUIUtility.isProSkin || EditorPref.Get <bool>("Zios.Theme.Dark", false); string name = this.target is string?(string)this.target : script.alias; string background = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm"; Color textColor = darkSkin? Colors.Get("Silver") : Colors.Get("Black"); GUIStyle style = new GUIStyle(GUI.skin.label); GUIStyle expand = Style.Get("buttonExpand", true); bool fieldHovered = window.row == this.row.order; if (fieldHovered) { textColor = darkSkin ? Colors.Get("ZestyBlue") : Colors.Get("White"); background = darkSkin ? "BoxBlackHighlightBlueAWarm" : "BoxBlackHighlightBlueDWarm"; } if (this.row.selected) { textColor = darkSkin ? Colors.Get("White") : Colors.Get("White"); background = darkSkin ? "BoxBlackHighlightCyanA" : "BoxBlackHighlightCyanCWarm"; } style.fixedWidth -= 28; style.margin.left = 0; style.normal.textColor = textColor; style.normal.background = File.GetAsset <Texture2D>(background); if (this.row.selected) { expand.normal.background = style.normal.background; expand.normal.textColor = textColor; expand.hover = expand.normal; style.hover = style.normal; } bool open = EditorPref.Get <bool>("StateWindow-GroupRow-" + row.section, false); string symbol = open ? "-" : "+"; StateWindow.Clip(symbol, expand, -1, window.headerSize); if (GUILayoutUtility.GetLastRect().AddX(window.scroll.x).Clicked()) { EditorPref.Toggle("StateWindow-GroupRow-" + row.section); foreach (var groupRow in this.groupRows) { groupRow.disabled = !groupRow.disabled; } Event.current.Use(); window.tableGUI.ShowAll(); window.Repaint(); } StateWindow.Clip(name, style, -1, window.headerSize); }
public virtual void DrawStyle(int state = 0) { var window = StateWindow.Get(); string value = ""; var stateRow = (StateRow)this.row.target; var row = this.row.target.As <StateRow>(); int rowIndex = window.rowIndex[row]; var mode = (HeaderMode)EditorPref.Get <int>("StateWindow-Mode", 3); GUIStyle style = new GUIStyle(GUI.skin.button); value = stateRow.requirements.Length > 1 ? (rowIndex + 1).ToString() : ""; if (this.row.selected) { style = Style.Get("buttonSelected", true); } else if (state == -1) { style = Style.Get("buttonDisabled", true); } else if (state == 1) { style = Style.Get("buttonOn", true); } else if (state == 2) { style = Style.Get("buttonOff", true); } else if (state == 3) { style = Style.Get("buttonUsed", true); } style.fixedWidth = window.cellSize; if (mode == HeaderMode.HorizontalFit) { bool lastEnabled = this.row.fields.Last(x => !x.disabled) == this; style.margin.right = lastEnabled ? 18 : 0; style.fixedWidth = lastEnabled ? 0 : style.fixedWidth; } float headerSize = window.headerSize; StateWindow.Clip(value.ToLabel(), style, GUI.skin.label.fixedWidth + 7, headerSize); if (!Proxy.IsPlaying() && GUILayoutUtility.GetLastRect().Hovered()) { window.row = this.row.order; window.column = this.order; window.hovered = true; } }
//=================================== // Utility //=================================== public static void Clip(UnityLabel label, GUIStyle style, float xClip = 0, float yClip = 0) { Rect next = GUILayoutUtility.GetRect(label, style); StateWindow.Clip(next, label, style, xClip, yClip); }
public override void Draw() { var window = StateWindow.Get(); var hidden = !this.target.Equals("") && !window.target.manual && this.target.As <StateRequirement>().name == "@External"; if (hidden) { return; } var target = this.target is StateRequirement?this.target.As <StateRequirement>() : null; var script = !target.IsNull() ? target.target.As <StateBehaviour>() : null; var scroll = window.scroll; var label = this.target is string?new GUIContent("") : new GUIContent(this.target.GetVariable <string>("name")); GUIStyle style = new GUIStyle(GUI.skin.label); var mode = (HeaderMode)EditorPref.Get <int>("StateWindow-Mode", 2); bool darkSkin = EditorGUIUtility.isProSkin || EditorPref.Get <bool>("Zios.Theme.Dark", false); Color textColor = Colors.Get("Gray"); string background = darkSkin ? "BoxBlackAWarm30" : "BoxWhiteBWarm50"; if (window.target.external) { textColor = darkSkin ? Colors.Get("Silver") : Colors.Get("Black"); background = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm"; } if (label.text == "") { this.disabled = this.row.fields.Skip(1).Count(x => !x.disabled) < 1; window.headerSize = 64; style.margin.left = 5; style.hover = style.normal; style.normal.background = File.GetAsset <Texture2D>(background); if (mode == HeaderMode.Vertical) { window.headerSize = 35; style.fixedHeight = style.fixedWidth; StateWindow.Clip(label, style, 0, window.headerSize); } if (mode != HeaderMode.Vertical) { StateWindow.Clip(label, style, -1, -1); } return; } bool fieldHovered = window.column == this.order; if (fieldHovered) { background = darkSkin ? "BoxBlackHighlightBlueAWarm" : "BoxBlackHighlightBlueDWarm"; textColor = darkSkin ? Colors.Get("ZestyBlue") : Colors.Get("White"); } if (Proxy.IsPlaying() && !script.IsNull()) { textColor = Colors.Get("Gray"); background = darkSkin ? "BoxBlackAWarm30" : "BoxWhiteBWarm50"; bool usable = target.name == "@External" ? window.target.external : script.usable; bool active = target.name == "@External" ? window.target.external : script.active; if (usable) { textColor = darkSkin ? Colors.Get("Silver") : Colors.Get("Black"); background = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm"; } if (script.used) { textColor = darkSkin ? Colors.Get("White") : Colors.Get("White"); background = darkSkin ? "BoxBlackHighlightYellowAWarm" : "BoxBlackHighlightYellowDWarm"; } if (active) { textColor = darkSkin ? Colors.Get("White") : Colors.Get("White"); background = darkSkin ? "BoxBlackHighlightPurpleAWarm" : "BoxBlackHighlightPurpleDWarm"; } } style.normal.textColor = textColor; style.normal.background = File.GetAsset <Texture2D>(background); if (mode == HeaderMode.Vertical) { window.cellSize = style.fixedHeight; float halfWidth = style.fixedWidth / 2; float halfHeight = style.fixedHeight / 2; GUIStyle rotated = new GUIStyle(style).Rotate90(); Rect last = GUILayoutUtility.GetRect(new GUIContent(""), rotated); GUIUtility.RotateAroundPivot(90, last.center); Rect position = new Rect(last.x, last.y, 0, 0); position.x += halfHeight - halfWidth; position.y += -halfHeight + halfWidth; style.overflow.left = (int)-scroll.y; label.text = style.overflow.left >= -(position.width / 4) - 9 ? label.text : ""; label.ToLabel().DrawLabel(position, style); GUI.matrix = Matrix4x4.identity; } else { style.fixedWidth -= 36; window.cellSize = style.fixedWidth; if (mode == HeaderMode.HorizontalFit) { var visible = this.row.fields.Skip(1).Where(x => !x.disabled).ToList(); float area = window.cellSize = (Screen.width - style.fixedWidth - 56) / visible.Count; area = window.cellSize = Mathf.Floor(area - 2); bool lastEnabled = visible.Last() == this; style.margin.right = lastEnabled ? 18 : 0; style.fixedWidth = lastEnabled ? 0 : area; } style.alignment = TextAnchor.MiddleCenter; StateWindow.Clip(label, style, GUI.skin.label.fixedWidth + 7, -1); } this.CheckClicked(0, scroll.y); }
public virtual void DrawStyle() { var window = StateWindow.Get(); var stateRow = (StateRow)this.row.target; var row = this.row.target.As <StateRow>(); var script = row.target; bool darkSkin = EditorGUIUtility.isProSkin || EditorPref.Get <bool>("Zios.Theme.Dark", false); string name = this.target is string?(string)this.target : this.target.As <StateRow>().name; string background = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm"; Color textColor = darkSkin ? Colors.Get("Silver") : Colors.Get("Black"); string prefixColor = Colors.Get("DarkOrange").ToHex(); GUIStyle style = new GUIStyle(GUI.skin.label); style.margin.left = 5; bool fieldHovered = window.row == this.row.order || this.hovered; if (fieldHovered) { prefixColor = Colors.Get("ZestyOrange").ToHex(); textColor = darkSkin ? Colors.Get("ZestyBlue") : Colors.Get("White"); background = darkSkin ? "BoxBlackHighlightBlueAWarm" : "BoxBlackHighlightBlueDWarm"; } if (this.row.selected) { prefixColor = Colors.Get("ZestyOrange").ToHex(); textColor = darkSkin ? Colors.Get("White") : Colors.Get("White"); background = darkSkin ? "BoxBlackHighlightCyanA" : "BoxBlackHighlightCyanCWarm"; } if (Proxy.IsPlaying()) { textColor = Colors.Get("Gray"); background = darkSkin ? "BoxBlackAWarm30" : "BoxWhiteBWarm50"; bool usable = row.target is StateTable && row.target != window.target ? row.target.As <StateTable>().external : script.usable; if (usable) { textColor = darkSkin ? Colors.Get("Silver") : Colors.Get("Black"); background = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm"; } if (script.used) { textColor = darkSkin ? Colors.Get("White") : Colors.Get("White"); background = darkSkin ? "BoxBlackHighlightYellowAWarm" : "BoxBlackHighlightYellowDWarm"; } if (script.active) { textColor = darkSkin ? Colors.Get("White") : Colors.Get("White"); background = darkSkin ? "BoxBlackHighlightPurpleAWarm" : "BoxBlackHighlightPurpleDWarm"; } } if (!row.section.IsEmpty()) { style.margin.left = 33; style.fixedWidth -= 28; } style.normal.textColor = textColor; style.normal.background = File.GetAsset <Texture2D>(background); if (this.row.selected) { style.hover = style.normal; } int currentRow = window.rowIndex[stateRow] + 1; int totalRows = stateRow.requirements.Length; var prefix = stateRow.requirements.Length > 1 ? "<color=" + prefixColor + "><i>[" + currentRow + "/" + totalRows + "]</i></color> " : ""; GUIContent content = new GUIContent(prefix + name); StateWindow.Clip(content, style, -1, window.headerSize); }