private static void RestoreClickControlsAfterTwoFrames() { if (inspector != null) { inspector.OnNextLayout(RestoreClickControlsAfterAFrame); } }
private static void RestoreClickControlsAfterTwoFrames() { if (inspector != null) { inspector.OnNextLayout(RestoreClickControlsAfterAFrame); } #if DEV_MODE else { Debug.Log("RestoreClickControlsAfterTwoFrames called with inspector null, so can't restore controls. InspectorUtility.ActiveInspector=" + StringUtils.ToString(InspectorUtility.ActiveInspector)); } #endif }
private void ShowCurrent(IInspector inspector) { if (history[currentIndex].ContentsMatch(inspector.State.inspected)) { return; } #if DEV_MODE Debug.Log("SelectionHistory.ShowCurrent with ViewIsLocked=" + inspector.State.ViewIsLocked); #endif if (inspector.State.ViewIsLocked) { inspector.OnNextLayout(() => RebuildDrawerForCurrent(inspector)); } else { IgnoreNextRecordRequest(); inspector.Select(history[currentIndex]); } }
/// <summary> Deserialize inspector state. </summary> /// <param name="drawer"> The drawer of the inspector. </param> /// <param name="inspector"> /// The inspector over which the state should be deserialized. If this is null, a new split view /// will be opened in the drawer, and state will be deserialized over that. /// </param> public void Deserialize(IInspectorDrawer drawer, [CanBeNull] IInspector inspector) { #if DEV_MODE && DEBUG_ENABLED Debug.Log("Restoring state of " + inspector + " from " + inspected.Length + " int..."); #endif if (inspector == null) { var splittable = drawer as ISplittableInspectorDrawer; if (viewLocked) { splittable.ShowInSplitView(Deserialize()); } else { splittable.SetSplitView(true); } inspector = splittable.SplitView; } else { inspector.State.ViewIsLocked = viewLocked; if (viewLocked) { inspector.RebuildDrawers(Deserialize(), false); } else { inspector.RebuildDrawersIfTargetsChanged(); } } if (!string.IsNullOrEmpty(filter)) { inspector.SetFilter(filter); } inspector.OnNextLayout(() => inspector.State.ScrollPos = scrollPos); }
public bool OnGUI(ref bool addedComponent) { bool dirty = false; var e = Event.current; var eventType = e.type; switch (eventType) { case EventType.KeyDown: if (OnKeyboardInputGiven(e)) { return(true); } break; case EventType.MouseDown: case EventType.MouseMove: dirty = true; break; case EventType.Layout: if (goBackLevelNextLayout) { goBackLevelNextLayout = false; GoBackLevel(); } #if UNITY_EDITOR else if (openCreateNewScriptViewNextLayout) { openCreateNewScriptViewNextLayout = false; string inNamespace = null; string saveIn = null; if (activeItem != null) { var type = activeItem.TypeOrAnyChildType(); if (type != null) { var existingScript = FileUtility.FindScriptFile(type); if (existingScript != null) { inNamespace = type.Namespace; saveIn = FileUtility.GetParentDirectory(UnityEditor.AssetDatabase.GetAssetPath(existingScript)); } } } if (inNamespace == null) { inNamespace = InspectorUtility.Preferences.defaultNamespace; } if (saveIn == null) { saveIn = InspectorUtility.Preferences.defaultScriptPath; } if (filter.Length > 0) { Platform.Active.SetPrefs("PI.CreateScriptWizard/Name", filter); } Platform.Active.SetPrefs("PI.CreateScriptWizard/Namespace", inNamespace); Platform.Active.SetPrefs("PI.CreateScriptWizard/SaveIn", saveIn); Platform.Active.SetPrefs("PI.CreateScriptWizard/Template", "MonoBehaviour"); Platform.Active.SetPrefs("PI.CreateScriptWizard/AttachTo", target.UnityObject.GetInstanceID()); inspector.OnNextLayout(() => DrawGUI.ExecuteMenuItem(PowerInspectorMenuItemPaths.CreateScriptWizardFromCreateMenu)); Close(); return(true); } #endif else if (clearTextNextLayout) { clearTextNextLayout = false; ClearText(); } break; } if (Draw(ref addedComponent)) { dirty = true; } return(dirty); }
/// <summary> /// Sets focused drawer and handles calling OnDeselected (first) and OnSelected (second) for setDrawer /// and any previously focused drawer that is no longer selected. Also makes sure that selected inspector /// and inspector part are valid. /// </summary> /// <param name="setDrawer"> The drawer to set as the focused drawer. Can be null if focused drawer should be set to none. </param> /// <param name="multiSelect"> If 0 this is not a multi selection, if -1 remove from multi-selection, and if 1 add to multi-selection. </param> /// <param name="reason">Reason why focus is changing.</param> private void SetFocusedDrawer([CanBeNull] IDrawer setDrawer, int multiSelect, ReasonSelectionChanged reason) { var focusedDrawerWas = focusedDrawer; #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(multiSelect == 0 || setDrawer != null); //multi-selecting doesn't make sense for a null drawer UnityEngine.Debug.Assert(multiSelect == 0 || setDrawer.Parent is ICollectionDrawer); //for now multi-selection is only supported for collection members UnityEngine.Debug.Assert(multiSelect != -1 || isMultiSelection); //can't remove from multi-selection if there is no multi-selection UnityEngine.Debug.Assert(!isMultiSelection || multiSelection.Count >= 2); //multi-selection requires at least two selected drawers #endif #if SAFE_MODE || DEV_MODE if (setDrawer != null && !setDrawer.Selectable) { #if DEV_MODE UnityEngine.Debug.LogError("SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Selectable was " + StringUtils.False); #endif for (setDrawer = setDrawer.Parent; setDrawer != null && !setDrawer.Selectable; setDrawer = setDrawer.Parent) { ; } } #endif #if SAFE_MODE || DEV_MODE if (setDrawer != null) { #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(setDrawer.Selectable, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Selectable was " + StringUtils.False); UnityEngine.Debug.Assert(!setDrawer.Inactive, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Inactive was " + StringUtils.True); UnityEngine.Debug.Assert(setDrawer.ShouldShowInInspector, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").ShowInInspector was " + StringUtils.False); UnityEngine.Debug.Assert(inspector != null, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") inspector was " + StringUtils.Null); UnityEngine.Debug.Assert(inspectorPart == InspectorPart.Viewport, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") inspectorPart was " + inspectorPart); UnityEngine.Debug.Assert(!ObjectPicker.IsOpen, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") ObjectPicker.IsOpen was " + StringUtils.True); //UnityEngine.Debug.Assert(inspector.InspectorDrawer.HasFocus); //this can be true if an item is right cicked #endif if (inspector == null) { Inspector = InspectorUtility.ActiveInspector; } inspectorPart = InspectorPart.Viewport; //this can be true if an item was just right-clicked if (!inspector.InspectorDrawer.HasFocus) { #if DEV_MODE UnityEngine.Debug.Log("Manually focusing window! Event=" + StringUtils.ToString(UnityEngine.Event.current)); #endif inspector.InspectorDrawer.FocusWindow(); } } #endif #if DEV_MODE && DEBUG_SET_DRAWER UnityEngine.Debug.Log(StringUtils.ToColorizedString("Selected.SetFocusedDrawer(", setDrawer, ", multiSelect=", multiSelect, ", reason=", reason, ")")); #endif switch (multiSelect) { case 0: focusedDrawer = setDrawer; ClearMultiSelection(reason, setDrawer); if (setDrawer != focusedDrawerWas) { if (focusedDrawerWas != null && !focusedDrawerWas.Inactive) { focusedDrawerWas.OnDeselected(reason, setDrawer); } if (setDrawer != null) { if (!(setDrawer is ITextFieldDrawer) && !(setDrawer is ICustomEditorDrawer)) { DrawGUI.EditingTextField = false; } setDrawer.OnSelected(reason, focusedDrawerWas, false); } else { DrawGUI.EditingTextField = false; } if (inspector != null) { // This can possibly help in ensuring that selection rects are drawn in the right place // and in ensuring that the inspector feels very responsive. inspector.OnNextLayout(inspector.RefreshView); } } break; case 1: DrawGUI.EditingTextField = false; bool wasSelected = IsSelected(setDrawer); focusedDrawer = setDrawer; multiSelection.AddIfDoesNotContain(focusedDrawerWas); multiSelection.AddIfDoesNotContain(setDrawer); UpdateMultiSelection(); if (!wasSelected) { setDrawer.OnSelected(reason, focusedDrawerWas, isMultiSelection); } if (inspector != null) { // This can possibly help in ensuring that selection rects are drawn in the right place // and in ensuring that the inspector feels very responsive. inspector.OnNextLayout(inspector.RefreshView); } break; case -1: multiSelection.Remove(setDrawer); if (setDrawer == focusedDrawer) { int selectedCount = multiSelection.Count; focusedDrawer = selectedCount == 0 ? setDrawer : multiSelection[selectedCount - 1]; } UpdateMultiSelection(); if (setDrawer != focusedDrawer && !setDrawer.Inactive) { setDrawer.OnDeselected(reason, focusedDrawer); } if (!isMultiSelection) { DrawGUI.EditingTextField = false; } else if (focusedDrawer != null) { if (!(setDrawer is ITextFieldDrawer)) { DrawGUI.EditingTextField = false; } } else { DrawGUI.EditingTextField = false; } if (inspector != null) { // This can possibly help in ensuring that selection rects are drawn in the right place // and in ensuring that the inspector feels very responsive. inspector.OnNextLayout(inspector.RefreshView); } break; } if (focusedDrawer != null) { rowIndex = focusedDrawer.GetSelectedRowIndex(); rowElementCount = setDrawer.GetRowSelectableCount(); } #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(multiSelect != 0 || !isMultiSelection); UnityEngine.Debug.Assert(!isMultiSelection || multiSelection.Count >= 2); #endif }
private bool Draw(ref bool menuItemWasClicked) { if (instance == null) { return(false); } #if DEV_MODE || PROFILE_POWER_INSPECTOR Profiler.BeginSample("PopupMenu.Draw"); #endif PopupMenuItemUtility.drawWithFullPath = filter.Length > 0; bool dirty = false; var e = Event.current; //using raw type, since we consume all click events var eventType = e.rawType; bool lmbClick = eventType == EventType.MouseDown && e.button == 0; bool mmbClick = eventType == EventType.MouseDown && e.button == 2; if (clearingText) { if (eventType == 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 (DrawFilterField()) { dirty = true; } DrawGUI.Active.ColorRect(headerRect, BgColorNavigationBar); bool hasFilter = FilterString.Length > 0; bool drawBackArrow = !hasFilter && activeGroup != null; bool drawLabelField = currentViewLabel.text.Length > 0; if (drawBackArrow || drawLabelField) { if (drawBackArrow) { GUI.Label(backArrowRect, GUIContent.none, "AC LeftArrow"); if (lmbClick && backArrowRect.Contains(e.mousePosition)) { goBackLevelNextLayout = true; dirty = true; } } DrawGUI.DrawRect(headerRect, new Color32(24, 24, 24, 255), localDrawAreaOffset); if (drawLabelField) { GUI.Label(headerLabelRect, currentViewLabel, InspectorPreferences.Styles.PopupMenuTitle); } GUI.DrawTexture(dividerRect, InspectorUtility.Preferences.graphics.horizontalSplitterBg); } #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(contentRect.x == 0f, "contentRect.x=" + contentRect.x); Debug.Assert(contentRect.y == 0f, "contentRect.y=" + contentRect.y); Debug.Assert(contentRect.height == currentViewItemCount * DrawGUI.SingleLineHeight, "contentRect.height=" + contentRect.height + ", currentViewItemCount=" + currentViewItemCount); Debug.Assert(currentViewItemCount == currentViewItems.Count, "currentViewItemCount=" + currentViewItemCount + ", currentViewItems.Count=" + currentViewItems.Count); Debug.Assert(viewRect.height == contentRect.height || viewRect.height == ScrollAreaMaxHeight, "viewRect.height (" + viewRect.height + ") != contentRect.height (" + contentRect.height + ") NOR ScrollAreaMaxHeight (" + ScrollAreaMaxHeight + ")"); #endif 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; if (last >= currentViewItemCount) { #if DEV_MODE Debug.LogWarning(ToString() + " - last (" + last + ") >= visibleCount (" + (lastVisibleIndex - firstVisibleIndex + 1) + ") with firstVisibleIndex=" + firstVisibleIndex + " and lastVisibleIndex=" + lastVisibleIndex); #endif last = currentViewItemCount - 1; } for (int n = firstVisibleIndex; n <= last; n++) { var item = currentViewItems[n]; bool selected = n == selectedMemberIndex; if (selected) { DrawGUI.Active.ColorRect(memberRect, InspectorUtility.Preferences.theme.BackgroundSelected); } if (memberRect.Contains(e.mousePosition)) { if (!selected) { SetSelectedMember(n, false); dirty = true; } if (lmbClick) { dirty = true; if (item.IsGroup) { SetActiveItem(item); break; } menuItemWasClicked = true; inspector.OnNextLayout(() => OnMenuItemClicked(item)); break; } if (mmbClick) { if (item.IsGroup) { var unityObjects = item.children.Select(menuItem => menuItem.IdentifyingObject as Object).ToArray(); if (unityObjects.Length > 0) { DrawGUI.Ping(unityObjects); } } else { var itemValue = item.IdentifyingObject; var unityObject = itemValue as Object; if (unityObject != null) { DrawGUI.Ping(unityObject); } var unityObjects = itemValue as Object[]; if (unityObjects != null) { DrawGUI.Ping(unityObjects); } } } } if (PopupMenuItemUtility.Draw(memberRect, selectedMemberIndex == n, item)) { #if DEV_MODE Debug.Log(GetType().Name + " - member " + item + " clicked with eventType " + eventType + "! (member returned true)"); #endif dirty = true; if (item.IsGroup) { SetActiveItem(item); break; } menuItemWasClicked = true; inspector.OnNextLayout(() => OnMenuItemClicked(item)); DrawGUI.Use(e); break; } if (!item.IsGroup) { bool ticked = tickedItems != null && tickedItems.Contains(item); var toggleRect = memberRect; toggleRect.width = 16f; toggleRect.x += memberRect.width - toggleRect.width; if (canTickMultiple) { bool setTicked = GUI.Toggle(toggleRect, ticked, GUIContent.none, InspectorUtility.Preferences.GetStyle("OL Toggle")); if (setTicked != ticked) { if (ticked) { tickedItems.Add(item); } else { tickedItems.Remove(item); } menuItemWasClicked = true; inspector.OnNextLayout(() => OnMenuItemClicked(item)); DrawGUI.Use(e); break; } } else if (ticked) { GUI.Toggle(toggleRect, true, GUIContent.none, InspectorUtility.Preferences.GetStyle("OL Toggle")); } } GUI.enabled = true; memberRect.y += DrawGUI.SingleLineHeight; } ///after visible part, count * DrawGUI.singleLineHeight GUI.EndScrollView(); } #if DEV_MODE || PROFILE_POWER_INSPECTOR Profiler.EndSample(); #endif return(dirty); }
/// <inheritdoc/> public virtual void OnSelected(ReasonSelectionChanged reason) { #if DEV_MODE && DEBUG_ON_SELECTED Debug.Log(GetType().Name + ".OnSelected(" + reason + ")"); #endif switch (reason) { case ReasonSelectionChanged.ThisClicked: case ReasonSelectionChanged.ControlClicked: if (mouseoverVisibleItemIndex != -1) { var item = visibleItems[mouseoverVisibleItemIndex]; if (item.Selectable) { SetSelectedItem(item, reason); return; } SetSelectedItem(-1, reason); return; } if (TrySelectSearchBox(reason)) { return; } SelectFirstSelectableItem(reason); return; case ReasonSelectionChanged.SelectNextControl: case ReasonSelectionChanged.SelectControlRight: SelectFirstSelectableItem(reason); return; case ReasonSelectionChanged.SelectPrevControl: case ReasonSelectionChanged.SelectControlLeft: SelectLastSelectableItem(reason); return; case ReasonSelectionChanged.SelectControlUp: case ReasonSelectionChanged.SelectControlDown: case ReasonSelectionChanged.SelectPrevComponent: case ReasonSelectionChanged.SelectNextComponent: if (TrySelectSearchBox(reason)) { return; } SelectFirstSelectableItem(reason); return; default: inspector.OnNextLayout(() => { if (selectedItemIndex != -1) { return; } if (TrySelectSearchBox(reason)) { return; } SelectFirstSelectableItem(reason); }); return; } }