/// <inheritdoc /> public override bool Draw(Rect position) { if (Event.current.type == EventType.Layout) { OnLayoutEvent(position); } else if (splitterRect.height < 1f) { GetDrawPositions(position); Inspector.RefreshView(); } DrawGUI.DrawLine(splitterRect, inspector.Preferences.theme.ComponentSeparatorLine); GenerateControlId(); if (Event.current.type == EventType.Repaint) { GUI.Button(buttonRect, "Add Component", "AC Button"); } DrawGUI.LayoutSpace(Height); return(false); }
/// <inheritdoc /> public override bool Draw(Rect position) { if (Event.current.type == EventType.Layout) { OnLayoutEvent(position); } DrawGUI.DrawLine(splitterRect, inspector.Preferences.theme.ComponentSeparatorLine); //needed for button GenerateControlId(); bool selected = Selected; var colorWas = GUI.color; if (selected) { GUI.color = InspectorUtility.Preferences.theme.ButtonSelected; } GUI.Button(buttonRect, "Add Component", "AC Button"); GUI.color = colorWas; DrawGUI.LayoutSpace(Height); return(false); }
/// <inheritdoc/> public override bool DrawPrefix(Rect position) { bool guiChangedWas = GUI.changed; GUI.changed = false; bool dirty = false; position.height = DrawGUI.Active.InspectorTitlebarHeight; var foldoutPos = position; foldoutPos.x += 2f; foldoutPos.y += 2f; foldoutPos.height -= 2f; foldoutPos.width -= 2f; DrawGUI.Active.Foldout(foldoutPos, new GUIContent(" "), Unfolded, Selected, Mouseovered, false); var settings = InspectorUtility.Preferences; var linePos = position; linePos.height = 1f; DrawGUI.DrawLine(linePos, settings.theme.ComponentSeparatorLine); var assetIconPos = position; assetIconPos.x += 15f; assetIconPos.y += 2f; assetIconPos.width = 15f; assetIconPos.height = 15f; GUI.DrawTexture(assetIconPos, settings.graphics.missingAssetIcon); var labelPos = position; labelPos.x += 47f; labelPos.y += 2f; GUI.Label(labelPos, label, DrawGUI.prefixLabelModified); GUI.Label(GetRectForFirstHeaderToolbarControl(position), contextMenuLabel, InspectorPreferences.Styles.Centered); if (GUI.changed) { dirty = true; } GUI.changed = guiChangedWas; return(dirty); }
private void DrawSideBar(Rect sideBarRect) { var guiColorWas = GUI.color; var drawRect = sideBarRect; drawRect.height = sideBarItemHeight; for (int n = 0, count = Urls.Length; n < count; n++) { var header = Urls[n].Key; if (n == activeView) { GUI.color = InspectorUtility.Preferences.theme.BackgroundSelected; GUI.Label(drawRect, header, InspectorPreferences.Styles.SideBarItem); } else { GUI.color = guiColorWas; if (GUI.Button(drawRect, header, InspectorPreferences.Styles.SideBarItem)) { SetActiveView(n); } } drawRect.y += sideBarItemHeight; } DrawGUI.DrawLine(separator1, Color.black); DrawGUI.DrawLine(separator2, Color.black); GUI.color = ViewInBrowserButtonColor; viewInBrowserLabel.tooltip = url; if (GUI.Button(viewInBrowserRect, viewInBrowserLabel, InspectorPreferences.Styles.SideBarItem)) { OpenInBrowser(); } GUI.color = autoUpdateEnabled ? AutoUpdateEnabledColor : AutoUpdateDisabledColor; if (GUI.Button(autoUpdateRect, autoUpdateEnabled ? disableAutoUpdate : enableAutoUpdate, InspectorPreferences.Styles.SideBarItem)) { autoUpdateEnabled = !autoUpdateEnabled; } GUI.color = guiColorWas; }
/// <inheritdoc/> public override bool DrawBody(Rect position) { float unfoldedness = Unfoldedness; if (unfoldedness <= 0f) { position.height = 1f; DrawGUI.DrawLine(position, Inspector.Preferences.theme.ComponentSeparatorLine); return(false); } Profiler.BeginSample("CategorizedComponentsDrawer.DrawBody"); bool dirty; if (unfoldedness >= 1f) { dirty = DrawFoldableContent(position); } else { #if DEV_MODE && PI_ASSERTATIONS var assertColor = GUI.color; #endif using (new MemberScaler(position.min, unfoldedness)) { dirty = DrawFoldableContent(position); } #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(GUI.color == assertColor, ToString() + " - After DrawFoldableContent"); #endif } Profiler.EndSample(); return(dirty); }
private bool Draw(ref bool addedComponent) { if (instance == null) { return(false); } bool dirty = false; GUI.Label(headerLabelRect, categoryLabel, InspectorPreferences.Styles.PopupMenuTitle); #if UNITY_EDITOR if (GUI.Button(createScriptButtonRect, GUIContent.none, InspectorPreferences.Styles.Blank)) { dirty = true; openCreateNewScriptViewNextLayout = true; } #endif bool hasFilter = FilterString.Length > 0; bool hasBackArrow = !hasFilter && activeItem != null; if (hasBackArrow && GUI.Button(backArrowRect, GUIContent.none, InspectorPreferences.Styles.Blank)) { #if UNITY_EDITOR if (!openCreateNewScriptViewNextLayout) #endif { goBackLevelNextLayout = true; dirty = true; } } if (DrawFilterField()) { dirty = true; } var setScrollPos = GUI.BeginScrollView(viewRect, scrollPos, contentRect); { if (setScrollPos.y != scrollPos.y) { SetScrollPos(setScrollPos.y, true); dirty = true; } var memberRect = contentRect; DrawGUI.Active.ColorRect(memberRect, BgColor); memberRect.height = DrawGUI.SingleLineHeight; //only start drawing from first visible member memberRect.y += firstVisibleIndex * DrawGUI.SingleLineHeight; int last = lastVisibleIndex - firstVisibleIndex; int visibleCount = visibleMembers.Length; if (last >= visibleCount) { #if DEV_MODE Debug.LogWarning(ToString() + " - last (" + last + ") >= visibleCount (" + visibleCount + ") with firstVisibleIndex=" + firstVisibleIndex + " and lastVisibleIndex=" + lastVisibleIndex); #endif last = visibleCount - 1; } var mousePos = Event.current.mousePosition; for (int n = 0; n <= last; n++) { int memberIndex = firstVisibleIndex + n; //TEMP if (last >= visibleMembers.Length) { #if DEV_MODE Debug.LogError("n=" + n + ", last=" + last + ", visibleMembers.Length=" + visibleMembers.Length + ", "); #endif break; } var member = visibleMembers[n]; bool selected = memberIndex == selectedComponentIndex; if (selected) { DrawGUI.Active.ColorRect(memberRect, InspectorUtility.Preferences.theme.BackgroundSelected); } if (memberRect.Contains(mousePos)) { if (memberIndex != selectedComponentIndex) { SetSelectedMember(memberIndex, false); dirty = true; } } if (visibleMembersHaveConflicts[n]) { GUI.enabled = false; } if (member.Draw(memberRect)) { switch (Event.current.button) { case 0: break; case 1: member.OpenContextMenu(Event.current, memberRect, true, Part.Base); return(true); case 2: var script = FileUtility.FindScriptFile(member.Type); if (script != null) { DrawGUI.Active.PingObject(script); } return(true); default: return(false); } var type = member.Type; dirty = true; var itemDrawer = member as AddComponentMenuItemDrawer; if (type == null) { SetActiveItem(itemDrawer.Item); break; } addedComponent = true; if (itemDrawer.nameBy) { string setName = StringUtils.SplitPascalCaseToWords(type.Name); var gameObjectDrawers = inspector.State.drawers.Members; for (int d = gameObjectDrawers.Length - 1; d >= 0; d--) { var gameObjectDrawer = gameObjectDrawers[d] as IGameObjectDrawer; if (gameObjectDrawer != null) { var gameObjects = gameObjectDrawer.GameObjects; for (int g = gameObjectDrawers.Length - 1; g >= 0; g--) { var gameObject = gameObjects[g]; gameObject.name = setName; } } } } inspector.OnNextLayout(() => AddComponent(type)); if (Event.current.type == EventType.MouseDown) { DrawGUI.Use(Event.current); } break; } GUI.enabled = true; memberRect.y += DrawGUI.SingleLineHeight; } GUI.EndScrollView(); } if (clearingText) { if (Event.current.type == EventType.Layout) { clearingText = false; } GUI.changed = true; dirty = true; } else { if (!DrawGUI.EditingTextField) { DrawGUI.EditingTextField = true; GUI.changed = true; dirty = true; } if (!string.Equals(GUI.GetNameOfFocusedControl(), ControlName)) { DrawGUI.FocusControl(ControlName); GUI.changed = true; dirty = true; } } if (hasBackArrow) { DrawGUI.Active.ColorRect(backArrowBgRect, BgColorNavigationBar); DrawGUI.Active.AddCursorRect(backArrowRect, MouseCursor.Link); GUI.Label(backArrowRect, GUIContent.none, backArrowStyle); } #if UNITY_EDITOR DrawGUI.Active.ColorRect(createScriptBgRect, BgColorNavigationBar); DrawGUI.Active.AddCursorRect(createScriptButtonRect, MouseCursor.Link); GUI.Label(createScriptButtonRect, GUIContent.none, createNewStyle); #endif DrawGUI.DrawLine(dividerRect1, InspectorUtility.Preferences.theme.ComponentSeparatorLine); DrawGUI.DrawLine(dividerRect2, InspectorUtility.Preferences.theme.ComponentSeparatorLine); return(dirty); }
/// <inheritdoc/> public override bool DrawPrefix(Rect position) { bool textColorAltered = false; if (Event.current.type == EventType.Repaint) { var lineRect = position; lineRect.height = 1f; var theme = Inspector.Preferences.theme; DrawGUI.DrawLine(lineRect, theme.ComponentSeparatorLine); #if SAFE_MODE if (prefixLabelDrawer == null) { #if DEV_MODE Debug.LogWarning(GetType().Name + ".DrawPrefix - prefixLabelDrawer of " + this + " under parent " + (parent == null ? "null" : parent.ToString()) + " was null!"); #endif return(false); } #endif if (mouseoveredIconIndex == -1) { if (Selected) { textColorAltered = true; SetLabelGUIStyleColor(theme.PrefixSelectedText); } else if (Mouseovered) { if (InspectorUtility.Preferences.mouseoverEffects.unityObjectHeaderTint) { textColorAltered = true; SetLabelGUIStyleColor(theme.PrefixMouseoveredText); } } } } var drawPos = position; drawPos.x += 3f; drawPos.width -= 3f; drawPos.y += 3f; drawPos.height -= 3f; if (lastPassedFilterTestType != FilterTestType.None) { prefixLabelDrawer.Draw(drawPos, Inspector.State.filter, label.text, lastPassedFilterTestType); } else { prefixLabelDrawer.Draw(drawPos); } if (textColorAltered) { SetLabelGUIStyleColor(labelIdleColor); } DrawGUI.LayoutSpace(position.height); if (Event.current.type == EventType.Repaint) { DrawComponentIcons(position); } return(false); }
/// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary> /// <param name="inspectorDimensions"> The position and bounds for where the inspecto should be drawn. </param> /// <param name="anyInspectorPartMouseovered"> True if any inspector part is currently mouseovered. </param> public override void OnGUI(Rect inspectorDimensions, bool anyInspectorPartMouseovered) { UnityEngine.Profiling.Profiler.BeginSample("OnGUI"); #if DEV_MODE && DEBUG_CLICK var ev = Event.current; if (ev.rawType == EventType.MouseDown) { Debug.Log(StringUtils.ToColorizedString(ToString() + " Event=", ev, ", e.type=", ev.type, ", button=", ev.button, ", mousePos=", ev.mousePosition, ", GUIUtility.hotControl=", GUIUtility.hotControl)); } #endif #if DEV_MODE && PI_ASSERTATIONS if (inspectorDimensions.width <= 0f) { Debug.LogError(GetType().Name + ".OnGUI inspectorDimensions.width <= 0f: " + inspectorDimensions); } #endif //this can happen e.g. if the preferences file gets reimported due to being altered outside of Unity if (Preferences == null) { Preferences = GetPreferences(); } #if DEV_MODE && DEBUG_MOUSEOVERED_PART if (State.drawer.VisibleMembers.Length > 0 && DrawGUI.IsUnityObjectDrag) { Debug.Log(StringUtils.ToColorizedString(ToString(), ".OnGUI with mouseoveredPart=", MouseoveredPart, ", Event=" + StringUtils.ToString(Event.current), ", ignoreAllMouseInputs=", InspectorDrawer.Manager.IgnoreAllMouseInputs, "ยด, ObjectPickerIsOpen=", ObjectPicker.IsOpen, ", anyInspectorPartMouseovered=", anyInspectorPartMouseovered, ", InspectorDrawer.MouseIsOver=", InspectorDrawer.MouseIsOver, ", DrawGUI.CanRequestMousePosition=", Cursor.CanRequestLocalPosition)); } #endif InspectorUtility.BeginInspector(this, ref anyInspectorPartMouseovered); Rect toolbarRect; Rect viewportRect; Rect previewAreaRect; GetDrawPositions(inspectorDimensions, out toolbarRect, out viewportRect, out previewAreaRect); // trying to fix a bug where the default inspector layout gets wacky if both it and this window are open // by making sure all values that could affect it are restored back to normal // var indentLevelWas = EditorGUI.indentLevel; var labelWidthWas = EditorGUIUtility.labelWidth; var matrixWas = GUI.matrix; var currentEvent = Event.current; switch (currentEvent.type) { case EventType.Layout: State.nextUpdateCachedValues--; if (State.nextUpdateCachedValues <= 0) { UpdateCachedValuesFromFields(); } OnCursorPositionOrLayoutChanged(); break; case EventType.MouseMove: case EventType.MouseDrag: case EventType.DragUpdated: if (IgnoreViewportMouseInputs()) { #if DEV_MODE //Debug.Log("ignoring "+ currentEvent.type+"..."); #endif break; } OnCursorPositionOrLayoutChanged(); InspectorDrawer.RefreshView(); break; } bool dirty; try { dirty = DrawViewport(viewportRect); } catch (Exception e) { if (ExitGUIUtility.ShouldRethrowException(e)) { NowDrawingPart = InspectorPart.None; DrawGUI.IndentLevel = 0; EditorGUIUtility.labelWidth = labelWidthWas; GUI.skin = null; GUI.matrix = matrixWas; throw; } #if DEV_MODE Debug.LogWarning(ToString() + " " + e); #endif // Always throw ExitGUI exception if exceptions were caught to avoid GUI Layout warnings. ExitGUIUtility.ExitGUI(); return; } #if !POWER_INSPECTOR_LITE NowDrawingPart = InspectorPart.Toolbar; { Toolbar.Draw(toolbarRect); #if UNITY_2019_3_OR_NEWER Color lineColor; if (DrawGUI.IsProSkin) { lineColor = Preferences.theme.ComponentSeparatorLine; } else { lineColor = new Color32(153, 153, 153, 255); } var lineRect = toolbarRect; lineRect.height = 1f; lineRect.y = toolbarRect.height; DrawGUI.DrawLine(lineRect, lineColor); #endif } #endif NowDrawingPart = InspectorPart.Other; try { if (DrawPreviewArea) { NowDrawingPart = InspectorPart.PreviewArea; { previewDrawer.Draw(previewAreaRect); } NowDrawingPart = InspectorPart.Other; } } #if DEV_MODE catch (ArgumentException e) // GUILayout: Mismatched LayoutGroup.repaint { Debug.LogError(StringUtils.ToString(Event.current) + " " + e + "\nEvent=" + StringUtils.ToString(Event.current)); #else catch (ArgumentException) { #endif // new test to avoid GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced. NowDrawingPart = InspectorPart.None; ExitGUIUtility.ExitGUI(); } //TO DO: Move to EndInspector if these are needed? //trying to fix a bug where the default inspector layout gets wacky if both it and this window are open //by making sure all values that could affect it are restored back to normal DrawGUI.IndentLevel = 0; EditorGUIUtility.labelWidth = labelWidthWas; GUI.skin = null; GUI.matrix = matrixWas; if (dirty) { InspectorDrawer.RefreshView(); } InspectorUtility.EndInspector(this); UnityEngine.Profiling.Profiler.EndSample(); }
/// <inheritdoc/> public virtual void Draw(Rect toolbarPosition) { var e = Event.current; var eventType = e.type; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(BackgroundStyle != null); #endif var backgroundStyle = BackgroundStyle; GUILayout.BeginArea(toolbarPosition, backgroundStyle); { bool isLayoutEvent = eventType == EventType.Layout; bool toolbarMouseovered = inspector.MouseoveredPart == InspectorPart.Toolbar; if (updateToolbarItemBounds) { UpdateVisibleItemBounds(toolbarPosition); if (isLayoutEvent) { updateToolbarItemBounds = false; } } int count = visibleItems.Length; bool detectMouseover = toolbarMouseovered && isLayoutEvent; if (detectMouseover) { mouseoverVisibleItemIndex = -1; for (int n = 0; n < count; n++) { var item = visibleItems[n]; var bounds = item.Bounds; if (bounds.Contains(Event.current.mousePosition)) { mouseoverVisibleItemIndex = n; } } } // new: style all items with toolbar style by default if (Event.current.type == EventType.Repaint) { for (int n = 0; n < count; n++) { var item = visibleItems[n]; var bounds = item.Bounds; item.DrawBackground(bounds, backgroundStyle); } } for (int n = 0; n < count; n++) { var item = visibleItems[n]; var bounds = item.Bounds; item.Draw(bounds); } #if UNITY_2019_3_OR_NEWER var lineRect = toolbarPosition; lineRect.y = 0f; lineRect.height = 1f; DrawGUI.DrawLine(lineRect, lineAboveColor); lineRect.y = toolbarPosition.height - 1f; DrawGUI.DrawLine(lineRect, lineBelowColor); #endif if (selectedItemIndex != -1) { var item = items[selectedItemIndex]; item.DrawSelectionRect(item.Bounds); } } GUILayout.EndArea(); #if DEV_MODE && UNITY_EDITOR if (e.control && (eventType == EventType.ContextClick || (eventType == EventType.MouseDown && e.button == 1)) && toolbarPosition.Contains(e.mousePosition)) { var menu = Menu.Create(); if (mouseoverVisibleItemIndex != -1) { var item = visibleItems[mouseoverVisibleItemIndex]; menu.Add("Edit " + item.GetType().Name + ".cs", () => { var script = FileUtility.FindScriptFile(item.GetType()); if (script != null) { UnityEditor.AssetDatabase.OpenAsset(script); } else { Debug.LogError("FileUtility.FindScriptFilepath could not find file " + GetType().Name + ".cs"); } }); } menu.Add("Edit " + GetType().Name + ".cs", () => { var script = FileUtility.FindScriptFile(GetType()); if (script != null) { UnityEditor.AssetDatabase.OpenAsset(script); } else { Debug.LogError("FileUtility.FindScriptFilepath could not find file " + GetType().Name + ".cs"); } }); menu.Open(); } #endif // Prevent controls in the inspector viewport's scroll view from reacting to mouse inputs behind the toolbar. if (GUI.Button(toolbarPosition, GUIContent.none, InspectorPreferences.Styles.Blank)) { #if DEV_MODE Debug.LogWarning("Consumed click event behind toolbar via GUI.Button: " + StringUtils.ToString(Event.current)); #endif } }