/// <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 e = Event.current; if (e.rawType == EventType.MouseDown) { Debug.Log(StringUtils.ToColorizedString(ToString() + " Event=", e, ", e.type=", e.type, ", button=", e.button, ", mousePos=", e.mousePosition, ", GUIUtility.hotControl=", GUIUtility.hotControl)); } #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; #if UNITY_EDITOR var labelWidthWas = EditorGUIUtility.labelWidth; #endif 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; #if UNITY_EDITOR EditorGUIUtility.labelWidth = labelWidthWas; #endif GUI.skin = null; GUI.matrix = matrixWas; throw; } #if DEV_MODE Debug.LogWarning(ToString() + " " + e); #endif dirty = true; } #if !POWER_INSPECTOR_LITE NowDrawingPart = InspectorPart.Toolbar; { Toolbar.Draw(toolbarRect); } #endif NowDrawingPart = InspectorPart.Other; //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; #if UNITY_EDITOR EditorGUIUtility.labelWidth = labelWidthWas; #endif GUI.skin = null; GUI.matrix = matrixWas; if (dirty) { InspectorDrawer.RefreshView(); } InspectorUtility.EndInspector(this); UnityEngine.Profiling.Profiler.EndSample(); }