public void Draw(Rect rect, TypeSelectorPopupContent selector, Action <Type> callback) { var viewRect = rect.SubXMax(16); var groupStyle = GroupStyle.Value; var totalHeight = CalcHeight(viewRect.width); var itemRect = viewRect; viewRect.height = totalHeight; using (var scope = new GUI.ScrollViewScope(rect, scrollPos, viewRect)) { scrollPos = scope.scrollPosition; foreach (var group in Subgroups) { var msg = $"{group.Name}/"; var content = new GUIContent(msg); var height = groupStyle.CalcHeight(content, itemRect.width); itemRect.height = height; var fwdArrow = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector) .GetStyle(GUIStyles.ACRightArrow); if (Event.current.type == EventType.Repaint) { fwdArrow.Draw(itemRect.SetXMin(itemRect.xMax - itemRect.height), false, false, false, false); } if (GUI.Button(itemRect, content, groupStyle)) { selector.Path.Push(group.Name); } itemRect.y += height; } DrawItems(GroupTypes, itemRect, callback); } }
void OnGUI() { GUI.Label(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 125, 400, 100), "This example outputs information to the console. " + "It demonstrates how tasks can be chained together to run in sequence and how waits can be scheduled in a way that does not block the main Unity thread." + "The rotating cube shows the main thread continues to execute." + "The sample uses fibers and is suitable for web."); using (var scrollViewScope = new GUI.ScrollViewScope( new Rect(Screen.width / 2 - 200, Screen.height / 2 - 25, 400, 200), scrollPos, new Rect(Screen.width / 2 - 200, Screen.height / 2 - 25, 380, 400))) { scrollPos = scrollViewScope.scrollPosition; GUI.Label(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 25, 380, 400), lastLogMessage); } if (!running) { var again = GUI.Button(new Rect(Screen.width / 2 - 200, Screen.height / 2 + 200, 100, 40), "Run Again"); if (again) { lastLogMessage = string.Empty; Start(); } } }
public new void OnGUI() { base.OnGUI(); if (show) { float popupWidth = Screen.width / 2f; float popupHeight = Screen.height / 2f; windowRect = new Rect(Screen.width / 2f - popupWidth / 2f, Screen.height / 2f - popupHeight / 2f, popupWidth, popupHeight); Rect viewRect = new Rect(0, 0, popupWidth, popupHeight); GUI.Box(windowRect, "", windowStyle); using (GUI.ScrollViewScope popupScrollScope = new GUI.ScrollViewScope(windowRect, Vector2.zero, viewRect, SCROLLBAR_NOT_VISIBLE, SCROLLBAR_NOT_VISIBLE)) { if (level != null) { // Brief OnGUIBrief(popupWidth, popupHeight); } else if (summary != null) { // Summary OnGUISummary(popupWidth, popupHeight); } } } }
/// <summary> /// ツリーを描画します。foldoutがtrueの時、子階層の描画を再起的に実行します。 /// </summary> /// <param name="rect">描画範囲</param> /// <param name="root">ツリーのルートノード</param> public void DrawTree(Rect rect, GUIFoldoutTree root) { using (var scrollView = new GUI.ScrollViewScope(rect, ScrollPosition, mLastScrollViewContentRect)) { ViewSize = rect.size; Vector2 size = CalcLabelSize(root); // ※おまじない // 描画前に高さをリセットしておく // (あらかじめルートノードの高さを引いておく) mLastScrollViewContentRect.height = -size.y; // 描画範囲は縦スクロールバーの幅を引いた値にしておく mLastScrollViewContentRect.width = ViewSize.x - SCROLL_BAR_WIDTH; // 描画数のリセット mDebugDrawCount = 0; // 階層の描画 DrawItems(root); // ※おまじない // ルートノード分の高さを足しておく mLastScrollViewContentRect.height += size.y; // スクロール座標の更新 ScrollPosition = scrollView.scrollPosition; } }
/// <summary> /// Displays the asset list with Toggles and File icons. /// When entering, exits immediately if it's a Layout or Used event. /// </summary> private void DisplayAssets() { if (Event.current.type == EventType.Layout || Event.current.type == EventType.Used) { return; } if (_path_holder == null) { RefreshContent(); } List <AssetInfo> assets = _path_holder.GetAssetInfos(); _scrollRect.width = _assetsViewArea.width - 16; // This practically disables horizontal scrolling, which is intended behaviour using (var scrollViewScope = new GUI.ScrollViewScope(_assetsViewArea, _scroll_position, _scrollRect)) { _scroll_position = scrollViewScope.scrollPosition; float currY = 0; float viewHeight = 0; foreach (AssetInfo ai in assets) { // Display only level 0 assets (DisplayAssetGroup will be in charge of displaying childs). if (ai.depth_level == 0) { // Display specific asset and all its content. DisplayAssetGroup(ai, ref currY, ref viewHeight); } } _scrollRect.height = viewHeight; } }
private void OnGUIBrief(float popupWidth, float popupHeight) { float y = 0; printTitle(level.name, ref y, popupWidth, titleStyle); float briefHeight = popupHeight - (y + FOOTER_HEIGHT); Rect briefRect = new Rect(0, y, popupWidth, briefHeight); float briefTextHeight = getBriefTextHeight(); Rect briefViewRect = new Rect(0, 0, popupWidth, briefTextHeight); using (GUI.ScrollViewScope scrollScope = new GUI.ScrollViewScope(briefRect, scrollPosition, briefViewRect, SCROLLBAR_NOT_VISIBLE, VERTICAL_SCROLLBAR_VISIBLE)) { scrollPosition = scrollScope.scrollPosition; GUI.Label(new Rect(5f, 0, popupWidth - 5f, briefTextHeight), level.brief.Replace("\\n", Environment.NewLine), textStyle); } // Time of day GUI.Label(new Rect(5f, popupHeight - (FOOTER_HEIGHT - 5f), popupWidth / 3f, FOOTER_HEIGHT - 10f), "Time: " + level.timeOfDay, subtitleStyle); // Previous stars int stars = PlayerPrefsData.GetLevelStars(level.id); float starsY = popupHeight - starFilled.height; drawStars(stars, ref starsY, popupWidth, -5f); // Random seed GUI.Label(new Rect(popupWidth * 2f / 3f - 5f, popupHeight - (FOOTER_HEIGHT - 5f), popupWidth / 3f, FOOTER_HEIGHT - 10f), level.randomSeedStr, subtitleStyleRight); }
//------------------------------------------------------ // texture list //------------------------------------------------------ void DrawTextureList() { m_scrollRect = GUILayoutUtility.GetRect(GUIContent.none, "ScrollView", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); m_displayed = GetTargetTextures(); var viewRectWidth = m_scrollRect.width - GUI.skin.verticalScrollbar.fixedWidth; m_columnNum = Mathf.FloorToInt((viewRectWidth - kPaddingMin) / (m_itemSize + kPaddingMin)); m_rawNum = m_displayed.Length / m_columnNum + (m_displayed.Length % m_columnNum == 0 ? 0 : 1); m_padding.x = (viewRectWidth - m_itemSize * m_columnNum) / (m_columnNum + 1); m_padding.y = kPaddingMin; var viewRect = new Rect(0, 0, viewRectWidth, m_rawNum * (m_itemSize + m_padding.y) + m_padding.y); using (var scroll = new GUI.ScrollViewScope(m_scrollRect, m_scrollPosition, viewRect)) { var displayRect = new Rect(0, m_scrollPosition.y, viewRect.width, viewRect.height); var y = kPaddingMin; for (int i = 0; i < m_rawNum; ++i, y += m_itemSize + kPaddingMin) { DrawColumn(ref displayRect, y, m_displayed, i * m_columnNum, m_columnNum, m_padding.x); } m_scrollPosition = scroll.scrollPosition; } var ev = Event.current; switch (ev.type) { case EventType.KeyDown: switch (ev.keyCode) { case KeyCode.RightArrow: MoveSelect(+1); ev.Use(); break; case KeyCode.LeftArrow: MoveSelect(-1); ev.Use(); break; case KeyCode.DownArrow: MoveSelect(m_columnNum); ev.Use(); break; case KeyCode.UpArrow: MoveSelect(-m_columnNum); ev.Use(); break; } break; } }
//------------------------------------------------------ // gui //------------------------------------------------------ void DrawList() { EditorGUI.BeginChangeCheck(); m_tab = GUILayout.Toolbar(m_tab, kTab); if (EditorGUI.EndChangeCheck() || m_current == null) { m_current = GetList(); m_selectedIndex = -1; Selection.activeObject = null; } GUILayout.Space(-5); GUILayout.Box(GUIContent.none, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); m_scrollRect = GUILayoutUtility.GetLastRect(); // この後描画されるbackgrounで枠線が消えてしまうので削る m_scrollRect.x += 1f; m_scrollRect.y += 1f; m_scrollRect.width -= 2f; m_scrollRect.height -= 2f; DrawBackground(); var viewRect = new Rect(0, 0, m_scrollRect.width, m_current.Count * kItemHeight); using (var scroll = new GUI.ScrollViewScope(m_scrollRect, m_scrollPosition, viewRect)) { var itemPosition = new Rect(0, 0, viewRect.width, kItemHeight); for (int i = 0; i < m_current.Count; ++i) { if (DrawFolder(itemPosition, m_current[i], m_selectedIndex == i)) { if (m_selectedIndex >= i) { --m_selectedIndex; } m_current.RemoveAt(i--); } itemPosition.y += itemPosition.height; } // アイテム描画した後に更新しないとDrawBackground()とズレる m_scrollPosition = scroll.scrollPosition; } GUILayout.Space(-5); EditorGUILayout.HelpBox("フォルダをドロップで追加", MessageType.Info); }
//------------------------------------------------------------------------------ public void Draw() { GUI.skin = mSkin; GUI.enabled = true; // content rect var rectContainer = GetEditorRect(); // clear background var rectFullScreen = new Rect(0.0f, rectContainer.yMin - 4.0f, Screen.width, Screen.height); GUI.DrawTexture(rectFullScreen, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, false); // scroll window var padLeft = 8.0f; var padRight = 4.0f; var padHoriz = padLeft + padRight; var scrollWidth = GUI.skin.verticalScrollbar.fixedWidth; var minWidth = rectContainer.width - scrollWidth - padHoriz; var maxHeight = ContentHeight(minWidth); var hasScrollbar = maxHeight >= rectContainer.height; var contentWidth = hasScrollbar ? minWidth : rectContainer.width - padHoriz; var rectContent = new Rect(-padLeft, 0.0f, contentWidth, maxHeight); // draw content using (var scroll = new GUI.ScrollViewScope(rectContainer, mScrollPos, rectContent)) { mScrollPos = scroll.scrollPosition; if (mRaw) { rectContent.width = minWidth - GUI.skin.button.fixedWidth; DrawRaw(rectContent); } else { DrawMarkdown(rectContent); } } DrawToolbar(rectContainer, hasScrollbar ? scrollWidth + padRight : padRight); }
public void Update(Rect windowPos) { if (trackDrawers.Count == 0) { GUI.Label(new Rect(0, 0, 100, 20), "No Tracks to draw"); } Rect view = new Rect(Vector2.zero, windowPos.size); Rect totalSize = new Rect(Vector2.zero, new Vector2(TotalWidth, TotalHeight) + Border * 2); using (var scrollScope = new GUI.ScrollViewScope(view, scroll, totalSize)) { scroll = scrollScope.scrollPosition; DrawTracks(windowPos); } }
public void DrawRight() { SetDuration(this.duration); scrollRect = this.resizableRects.paddingRects[1]; _viewRect.Set(0, 0, duration * widthPerSecond, scrollRect.height - 16); using (var s = new GUI.ScrollViewScope(scrollRect, _scrollPosition, _viewRect, true, false)) { _scrollPosition = s.scrollPosition; DrawTimelineTrack(); onDrawTracksRightSideCallback?.Invoke(); DrawPlayTimeLine(); HandleRightMouseInput(); EditorMouseInput.DrawSelectBox(); } HandleScrollWheelEvent(); }
//------------------------------------------------------ // アイテム //------------------------------------------------------ void DrawItems(Rect position, Column[] columns) { var viewRect = new Rect(0, 0, GetContentWidth(columns), m_itemList.Count * kItemHeight); using (var scroll = new GUI.ScrollViewScope(position, m_scrollPosition, viewRect)) { var ev = Event.current; var min = Mathf.FloorToInt(m_scrollPosition.y / kItemHeight); var max = min + Mathf.CeilToInt(position.height / kItemHeight); // 背景の縞々 if (ev.type == EventType.Repaint) { var prev = GUI.color; var gray = new Color(prev.r * 0.95f, prev.g * 0.95f, prev.b * 0.95f); for (int i = min; i < max; ++i) { var area = new Rect(m_scrollPosition.x, i * kItemHeight, position.width, kItemHeight); GUI.color = i % 2 == 1 ? prev : gray; m_backgroundStyle.Draw(area, GUIContent.none, 0); } GUI.color = prev; } // 本体 // 未表示部分も回さないとControlIDズレるんだよなぁ… for (int i = min; i < Mathf.Min(m_itemList.Count, max); ++i) { var itemPosition = new Rect(0, i * kItemHeight, position.width, kItemHeight); DrawItem(itemPosition, columns, m_itemList[i], i); } switch (ev.type) { case EventType.MouseDown: SelectItem(ev); break; } m_scrollPosition = scroll.scrollPosition; } }
private void drawOpenedList() { GUIStyle listStyle = GUI.skin.window; GUI.Box(openedListRect, "", listStyle); using (var scrollViewScrope = new GUI.ScrollViewScope(openedListRect, openedListScrollPosition, openedListViewRect)) { openedListScrollPosition = scrollViewScrope.scrollPosition; float itemX = 0; float itemY = 0; float itemWidth = openedListViewRect.width; int currentIndex = 0; this.openedListMaxItemWidth = 0; foreach (T item in items) { GUIContent itemContent = new GUIContent(stringizer(item)); GUIStyle itemStyle = new GUIStyle(); itemStyle.normal.textColor = new Color(200, 200, 200); if (currentIndex == selectedItemIndex) { itemStyle.hover.textColor = Color.black; itemStyle.normal.background = hoverBackgroundTexture; } itemStyle.hover.background = hoverBackgroundTexture; itemStyle.onHover.background = hoverBackgroundTexture; itemStyle.hover.textColor = Color.black; itemStyle.onHover.textColor = Color.black; itemStyle.padding = new RectOffset(4, 4, 4, 4); Vector2 itemSize = itemStyle.CalcSize(itemContent); float itemHeight = itemStyle.CalcSize(itemContent).y; this.openedListItemHeight = itemHeight; this.openedListMaxItemWidth = Math.Max(itemSize.x, openedListMaxItemWidth); if (GUI.Button(new Rect(itemX, itemY, itemWidth, itemHeight), itemContent, itemStyle)) { this.selectedItemIndex = currentIndex; this.opened = false; } itemY += itemHeight; ++currentIndex; } } }
public new void OnGUI() { base.OnGUI(); if (show) { float informationWindowWidth = Screen.width / 5f; float contentHeight = calculateContentHeight(informationWindowWidth); // TODO - calculate precise information height windowRect = new Rect(0, 0, informationWindowWidth, Screen.height); Rect viewRect = new Rect(0, 0, Screen.width / 5f + 10, contentHeight); GUI.Box(windowRect, "", windowStyle); using (GUI.ScrollViewScope scrollScope = new GUI.ScrollViewScope(windowRect, scrollPosition, viewRect, SCROLLBAR_NOT_VISIBLE, VERTICAL_SCROLLBAR_VISIBLE)) { scrollPosition = scrollScope.scrollPosition; float y = 0; foreach (KeyValuePair <string, object> infoRow in information) { printKeyValuePair(infoRow, ref y, informationWindowWidth); } if (GUI.Button(new Rect(informationWindowWidth - 35f, 5f, 20f, 20f), "X")) { hideInformation(); } // TODO - If we should keep this, make some text/image if (informationObject != null && informationObject.GetType() == typeof(InformationVehicle) && !informationObject.GetComponent <Vehicle>().destroying) { if (GUI.Button(new Rect(informationWindowWidth - 35f, 35f, 20f, 20f), "")) { switchCamera(); } } if (follow && informationObject != null && informationObject.gameObject != null) { scrollToInformationBase(informationObject); } } } }
//------------------------------------------------------ // stylelist //------------------------------------------------------ void DrawStylelist(Rect position) { var viewRect = new Rect(0, 0, position.width - GUI.skin.verticalScrollbar.fixedWidth, EditorGUIUtility.singleLineHeight * m_styles.Length); using (var scroll = new GUI.ScrollViewScope(position, m_scrollPosition, viewRect, false, true)) { for (int i = 0; i < m_styles.Length; ++i) { GUIStyleField(new Rect(0, EditorGUIUtility.singleLineHeight * i, viewRect.width, EditorGUIUtility.singleLineHeight), m_styles[i]); } m_scrollPosition = scroll.scrollPosition; } var ev = Event.current; switch (ev.type) { case EventType.KeyDown: switch (ev.keyCode) { case KeyCode.UpArrow: if (PrevStyle()) { ev.Use(); } break; case KeyCode.DownArrow: if (NextStyle(position.height)) { ev.Use(); } break; } break; } }
private void OnGUISummary(float popupWidth, float popupHeight) { float y = 0; printTitle(summary.name, ref y, popupWidth, titleStyle); float summaryHeight = popupHeight - (y + FOOTER_HEIGHT); Rect summaryRect = new Rect(0, y, popupWidth, summaryHeight); float summaryContentHeight = getSummaryContentHeight(popupWidth); Rect summaryViewRect = new Rect(0, 0, popupWidth, summaryContentHeight); using (GUI.ScrollViewScope scrollScope = new GUI.ScrollViewScope(summaryRect, scrollPosition, summaryViewRect, SCROLLBAR_NOT_VISIBLE, VERTICAL_SCROLLBAR_VISIBLE)) { scrollPosition = scrollScope.scrollPosition; drawSummaryInnerContents(popupWidth); } // Footer - Main Menu, Retry(, Next Mission) float buttonWidth = 150f; float buttonHeight = FOOTER_HEIGHT - 10f; float middleX = popupWidth / 2f; if (GUI.Button(new Rect(middleX - middleX / 2f - buttonWidth / 2f, popupHeight - FOOTER_HEIGHT / 2f - buttonHeight / 2f, buttonWidth, buttonHeight), "Main Menu")) { Game.instance.exitLevel(); hide(); } if (GUI.Button(new Rect(middleX - buttonWidth / 2f, popupHeight - FOOTER_HEIGHT / 2f - buttonHeight / 2f, buttonWidth, buttonHeight), "Retry")) { Game.instance.restartLevel(); hide(); } if (GUI.Button(new Rect(middleX + middleX / 2f - buttonWidth / 2f, popupHeight - FOOTER_HEIGHT / 2f - buttonHeight / 2f, buttonWidth, buttonHeight), "Next Mission")) { // TODO - Play next mission hide(); } }
//------------------------------------------------------ // platform list //------------------------------------------------------ void DrawPlatformList() { GUILayout.Box(GUIContent.none, GUILayout.Width(250f), GUILayout.ExpandHeight(true)); var position = GUILayoutUtility.GetLastRect(); position.x += 1f; position.y += 1f; position.width -= 1f; position.height -= 1f; var viewRect = new Rect(0, 0, position.width - 16f, kTargetItemHeight * m_platforms.Length); using (var scroll = new GUI.ScrollViewScope(position, m_targetScrollPosition, viewRect)) { for (int i = 0; i < m_platforms.Length; ++i) { var itemRect = new Rect(0, kTargetItemHeight * i, viewRect.width, kTargetItemHeight); PlatformField(itemRect, m_platforms[i], i % 2 == 0 ? m_entryBackEvenStyle : m_entryBackOddStyle); } m_targetScrollPosition = scroll.scrollPosition; } }
private void DrawTestLoggers() { this.SelectModuleOnNGConsole(this.MainModuleType); if (this.workingModule == null) { this.DisplayBrokenTutorialHelper("Loggers"); return; } GUI.Label(r, "Press buttons below to test the loggers provided by the class NGDebug."); r.y += r.height; GUI.Label(r, "Copy code to test it yourself."); r.y += r.height; Rect pos = new Rect(0F, r.y, Screen.width, Screen.height - r.y); Rect viewRect = new Rect(0F, 0F, 0F, r.height * 26 + TestLoggers.Spacing * 7); using (var scroll = new GUI.ScrollViewScope(pos, this.loggersScrollPosition, viewRect)) { this.loggersScrollPosition = scroll.scrollPosition; r.y = 0F; if (GUI.Button(r, "NGTools.NGDebug.Log(GetComponents(typeof(Component)))") == true) { NGDebug.Log(this.GetComponents(typeof(Component))); } r.y += r.height; GUI.TextField(r, "NGDebug.Log(GetComponents(typeof(Component)));", this.centeredTextField); r.y += r.height + TestLoggers.Spacing; if (GUI.Button(r, "NGDebug.Log(Physics.OverlapSphere(Vector3.zero, 1))") == true) { NGDebug.Log(Physics.OverlapSphere(Vector3.zero, 1F)); } r.y += r.height; GUI.TextField(r, "NGDebug.Log(Physics.OverlapSphere(Vector3.zero, 1));", this.centeredTextField); r.y += r.height + TestLoggers.Spacing; if (GUI.Button(r, "NGDebug.Log(Physics.RaycastAll(Vector3.zero, Vector3.up, 3))") == true) { NGDebug.Log(Physics.RaycastAll(Vector3.zero, Vector3.up, 3F)); } r.y += r.height; GUI.TextField(r, "NGDebug.Log(Physics.RaycastAll(Vector3.zero, Vector3.up, 3));", this.centeredTextField); r.y += r.height + TestLoggers.Spacing; if (GUI.Button(r, "NGDebug.Log(this, gameObject, transform)") == true) { NGDebug.Log(this, this.gameObject, this.transform); } r.y += r.height; GUI.TextField(r, "NGDebug.Log(this, gameObject, transform);", this.centeredTextField); r.y += r.height + TestLoggers.Spacing; if (GUI.Button(r, "NGDebug.Log(NULL)") == true) { Object o = null; NGDebug.Log(o); } r.y += r.height; GUI.TextField(r, "NGDebug.Log(NULL);", this.centeredTextField); r.y += r.height + TestLoggers.Spacing; if (GUI.Button(r, "NGDebug.Log(NULL, this, NULL)") == true) { NGDebug.Log(null, this, null); } r.y += r.height; GUI.TextField(r, "NGDebug.Log(NULL, this, NULL);", this.centeredTextField); r.y += r.height + TestLoggers.Spacing; if (GUI.Button(r, "NGDebug.LogCollection(new List<GameObject>(Resources.FindObjectsOfTypeAll<GameObject>()))") == true) { NGDebug.LogCollection(new List <GameObject>(Resources.FindObjectsOfTypeAll <GameObject>())); } r.y += r.height; GUI.TextField(r, "NGDebug.LogCollection(new List<GameObject>(Resources.FindObjectsOfTypeAll<GameObject>()));", this.centeredTextField); r.y += r.height; GUI.Label(r, "Use LogCollection with List, Stack or any array or collection that inherit from IEnumerable."); r.y += r.height; if (GUI.Button(r, "NGDebug.LogHierarchy(this)") == true) { NGDebug.LogHierarchy(this); } r.y += r.height; GUI.TextField(r, "NGDebug.LogHierarchy(this);", this.centeredTextField); r.y += r.height; GUI.Label(r, "Use LogHierarchy to display the upward hierarchy of any Game Object, Component or RaycastHit."); r.y += r.height; if (GUI.Button(r, "NGDebug.Snapshot(this)") == true) { NGDebug.Snapshot(this); } r.y += r.height; GUI.TextField(r, "NGDebug.Snapshot(this);", this.centeredTextField); r.y += r.height; GUI.Label(r, "Use Snapshot to output public fields of any object at the time you call it."); r.y += r.height; GUI.Label(r, "Tips:"); r.y += r.height; GUI.Label(r, "Pass your mouse over the images in NG Console to display the related Game Object's name."); r.y += r.height; GUI.Label(r, "Click on an image to ping the Object."); r.y += r.height; GUI.Label(r, "Double click on an image to select the Object."); r.y += r.height; GUI.Label(r, "Press Shift and click on an image to select the Object."); r.y += r.height; } }
void OnGUI() { Rect windowRect = selfW.position; Rect titleRect = new Rect(0, 0, windowRect.width, windowRect.height * 0.13f); Rect contentRect = new Rect(0, windowRect.height * 0.13f, windowRect.width, windowRect.height * 0.87f); //Draw window background. EditorGUI.DrawRect(titleRect, MaterialDesignColorset.lightBlue400); EditorGUI.DrawRect(contentRect, MaterialDesignColorset.grey200); labelStyle.fontSize = 40; labelStyle.normal.textColor = MaterialDesignColorset.grey100; Rect titleLabelRect = titleRect; titleLabelRect.x = 15; titleLabelRect.y = (windowRect.height * 0.13f) / 2f - 20; if (selectedID >= 0) { EditorGUI.LabelField(titleLabelRect, IconsData.iconsName[selectedID], labelStyle); } else { EditorGUI.LabelField(titleLabelRect, "Pick your icon here :", labelStyle); } iconStyle.fontSize = iconSize; Rect iconRect = new Rect(10, 10, iconSize, iconSize); int lines = IconsData.iconsUnicode.Length / itemPerLine; Rect scrollArea = new Rect(0, 0, 10, lines * (iconSize + spacing)); using (var scrollViewScope = new GUI.ScrollViewScope(contentRect, scrollPosition, scrollArea)) { scrollPosition = scrollViewScope.scrollPosition; for (int l = 0; l < lines; l++) { int curLine = (int)((float)lines * (scrollPosition.y / scrollArea.height)); iconRect.x = spacing; for (int r = 0; r < itemPerLine; r++) { if (curLine - l < -5 || curLine - l > 1) { continue; } int index2Pick = l * itemPerLine + r; string decoded = DecodeUnicodeString(@"\u" + IconsData.iconsUnicode[index2Pick]); if (decoded == selected) { selectedID = index2Pick; EditorGUI.DrawRect(iconRect, MaterialDesignColorset.grey400); } if (GUI.Button(iconRect, "", buttonStyle)) { selected = decoded; onSelectionChanged(selected); } EditorGUI.LabelField(iconRect, decoded, iconStyle); Rect textRect = iconRect; textRect.yMax += 13; string name2Display = IconsData.iconsName[index2Pick]; if (name2Display.Length > 14) { name2Display = name2Display.Substring(0, 14); } EditorGUI.LabelField(textRect, name2Display, iconTextStyle); iconRect.x += iconSize + spacing; } iconRect.y += iconSize + spacing; } } }
protected override void DrawContent(ref Rect contentRect) { // TOOLBAR DrawToolbar(ref contentRect); _lastContentRect = new Rect(contentRect); _consoleBuffer = OSCWindowConsole.GetConsoleBuffer(ShowTransmitted, ShowReceived, _filterDrawer.FilterValue); if (TrackLast) { SelectedMessage = _consoleBuffer.Length > 0 ? _consoleBuffer[0] : null; } var viewRect = new Rect(contentRect); viewRect.height = _consoleBuffer.Length * _lineHeight; if (viewRect.height > contentRect.height) { viewRect.width -= 15f; } var itemRect = new Rect(0, viewRect.y, viewRect.width, _lineHeight); using (var scroll = new GUI.ScrollViewScope(contentRect, _scrollPosition, viewRect)) { var drawed = false; for (var index = 0; index < _consoleBuffer.Length; index++) { if (itemRect.y + itemRect.height > _scrollPosition.y && itemRect.y < _scrollPosition.y + contentRect.height + itemRect.height) { drawed = true; var consoleMessage = _consoleBuffer[index]; var selected = SelectedMessage == consoleMessage; var color = GUI.color; DrawItem(ref itemRect, index, consoleMessage, selected); GUI.color = color; if (Event.current.type == EventType.MouseDown && itemRect.Contains(Event.current.mousePosition)) { GUIUtility.keyboardControl = 0; if (Event.current.button == 0) { TrackLast = false; if (SelectedMessage != consoleMessage) { SelectedMessage = consoleMessage; Window.Repaint(); } Event.current.Use(); } else if (Event.current.button == 1) { ShowMessageGenericMenu(consoleMessage); Event.current.Use(); } } } else if (drawed) { break; } itemRect.y += itemRect.height; } _scrollPosition = scroll.scrollPosition; } }
public override void OnGUI(Rect rect) { var pStyle = PathStyle.Value; var path = string.Join("/", Path.Reverse().ToArray()); var pathContent = new GUIContent($"/{path}"); var pathHeight = pStyle.CalcHeight(pathContent, rect.width) + 5; GUI.Box(rect.SetHeight(SearchHeight + pathHeight), GUIContent.none); var searchRect = rect; searchRect.height = SearchHeight; searchString = searchField.OnGUI(searchRect.Padding(5), searchString); var labelRect = rect; labelRect.yMin = searchRect.yMax; labelRect.yMax = labelRect.yMin + pathHeight; var groupRect = rect; groupRect.yMin = labelRect.yMax; if (!searchString.IsEmpty()) { // Draw Search var viewRect = groupRect.SubXMax(16); var foundTypes = rootGroup.SearchTypes(searchString); viewRect.height = foundTypes.Sum(type => TypeSelectorGroup.ItemStyle.Value.CalcHeight( new GUIContent(type.GetLegibleName(), type.FindUnityIcon()), viewRect.width)); using (var scope = new GUI.ScrollViewScope(groupRect, searchScroll, viewRect)) { searchScroll = scope.scrollPosition; TypeSelectorGroup.DrawItems(foundTypes, viewRect, onTypeSelected); } } else { // Draw Tree searchScroll = Vector2.zero; var group = rootGroup.FindSubGroup(path); EditorGUI.LabelField(labelRect, pathContent, pStyle); if (!IsAtRoot) { var backArrow = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector) .GetStyle(GUIStyles.ACLeftArrow); var returnRect = labelRect.SetXMax(labelRect.x + labelRect.height); if (GUI.Button(returnRect, GUIContent.none, backArrow)) { Path.Pop(); } //backArrow.Draw(returnRect, false, false, false, false); } if (group.IsEmpty()) { EditorGUI.LabelField(groupRect, noElementsFoundMessage, EditorStyles.boldLabel); } else { group.Draw(groupRect, this, onTypeSelected); } } editorWindow.Repaint(); }
void DrawChildren(Rect rect, GUIScrollTree root) { GUIStyle rightArrow = new GUIStyle("AC RightArrow"); GUIStyle leftArrow = new GUIStyle("AC LeftArrow"); GUIStyle background = new GUIStyle("grey_border"); Rect scrollViewRect = new Rect(0, 0, rect.width - 20, root.Children.Count * 16); Rect viewRect = rect; viewRect.y += 20; viewRect.yMax = rect.yMax; bool mouseRepaint = false; switch (Event.current.type) { case EventType.Repaint: { mouseRepaint = true; } break; } if (!root.isRoot) { if (GUI.Button(new Rect(rect.x, rect.y, rect.width, 20), root.Name, EditorStyles.miniButtonMid)) { Back(root.Parent.Depth); } GUI.Box(new Rect(rect.x, rect.y + 4, 16, 12), GUIContent.none, leftArrow); } else { GUI.Box(new Rect(rect.x, rect.y, rect.width, 20), root.Name, EditorStyles.miniButtonMid); } using (var scrollView = new GUI.ScrollViewScope(viewRect, root.GenericValue.mVerticalScrollPos, scrollViewRect)) { Rect nodeRect = new Rect(Vector2.zero, new Vector2(rect.width - GUI.skin.verticalScrollbar.fixedWidth, 16)); for (int i = 0; i < root.Children.Count; ++i) { if (mouseRepaint) { if (nodeRect.Contains(Event.current.mousePosition)) { Rect cu = nodeRect; cu.width = rect.width; Kiz_GUIUtility.DrawSelectRect(cu); mouseRepaint = false; } } var child = root.Children[i]; Rect nodeRect2 = new RectOffset(12, -12, 0, 0).Remove(nodeRect); if (child.isLeaf) { if (GUI.Button(nodeRect2, child.Name, EditorStyles.label)) { onSelect.Invoke(child); } } else { if (GUI.Button(nodeRect2, child.Name, EditorStyles.label)) { SetSelectedIndex(root.Depth, i, child.Depth); } GUI.Label(new Rect(nodeRect2.xMax - 16, nodeRect.y, 16, 16), GUIContent.none, rightArrow); } nodeRect.y += nodeRect.height; } root.GenericValue.mVerticalScrollPos = scrollView.scrollPosition; } }
public void DrawCells(Rect rect, GUICell cells) { GUI.Box(rect, GUIContent.none); Rect scrollViewContentRect = new Rect(0, 0, rect.width - 20, cells.RowCount * 16); Utility.ListAutoResize(mColumnWidth, cells.ColumnCount, DefatultWidth); Rect clipRect = new Rect(rect.x, rect.y, rect.width, 20); Rect columnRect = clipRect; columnRect.x = -ScrollPosition.x; columnRect.y = 0; columnRect.width = TotalColumnWidth; GUI.Button(new Rect(columnRect.y - 20, 0, 120, 20), mDebugDrawCount.ToString(), EditorStyles.miniButtonMid); mDebugDrawCount = 0; using (new GUI.ClipScope(clipRect)) { Rect hitRect = new Rect(0, 0, rect.width, clipRect.height); // カラム名の描画 for (int i = 0; i < cells.ColumnCount; ++i) { columnRect.width = mColumnWidth[i]; if (hitRect.Overlaps(columnRect)) { ++mDebugDrawCount; GUI.Button(columnRect, cells.ColumnNames[i], EditorStyles.miniButtonMid); } columnRect.x += mColumnWidth[i]; } } scrollViewContentRect.width = TotalColumnWidth - 40; Rect viewRect = new RectOffset(0, 0, (int)columnRect.height, 0).Remove(rect); ViewSize = viewRect.size - new Vector2(20, 20); // セルの描画 using (var scrollView = new GUI.ScrollViewScope(viewRect, ScrollPosition, scrollViewContentRect)) { DrawItems(cells); // スクロール座標の更新 ScrollPosition = scrollView.scrollPosition; } clipRect = new Rect(rect.x, rect.y, rect.width - 20, viewRect.height + 1); columnRect.x = -ScrollPosition.x; columnRect.y = 0; columnRect.width = TotalColumnWidth; using (new GUI.ClipScope(clipRect)) { Rect hitRect = new Rect(0, 0, rect.width, clipRect.height); Handles.BeginGUI(); Handles.color = Color.gray; for (int i = 0; i < cells.ColumnCount; ++i) { columnRect.width = mColumnWidth[i]; if (hitRect.Contains(new Vector2(columnRect.x + 0.5f, 1))) { ++mDebugDrawCount; Handles.DrawLine(new Vector2(columnRect.x + 0.5f, 1), new Vector2(columnRect.x + 0.5f, viewRect.height + 0.5f)); } columnRect.x += mColumnWidth[i]; } Handles.color = Color.white; Handles.EndGUI(); } }
private void DrawAutoSuggestionOverlay(Rect textFieldPosition, bool isFirstRenderPass) { // If styles haven't been computed yet, do so now CreateStylesIfNeeded(); var suggestionButtonHeight = EditorGUIUtility.singleLineHeight; var suggestionButtonHeightWithSpacing = suggestionButtonHeight + EditorGUIUtility.standardVerticalSpacing; var errorHeight = 2.0f * EditorGUIUtility.singleLineHeight; var errorHeightWithSpacing = errorHeight + EditorGUIUtility.standardVerticalSpacing; int numberToDisplay = Math.Min(_cachedSuggestions.Count, _options.MaxSuggestionsToDisplay); float height = (_cachedSuggestions.Any()) ? EditorGUIUtility.standardVerticalSpacing : 0.0f; // Determine height based on first N items. for (int i = 0; i < numberToDisplay; i++) { if (_cachedSuggestions[i].IsErrorMessage) { height += errorHeightWithSpacing; } else { height += suggestionButtonHeightWithSpacing; } } Rect currentPosition = new Rect( x: textFieldPosition.x + EditorGUIUtility.labelWidth, y: textFieldPosition.y - EditorGUIUtility.standardVerticalSpacing, width: Math.Max(0, textFieldPosition.width - EditorGUIUtility.labelWidth), height: height); if (Event.current.isScrollWheel && currentPosition.Contains(Event.current.mousePosition)) { if (Event.current.delta.y > 0) { _scrolledIndex += _scrollDistance; } else { _scrolledIndex -= _scrollDistance; } ClampScrolledIndex(false); Event.current.Use(); } if (Event.current.type == EventType.Repaint) { _heightAnimator.Target = currentPosition.height; } _drawSpaceClaimer.ClaimDrawSpace(isFirstRenderPass, _heightAnimator.Current); currentPosition.height = _heightAnimator.Current; if (currentPosition.height > _scrollbarSize.y * 2 && _cachedSuggestions.Count > _options.MaxSuggestionsToDisplay) { var barPosition = new Rect( currentPosition.xMax - _scrollbarSize.x, currentPosition.y, _scrollbarSize.x, currentPosition.height); EditorGUIUtility.AddCursorRect(barPosition, MouseCursor.Arrow); float scrollMin = 0.0f; float scrollMax = _cachedSuggestions.Count; _scrolledIndex = (int)GUI.VerticalScrollbar(barPosition, _scrolledIndex, _options.MaxSuggestionsToDisplay, scrollMin, scrollMax, GUI.skin.verticalScrollbar); ClampScrolledIndex(false); currentPosition.width -= _scrollbarSize.x; } using (var scrollScope = new GUI.ScrollViewScope(currentPosition, Vector2.zero, currentPosition, false, false, GUIStyle.none, GUIStyle.none)) { GUI.Box(currentPosition, string.Empty, _dropDownBoxStyle); scrollScope.handleScrollWheel = true; EditorGUIUtility.AddCursorRect(currentPosition, MouseCursor.Arrow); // Draw each of the suggestions currentPosition.y += EditorGUIUtility.standardVerticalSpacing; currentPosition.height = suggestionButtonHeight; int maxRemainingSuggestionsToDisplay = _options.MaxSuggestionsToDisplay; for (int i = _scrolledIndex; i < _cachedSuggestions.Count; i++) { var suggestion = _cachedSuggestions[i]; var style = _itemStyle; if (i == _selectedIndex) { style = _selectedItemStyle; } if (suggestion.IsErrorMessage) { currentPosition.height = errorHeight; EditorGUI.HelpBox(currentPosition, suggestion.DisplayText, MessageType.Error); currentPosition.y += errorHeightWithSpacing; } else { currentPosition.height = suggestionButtonHeight; if (GUI.Button(currentPosition, suggestion.RichDisplayText, style)) { _selectedIndex = i; SetCurrentSelectedIndexToTextField(); } currentPosition.y += suggestionButtonHeightWithSpacing; } if (--maxRemainingSuggestionsToDisplay == 0) { break; } } } }
void OnGUI() { Rect windowRect = selfW.position; Rect titleRect = new Rect(0, 0, windowRect.width, windowRect.height * 0.13f); Rect contentRect = new Rect(0, windowRect.height * 0.13f, windowRect.width, windowRect.height * 0.87f); //Draw window background. EditorGUI.DrawRect(titleRect, selected); EditorGUI.DrawRect(contentRect, MaterialDesignColorset.grey200); labelStyle.fontSize = 40; labelStyle.normal.textColor = MaterialDesignColorset.grey100; Rect titleLabelRect = titleRect; titleLabelRect.x = 15; titleLabelRect.y = (windowRect.height * 0.13f) / 2f - 20; if (!MaterialDesignColorset.IsDarkColor(selected)) { labelStyle.normal.textColor = MaterialDesignColorset.grey700; } EditorGUI.LabelField(titleLabelRect, "Colors :", labelStyle); Rect iconRect = new Rect(10, 10, 330, iconSize); Rect largeIconRect = new Rect(0, 0, 500, iconSize + 20); int lines = MaterialDesignColorset.colorSets.Count / itemPerLine; Rect scrollArea = new Rect(0, 0, 10, lines * (iconSize + spacing)); using (var scrollViewScope = new GUI.ScrollViewScope(contentRect, scrollPosition, scrollArea)) { scrollPosition = scrollViewScope.scrollPosition; for (int l = 0; l < lines; l++) { int curLine = (int)((float)lines * (scrollPosition.y / scrollArea.height)); iconRect.x = spacing; for (int r = 0; r < itemPerLine; r++) { if (curLine - l < -8 || curLine - l > 1) { continue; } int index2Pick = l * itemPerLine + r; Color decoded = MaterialDesignColorset.colorSets[index2Pick]; if (!MaterialDesignColorset.IsDarkColor(decoded)) { EditorGUI.DrawRect(largeIconRect, MaterialDesignColorset.grey500); } EditorGUI.DrawRect(iconRect, decoded); if (decoded == selected) { selectedID = index2Pick; } if (GUI.Button(iconRect, "", buttonStyle)) { selected = decoded; onSelectionChanged(selected); } Rect textRect = iconRect; textRect.yMax += 13; iconRect.x += iconSize + spacing; } iconRect.y += iconSize + spacing; largeIconRect.y += iconSize + spacing; } } }
public override void Action() { base.Action(); //moving if (movable) { if (pointed && Input.GetMouseButtonDown(0)) { dragging = true; sizeX = absolute.right - absolute.left; sizeY = absolute.bottom - absolute.top; dragOffset = new Vector2( offset.left - Input.mousePosition.x, offset.top - InstantGui.Invert(Input.mousePosition.y)); //negative, in common } if (Input.GetMouseButtonUp(0)) { dragging = false; } if (dragging) { offset.left = (int)(Input.mousePosition.x + dragOffset.x); offset.top = (int)(InstantGui.Invert(Input.mousePosition.y) + dragOffset.y); absolute.GetAbsolute(parentpos, relative, offset); //limiting window movement if (scape == InstantGuiWindowScape.screen) { absolute.left = Mathf.Max(absolute.left, 0); absolute.top = Mathf.Max(absolute.top, 0); if (absolute.left > Screen.width - sizeX) { absolute.left = Screen.width - sizeX; } if (absolute.top > Screen.height - sizeY) { absolute.top = Screen.height - sizeY; } } if (scape == InstantGuiWindowScape.parent) { absolute.left = Mathf.Max(absolute.left, parentpos.left); absolute.top = Mathf.Max(absolute.top, parentpos.top); if (absolute.left > parentpos.right - sizeX) { absolute.left = parentpos.right - sizeX; } if (absolute.top > parentpos.bottom - sizeY) { absolute.top = parentpos.bottom - sizeY; } } offset.GetOffset(parentpos, relative, new InstantGuiElementPos(absolute.left, absolute.left + sizeX, absolute.top, absolute.top + sizeY)); } } //closing if (closeButton != null && closeButton.activated) { gameObject.SetActive(false); } //expanding if (expandButton != null) { if (expandButton.activated && expandButton.check) { nonMaximizedRelative = new InstantGuiElementPos(relative); nonMaximizedOffset = new InstantGuiElementPos(offset); if (scape == InstantGuiWindowScape.screen || scape == InstantGuiWindowScape.off) { relative = new InstantGuiElementPos(0, 0, 0, 0); offset = new InstantGuiElementPos(0, Screen.width, 0, Screen.height); } if (scape == InstantGuiWindowScape.parent) { relative = new InstantGuiElementPos(0, 100, 0, 100); offset = new InstantGuiElementPos(0, 0, 0, 0); } } if (expandButton.activated && !expandButton.check) { relative = nonMaximizedRelative; offset = nonMaximizedOffset; } //re-calc offset on resolution change if (expandButton.check && (scape == InstantGuiWindowScape.screen || scape == InstantGuiWindowScape.off)) { offset = new InstantGuiElementPos(0, Screen.width, 0, Screen.height); } } // scrolling Rect rectangle = new Rect(x, y, width, height); using (var scrollViewScope = new GUI.ScrollViewScope(rectangle, scrollPosition, rectangle)){ scrollPosition = scrollViewScope.scrollPosition; } }
protected void DrawSearchResults(Rect rect) { if (Event.current.isScrollWheel) { var d = Event.current.delta.y; selectedSearchIndex += (int)(Mathf.Sign(d) * Mathf.Clamp(d, 1, 99)); } if (selectedSearchIndex >= searchResults.Count) { selectedSearchIndex = searchResults.Count - 1; } if (selectedSearchIndex < 0) { selectedSearchIndex = 0; } if (lastSelectedSearchIndex != selectedSearchIndex) { lastSelectedSearchIndex = selectedSearchIndex; } using (var scrollView = new GUI.ScrollViewScope(new Rect(0, rect.yMax, position.width, position.height - rect.yMax), searchScrollPosition, searchViewRect)) { searchScrollPosition = scrollView.scrollPosition; var index = 0; var cc = GUI.contentColor; var row = new Rect(0, 0, position.width, 24); var style = new GUIStyle(GUI.skin.textField); style.alignment = TextAnchor.MiddleLeft; style.fontStyle = FontStyle.Bold; style.imagePosition = ImagePosition.ImageLeft; foreach (var result in searchResults) { if (row.y > searchScrollPosition.y - row.height && row.y < position.height + searchScrollPosition.y) { if (result.content == null) { result.content = new GUIContent(result.niceName + " " + result.signature, GetIcon(result.type)); } var contentColor = result.candidateClass == null ? Color.white : Color.yellow; if (index == selectedSearchIndex) { if (row.y >= searchScrollPosition.y) { searchScrollPosition.y = row.y; } if (row.y <= searchScrollPosition.y) { searchScrollPosition.y = row.y; } GUI.contentColor = contentColor; } else { GUI.contentColor = contentColor *= 0.8f; } if (GUI.Button(row, result.content, style)) { AddNodeToTarget(result); } } row.y += row.height + 1; index += 1; } GUI.contentColor = cc; searchViewRect = new Rect(0, 0, row.xMax - 16, row.yMax); } }
/// <summary> /// Draws an inspector that displays the marker library contents /// and allows for selection of one of the markers in the library. /// </summary> /// <param name="scrollPos">The scroll position of the view showing the marker library</param> /// <param name="markerLibrary">The marker library currently being edited</param> /// <param name="selectedImageMarkerIndex">The index of the selected image marker in the marker library.</param> /// <returns>Current selected image marker index.</returns> public static int DrawImageMarkerLibraryInspector(ref Vector2 scrollPos, MarsMarkerLibrary markerLibrary, int selectedImageMarkerIndex) { var imageMarkerInspectorWidth = EditorGUIUtility.currentViewWidth - Styles.EdgeSubtraction; GUILayout.Box(string.Empty, GUILayout.Height(Styles.ImageBrowserHeight), GUILayout.Width(imageMarkerInspectorWidth)); var scrollAreaPosRect = GUILayoutUtility.GetLastRect(); // +4 space to fit buttons on top if img marker lib box var verticalBoxOffset = EditorGUIUtility.singleLineHeight + 4; scrollAreaPosRect = new Rect(scrollAreaPosRect.x, scrollAreaPosRect.y + verticalBoxOffset, scrollAreaPosRect.width - 1, scrollAreaPosRect.height - verticalBoxOffset - 1); // -1 to see box edges. var texturesToPlaceHorizontally = ((int)scrollAreaPosRect.width - Styles.EdgeSubtraction + Styles.SpaceBetweenImagesHorizontal * 0.5f) / (Styles.ImageMarkersSize + Styles.SpaceBetweenImagesHorizontal); var texturesToPlaceVertically = Mathf.CeilToInt(markerLibrary.Count / texturesToPlaceHorizontally); var scrollViewHeight = texturesToPlaceVertically * (Styles.ImageMarkersSize + Styles.SpaceBetweenImagesHorizontal + EditorGUIUtility.singleLineHeight); var scrollAreaRect = new Rect(0, verticalBoxOffset, scrollAreaPosRect.width - Styles.EdgeSubtraction, scrollViewHeight + verticalBoxOffset - EditorGUIUtility.singleLineHeight); var offsetX = (((scrollAreaRect.width + Styles.SpaceBetweenImagesHorizontal * 0.5f) / (Styles.ImageMarkersSize + Styles.SpaceBetweenImagesHorizontal)) / texturesToPlaceHorizontally) - 1; DrawTopImageMarkerInspectorBox(scrollAreaPosRect, verticalBoxOffset, markerLibrary); using (var scrollScope = new GUI.ScrollViewScope(scrollAreaPosRect, scrollPos, scrollAreaRect, false, true)) { scrollPos = scrollScope.scrollPosition; var currentEvent = Event.current; var counter = 0; for (var j = 0; j < texturesToPlaceVertically; j++) { for (var i = 0; i < texturesToPlaceHorizontally; i++) { var xPos = (Styles.SpaceBetweenImagesHorizontal + i * (Styles.ImageMarkersSize + Styles.SpaceBetweenImagesHorizontal)) + (offsetX * scrollAreaRect.width * 0.5f); var yPos = EditorGUIUtility.singleLineHeight + (Styles.SpaceBetweenImagesVertical * 0.5f + j * (Styles.ImageMarkersSize + Styles.SpaceBetweenImagesVertical)); if (counter < markerLibrary.Count) { var isActive = counter == selectedImageMarkerIndex; var markerDefinition = markerLibrary[counter]; if (DrawImageMarker(xPos, yPos, isActive, markerDefinition)) { selectedImageMarkerIndex = counter; if (markerLibrary[counter].MarkerId == Guid.Empty) { Debug.LogError("Marker library should be rebuilt since it contains empty guid."); } } } counter++; } } // Process here since we don't care if user drag/drops somewhere outside of img marker library box ProcessDragAndDropTexturesToMarkerConditionInspector( currentEvent, markerLibrary); } using (new EditorGUILayout.HorizontalScope()) { GUILayout.Space(imageMarkerInspectorWidth - Styles.AddRemoveButtonSize * 2); DrawAddImageMarkerButton(markerLibrary); if (DrawRemoveImageMarkerButton(selectedImageMarkerIndex, markerLibrary)) { selectedImageMarkerIndex = UnselectedMarkerIndex; } } return(selectedImageMarkerIndex); }
private void DrawChildren(Rect rect, TreeItem parent) { if (parent.Children.Count > 0) { var width = parent.Children.Count > _visibleItemCount ? rect.width - RectHelper.IconWidth : rect.width; var area = new Rect(Vector2.zero, new Vector2(width, _itemHeight * parent.Children.Count)); var selectedRect = area; using (var scroll = new GUI.ScrollViewScope(rect, parent.ScrollPosition, area)) { parent.ScrollPosition = scroll.scrollPosition; for (var i = 0; i < parent.Children.Count; i++) { var item = parent.Children[i]; var itemRect = RectHelper.TakeHeight(ref area, _itemHeight); if ((Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDown) && parent.SelectedIndex != i && itemRect.Contains(Event.current.mousePosition)) { parent.SelectedIndex = i; Repaint(); } var selected = i == parent.SelectedIndex; if (selected) { selectedRect = itemRect; } if (Event.current.type == EventType.Repaint) { _itemButtonStyle.Content.Draw(itemRect, item.Content, false, false, selected, selected); if (item.IsBranch) { var arrowRect = RectHelper.TakeTrailingIcon(ref itemRect); _childArrowStyle.Content.Draw(arrowRect, false, false, false, false); } } if (Event.current.type == EventType.MouseDown && itemRect.Contains(Event.current.mousePosition)) { Event.current.Use(); parent.SelectedIndex = i; SelectChild(); } } } if (_scrollToSelected && Event.current.type == EventType.Repaint) { _scrollToSelected = false; if (selectedRect.yMax - rect.height > parent.ScrollPosition.y) { parent.ScrollPosition.y = selectedRect.yMax - rect.height; Repaint(); } if (selectedRect.y < parent.ScrollPosition.y) { parent.ScrollPosition.y = selectedRect.y; Repaint(); } } } }