private void SubWinB(Rect main, Rect toolbar) { GUI.Label(new Rect(main.x, main.y, main.width, 20), "这是一个有Toolbar的SubWindow"); if (GUIEx.ToolbarButton(new Rect(toolbar.x, toolbar.y, 100, toolbar.height), "btn")) { } }
/// <summary> /// /// </summary> /// <param name="title">标题</param> /// <param name="icon">图标</param> /// <param name="active">初始是否激活</param> /// <param name="windowStyle">窗口样式</param> /// <param name="toolbar">是否显示工具栏</param> /// <param name="helpBox">帮助栏样式</param> public EWSubWindowAttribute(string title, EWSubWindowIcon icon = EWSubWindowIcon.None, bool active = true, SubWindowStyle windowStyle = SubWindowStyle.Default, EWSubWindowToolbarType toolbar = EWSubWindowToolbarType.None, SubWindowHelpBoxType helpBox = SubWindowHelpBoxType.None) { this.title = title; this.active = active; this.windowStyle = windowStyle; this.toolbar = toolbar; this.helpBox = helpBox; this.iconPath = GUIEx.GetIconPath(icon); }
public override void DrawGUI(Rect rect, System.Action repaintAction) { rect = new Rect(rect.x + 2, rect.y, rect.width - 4, rect.height - 2); if (m_TweenParam.isTweening) { m_TweenParam = GUIEx.ScaleTweenBox(rect, m_TweenParam, m_SubWindows[m_SelectSubWindow].Title, GUIStyleCache.GetStyle("dragtabdropwindow")); if (repaintAction != null) { repaintAction(); } return; } GUI.BeginGroup(rect, GUIStyleCache.GetStyle("PreBackground")); GUI.Box(new Rect(0, 0, rect.width, 18), string.Empty, GUIStyleCache.GetStyle("dockarea")); if (m_SelectSubWindow >= 0 && m_SelectSubWindow < m_SubWindows.Count) { GUI.Label(new Rect(m_SelectSubWindow * 110, 0, rect.width - m_SelectSubWindow * 110, 18), m_SubWindows[m_SelectSubWindow].Title, GUIStyleCache.GetStyle("dragtabdropwindow")); } for (int i = 0; i < m_SubWindows.Count; i++) { if (m_SelectSubWindow != i) { if (GUI.Button(new Rect(i * 110, 0, 110, 17), m_SubWindows[i].Title, GUIStyleCache.GetStyle("dragtab"))) { m_SelectSubWindow = i; } } } GUI.Box(new Rect(0, 18, rect.width, rect.height - 18), string.Empty, GUIStyleCache.GetStyle("hostview")); if (m_SelectSubWindow >= 0 && m_SelectSubWindow < m_SubWindows.Count) { GUI.BeginGroup(new Rect(0, 18, rect.width, rect.height - 18)); m_SubWindows[m_SelectSubWindow].DrawSubWindow(new Rect(0, 0, rect.width, rect.height - 18)); GUI.EndGroup(); if (repaintAction != null) { repaintAction(); } } if (m_SelectSubWindow >= 0 && m_SelectSubWindow < m_SubWindows.Count) { m_SubWindows[m_SelectSubWindow].DrawToolBarExt(new Rect(rect.width - 100, 0, 100, 18)); } GUI.EndGroup(); this.rect = rect; }
/// <summary> /// 绘制工具栏 /// </summary> public void DrawToolBar() { for (int i = 0; i < m_NodeList.Count; i++) { Rect rect = EditorGUILayout.GetControlRect(GUILayout.Width(70), GUILayout.Height(17)); if (GUIEx.ToolbarButton(rect, m_NodeList[i].m_Text)) { ClickDropDown(rect, m_NodeList[i]); } } }
/// <summary> /// 绘制工具栏-视图按钮 /// </summary> public void DrawViewButton(Rect rect) { // Rect rect = EditorGUILayout.GetControlRect(GUILayout.Width(70), GUILayout.Height(17)); if (GUIEx.ToolbarButton(rect, "Tabs")) { if (m_Root != null) { GenericMenu menu = new GenericMenu(); for (int i = 0; i < m_SubWindowList.Count; i++) { menu.AddItem(new GUIContent(m_SubWindowList[i].Title), m_SubWindowList[i].IsOpen, OnSetSubWindowActive, m_SubWindowList[i]); } menu.DropDown(rect); } } }
/// <summary> /// Renders the timeline. /// </summary> private void DrawWindow() { GUI.skin = skin; GUIEx.ScrollView(this.verticalScrollRect, this.verticalScrollPosition, this.verticalScrollViewRect, GUIStyle.none, GUIStyle.none, () => { this.DrawBackground(); this.DrawNames(); GUIEx.ScrollView(this.horizontalScrollRect, this.horizontalScrollPosition, this.horizontalScrollViewRect, GUIStyle.none, GUIStyle.none, () => { this.DrawEntries(); }); }); this.DrawScrollbars(); this.DrawZoomInfo(); }
private void OnGUI() { state1_ = GUIEx.Dropdown(new Rect(30, 30, 100, 30), new[] { "A", "B", "C" }, state1_); var styles = new GUIEx.DropdownStyles("button", "box", Color.white, 24, 8); state2_ = GUIEx.Dropdown(new Rect(150, 30, 150, 30), new[] { "X", "Y", "Z", "W" }, state2_, styles); state3_ = GUIEx.Dropdown( new Rect(10, Screen.height - 50, Screen.width - 20, 40), new[] { "1920 x 1080 (Recommend)", "1600 x 1024", "1280 x 960", "1280 x 800", }, state3_); }
protected override bool TriggerAnchorArea(Vector2 position, int depth, SubWindow window, System.Action <SubWindow> preDropAction, System.Action postDropAction) { if (m_TweenParam.isTweening) { return(false); } if (depth >= kMaxNodeDepth) { return(false); } if (m_SubWindows.Count >= kMaxSubWindowCount) { return(false); } if (this.m_SubWindows.Contains(window)) { return(false); } Rect rect = new Rect(this.rect.x, this.rect.y, this.rect.width, 17); if (rect.Contains(position)) { if (preDropAction == null) { tweenParam = GUIEx.ScaleTweenBox(rect, tweenParam, string.Empty, GUIStyleCache.GetStyle("SelectionRect")); } else { if (preDropAction != null) { preDropAction(window); this.AddWindow(window, 0); postDropAction(); } } return(true); } return(false); }
private void DrawersGUI() { int count = RootValueDrawerCount; if (count == 0) { return; } var width = position.width; drawersGUIOptions[0] = GUILayout.MaxWidth(width); for (int i = 0; i < count; ++i) { var drawer = rootValueDrawers[i]; drawer.GUI(null, drawersGUIOptions); // Draw separate line. if (i < count - 1) { GUIEx.HorizontalLine(position.width); } } }
private void LogEntriesGUI() { var evt = Event.current; var evtType = evt.type; var options = GUILayoutOptions.Get(GUILayoutOptionType.MinHeight) .SetValue(GUILayoutOptionType.MinHeight, 40); using (var scroll = new EditorGUILayout.ScrollViewScope(logEntriesScrollPosition, options)) { using (new EditorGUILayout.VerticalScope()) { foreach (var entry in LogEntries) { bool selected = entry == SelectedLogEntry; EditorGUILayout.LabelField(entry.Message, GetLogEntryStyle(selected)); var rect = GUILayoutUtility.GetLastRect(); int index = entry.Index; if (evtType == EventType.MouseDown && rect.Contains(evt.mousePosition)) { scheduledGUIActions.ScheduleAction(() => SelectedLogEntryIndex = index); Repaint(); } } } logEntriesScrollPosition = scroll.scrollPosition; } GUIEx.HorizontalLine(position.width); if (SelectedLogEntry != null) { SelectedLogEntry.StackTraceControl.GUI(); } }
private void AddDynamicSubWindowInternal(string title, EWSubWindowIcon icon, EWSubWindowToolbarType toolbar, SubWindowHelpBoxType helpbox, Delegate action) { AddDynamicSubWindowInternal(title, GUIEx.GetIconPath(icon), toolbar, helpbox, action); }
/// <summary> /// 触发锚点区域 /// </summary> /// <param name="position"></param> /// <param name="depth"></param> /// <param name="window"></param> /// <param name="preDropAction"></param> /// <param name="postDropAction"></param> /// <returns></returns> protected virtual bool TriggerAnchorArea(Vector2 position, int depth, SubWindow window, System.Action <SubWindow> preDropAction, System.Action postDropAction) { if (depth >= kMaxNodeDepth) { return(false); } Rect r = default(Rect); float offset = 0; for (int i = 0; i < m_Childs.Count; i++) { if (m_Childs[i].TriggerAnchorArea(position, depth + 1, window, preDropAction, postDropAction)) { return(true); } if (isHorizontal) { r = new Rect(rect.x + offset, rect.y, rect.width * m_Childs[i].weight * 0.2f, rect.height); if (r.Contains(position)) { if (preDropAction == null) { tweenParam = GUIEx.ScaleTweenBox(r, tweenParam, string.Empty, GUIStyleCache.GetStyle("SelectionRect")); } else { this.DropWindow(window, preDropAction, postDropAction, true, i); } return(true); } r = new Rect(rect.x + offset + rect.width * m_Childs[i].weight * 0.8f, rect.y, rect.width * m_Childs[i].weight * 0.2f, rect.height); if (r.Contains(position)) { if (preDropAction == null) { tweenParam = GUIEx.ScaleTweenBox(r, tweenParam, string.Empty, GUIStyleCache.GetStyle("SelectionRect")); } else { this.DropWindow(window, preDropAction, postDropAction, true, i + 1); } return(true); } r = new Rect(rect.x + offset, rect.y + rect.height * 0.8f, rect.width * m_Childs[i].weight, rect.height * 0.2f); if (r.Contains(position) && m_Childs.Count > 1) { if (preDropAction == null) { tweenParam = GUIEx.ScaleTweenBox(r, tweenParam, string.Empty, GUIStyleCache.GetStyle("SelectionRect")); } else { this.DropWindow(window, preDropAction, postDropAction, false, i); } return(true); } offset += m_Childs[i].weight * rect.width; } else { r = new Rect(rect.x, rect.y + offset, rect.width, rect.height * m_Childs[i].weight * 0.2f); if (r.Contains(position)) { if (preDropAction == null) { tweenParam = GUIEx.ScaleTweenBox(r, tweenParam, string.Empty, GUIStyleCache.GetStyle("SelectionRect")); } else { this.DropWindow(window, preDropAction, postDropAction, true, i); } return(true); } r = new Rect(rect.x, rect.y + offset + rect.height * m_Childs[i].weight * 0.8f, rect.width, rect.height * m_Childs[i].weight * 0.2f); if (r.Contains(position)) { if (preDropAction == null) { tweenParam = GUIEx.ScaleTweenBox(r, tweenParam, string.Empty, GUIStyleCache.GetStyle("SelectionRect")); } else { this.DropWindow(window, preDropAction, postDropAction, true, i + 1); } return(true); } r = new Rect(rect.x + rect.width * 0.8f, rect.y + offset, rect.width * 0.2f, rect.height * m_Childs[i].weight); if (r.Contains(position) && m_Childs.Count > 1) { if (preDropAction == null) { tweenParam = GUIEx.ScaleTweenBox(r, tweenParam, string.Empty, GUIStyleCache.GetStyle("SelectionRect")); } else { this.DropWindow(window, preDropAction, postDropAction, false, i); } return(true); } offset += m_Childs[i].weight * rect.height; } } return(false); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label, GUIEx.LabelStyle(FontStyle.Bold)); Rect foldoutRect = new Rect(position.x, position.y + 20, position.width, 20); property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, new GUIContent("Show Localizable string")); if (property.isExpanded) { SerializedProperty arrayProperty = property.FindPropertyRelative("_defaultStrings"); Rect buttonAddRect = new Rect(position.x, position.y + 40, position.width, 20); if (GUI.Button(buttonAddRect, "Add plural form")) { arrayProperty.InsertArrayElementAtIndex(arrayProperty.arraySize); } Rect buttonRemoveRect = new Rect(position.x, position.y + 64, position.width, 20); if (GUI.Button(buttonRemoveRect, "Remove last plural form")) { if (arrayProperty.arraySize > 1) { arrayProperty.DeleteArrayElementAtIndex(arrayProperty.arraySize - 1); } } this.ListIterator(position, arrayProperty); } EditorGUI.EndProperty(); }
public override void OnInspectorGUI() { string weightedSetTypeName = typeof(TWeightedSet).FullName; string itemTypeName = typeof(TWeightedSetItem).FullName; var setContainer = this.target as IWeightedSetContainer <TWeightedSet, TWeightedSetItem>; ThrowIf.Null( setContainer, "WeightedSetEditor<{0}, {1}> target does not implement IWeightedSetContainer<{0}, {1}>.", weightedSetTypeName, itemTypeName); List <TWeightedSetItem> items = setContainer.WeightedSet.Items; List <float> weights = setContainer.WeightedSet.Weights; ThrowIf.True(items.Count != weights.Count, "Mismatched number of items and wieghts."); GUILayout.BeginVertical(); this.IsItemsExpanded = EditorGUILayout.Foldout(this.IsItemsExpanded, new GUIContent("Items")); if (this.IsItemsExpanded) { EditorGUI.indentLevel++; GUILayout.BeginHorizontal(); GUI.skin.label.normal.textColor = Color.grey; GUILayout.Space(92); GUILayout.Label(itemTypeName); GUILayout.Label("Weight", GUI.skin.label, GUILayout.Width(72)); GUI.skin.label.normal.textColor = Color.black; GUILayout.EndHorizontal(); for (var i = 0; i < setContainer.WeightedSet.Count; ++i) { var rowStyle = new GUIStyle(GUI.skin.label); string itemControlName = string.Format("WeightedLayoutSetItem{0}", i); string weightControlName = string.Format("WeightedLayoutSetItemWeight{0}", i); string currentFocusedControlName = GUI.GetNameOfFocusedControl(); if (currentFocusedControlName == itemControlName || currentFocusedControlName == weightControlName) { rowStyle.normal.background = Texture2D.whiteTexture; } GUILayout.BeginHorizontal(rowStyle); GUILayout.Label(string.Format("Element {0}:", i), GUI.skin.label, GUILayout.Width(72)); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName(itemControlName); var newItem = (TWeightedSetItem)EditorGUILayout.ObjectField(items[i], typeof(TWeightedSetItem), false); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(this.target, string.Format("Change weighted set item {0}", i)); items[i] = newItem; } EditorGUI.BeginChangeCheck(); GUI.SetNextControlName(weightControlName); weights[i] = EditorGUILayout.FloatField(weights[i], GUILayout.Width(60)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(this.target, string.Format("Change weighted set weight {0}", i)); items[i] = newItem; } if (GUILayout.Button("X", GUI.skin.button, GUILayout.Width(20))) { Undo.RecordObject(this.target, string.Format("Remove item from weighted set", i)); setContainer.WeightedSet.Remove(items[i]); } GUILayout.EndHorizontal(); if (GUIEx.WasClicked(GUILayoutUtility.GetLastRect())) { if (Event.current.button == 0) { GUI.FocusControl(itemControlName); this.Repaint(); } if (Event.current.button == 1) { // Now create the menu, add items and show it GenericMenu menu = new GenericMenu(); menu.AddItem( new GUIContent("Delete Element"), false, index => { setContainer.WeightedSet.Remove(items[(int)index]); }, i); menu.AddItem( new GUIContent("Duplicate Element"), false, index => { setContainer.WeightedSet.Insert((int)index + 1, items[(int)index], weights[(int)index]); }, i); Event.current.Use(); menu.ShowAsContext(); } } } GUIEx.PushTooltip("Add new item to the weighted set."); if (GUILayout.Button("+")) { Undo.RecordObject(this.target, "Add new item to the weighted set"); setContainer.WeightedSet.Add(null, 1.0f); } GUIEx.PopTooltip(); EditorGUI.indentLevel--; } GUILayout.EndVertical(); }
private void OnGUI() { Event m_Event = Event.current; float paddingL = _paddingH * Screen.width; float paddingT = _paddingV * Screen.height; Rect screenRect = new Rect(paddingL, paddingT, Screen.width - (paddingL * 2), Screen.height - (paddingT * 2)); Rect itemRect = screenRect; itemRect.width = 100; itemRect.height = 22; GUI.color = _defaultTextColor; DebugOptionsSO debugOptions = GameManager.Instance.debugOptions; //TODO: link this up to game manager debugOptions.showFPS = GUI.Toggle(itemRect, debugOptions.showFPS, debugOptions.showFPS ? "Pause" : "Un-Pause"); itemRect.y += itemRect.height + _debugUISpacing; debugOptions.showFPS = GUI.Toggle(itemRect, debugOptions.showFPS, "Show fps"); itemRect.x += itemRect.width + _debugUISpacing; debugOptions.showLog = GUI.Toggle(itemRect, debugOptions.showLog, "Show log"); itemRect.x = screenRect.x; itemRect.y += itemRect.height + _debugUISpacing; if (debugOptions.showFPS) { float fpsNormal = 1 - ((float)_currentFPS / (float)_targetFPS); GUI.color = _goodBadColorGradient.Evaluate(fpsNormal); GUI.Label(itemRect, _currentFPS.ToString() + " FPS"); itemRect.y += itemRect.height + _debugUISpacing; Color rectColor; int currFPS; Rect rect = new Rect(itemRect.x, itemRect.y, _fpsLogSize.x / _fpsLog.Count, 1); for (int i = 0; i < _fpsLog.Count; i++) { currFPS = _fpsLog[i]; fpsNormal = 1 - ((float)currFPS / (float)_targetFPS); rectColor = _goodBadColorGradient.Evaluate(fpsNormal); rect.y = itemRect.y + (_fpsLogSize.y * fpsNormal) - (rect.height * 0.5f); GUIEx.DrawRect(rect, rectColor); rect.x += rect.width; } itemRect.y += _fpsLogSize.y + _debugUISpacing; } if (debugOptions.showLog) { GUI.color = _defaultTextColor; itemRect.width = 40; GUI.Label(itemRect, "Log:"); itemRect.x += itemRect.width + _debugUISpacing; itemRect.width = 80; itemRect.x += itemRect.width + _debugUISpacing; itemRect.width = 70; if (GUI.Button(itemRect, "Clear log")) { clearLog(); } itemRect.x = screenRect.x; itemRect.y += itemRect.height + _debugUISpacing; //scroll view for the log Rect rect = new Rect(0, 0, 10, itemRect.height); int spacing = 2; Rect windowRect = new Rect(itemRect.x, itemRect.y, 200, itemRect.height + _debugScrollBarHeight); Rect contentRect = new Rect(0, 0, (rect.width + spacing) * _logs.Count, rect.height); _logScrollPosition = GUI.BeginScrollView(windowRect, _logScrollPosition, contentRect); //only draw the ones that are within the visible scroll area... int startIndex = Mathf.Max(Mathf.FloorToInt(_logScrollPosition.x / (rect.width + spacing)), 0); int endIndex = Mathf.Min(startIndex + Mathf.CeilToInt(windowRect.width / (rect.width + spacing)) + 1, _logs.Count); Color backgroundColor = GUI.backgroundColor; int hoverIndex = -1; for (int i = startIndex; i < endIndex; i++) { rect.x = i * (rect.width + spacing); GUIEx.DrawRect(rect, _logs[i].color); GUI.DrawTexture(rect, _logs[i].screenshot, ScaleMode.ScaleToFit, true); if (rect.Contains(m_Event.mousePosition)) { hoverIndex = i; } } // End the scroll view that we began above. GUI.EndScrollView(); itemRect.y += windowRect.height + _debugUISpacing; //recent logs itemRect.width = 200; itemRect.height = 22; float eventLifetime = 2.0f; DebugLogEvent logEvent; for (int j = 0; j < _recentLogs.Count; j++) { logEvent = _recentLogs[j]; GUI.color = logEvent.color; GUI.Label(itemRect, logEvent.time + ": " + logEvent.message); if (Time.time - logEvent.time > eventLifetime) { _recentLogs.RemoveAt(j); j--; } itemRect.y += itemRect.height + _debugUISpacing; } GUI.color = _defaultTextColor; //hovering over the logs if (hoverIndex > -1) { Rect hoverRect = new Rect(m_Event.mousePosition.x, m_Event.mousePosition.y, screenRect.width * 0.75f, screenRect.height * 0.75f); GUIEx.DrawRect(hoverRect, _logs[hoverIndex].color); float areaW = 250; float hoverRectW = hoverRect.width; hoverRect.x += 2; hoverRect.y += 2; hoverRect.height -= 4; hoverRect.width = Mathf.Max(hoverRect.width - (areaW + 4), 0); GUI.DrawTexture(hoverRect, _logs[hoverIndex].screenshot, ScaleMode.ScaleToFit, true); hoverRect.x -= 2; hoverRect.y -= 2; hoverRect.height += 4; hoverRect.x = hoverRect.x + Mathf.Max(hoverRectW - areaW, 0); hoverRect.width = areaW; hoverRect.height = Mathf.Min(500, hoverRect.height); Color bgColor = new Color(0, 0, 0, 0.5f); GUIEx.DrawRect(hoverRect, bgColor); hoverRect.height = 50; GUI.Label(hoverRect, _logs[hoverIndex].time + ": " + _logs[hoverIndex].message); hoverRect.y += hoverRect.height; hoverRect.height = 600; GUI.Label(hoverRect, _logs[hoverIndex].stackTrace); } } }