private float ScaleThatFitsTargetInView(Vector2 targetInPixels, Vector2 viewInPoints) { var targetInPoints = EditorGUIUtility.PixelsToPoints(targetInPixels); var viewToTargetRatio = new Vector2(viewInPoints.x / targetInPoints.x, viewInPoints.y / targetInPoints.y); return(Mathf.Min(viewToTargetRatio.x, viewToTargetRatio.y)); }
/// <summary> /// <para>Map a mouse drag onto a movement along a line in 3D space.</para> /// </summary> /// <param name="src">The source point of the drag.</param> /// <param name="dest">The destination point of the drag.</param> /// <param name="srcPosition">The 3D position the dragged object had at src ray.</param> /// <param name="constraintDir">3D direction of constrained movement.</param> /// <returns> /// <para>The distance travelled along constraintDir.</para> /// </returns> public static float CalcLineTranslation(Vector2 src, Vector2 dest, Vector3 srcPosition, Vector3 constraintDir) { srcPosition = Handles.matrix.MultiplyPoint(srcPosition); constraintDir = Handles.matrix.MultiplyVector(constraintDir); float num = 1f; Vector3 forward = Camera.current.transform.forward; if ((double)Vector3.Dot(constraintDir, forward) < 0.0) { num = -1f; } Vector3 vector3 = constraintDir; vector3.y = -vector3.y; Camera current = Camera.current; Vector2 points1 = EditorGUIUtility.PixelsToPoints((Vector2)current.WorldToScreenPoint(srcPosition)); Vector2 points2 = EditorGUIUtility.PixelsToPoints((Vector2)current.WorldToScreenPoint(srcPosition + constraintDir * num)); Vector2 x0_1 = dest; Vector2 x0_2 = src; if (points1 == points2) { return(0.0f); } x0_1.y = -x0_1.y; x0_2.y = -x0_2.y; float parametrization = HandleUtility.GetParametrization(x0_2, points1, points2); return((HandleUtility.GetParametrization(x0_1, points1, points2) - parametrization) * num); }
public static float CalcLineTranslation(Vector2 src, Vector2 dest, Vector3 srcPosition, Vector3 constraintDir) { srcPosition = Handles.matrix.MultiplyPoint(srcPosition); constraintDir = Handles.matrix.MultiplyVector(constraintDir); float num = 1f; Vector3 forward = Camera.current.transform.forward; if (Vector3.Dot(constraintDir, forward) < 0f) { num = -1f; } Vector3 vector2 = constraintDir; vector2.y = -vector2.y; Camera current = Camera.current; Vector2 vector3 = EditorGUIUtility.PixelsToPoints(current.WorldToScreenPoint(srcPosition)); Vector2 vector4 = EditorGUIUtility.PixelsToPoints(current.WorldToScreenPoint(srcPosition + ((Vector3)(constraintDir * num)))); Vector2 vector5 = dest; Vector2 vector6 = src; if (vector3 == vector4) { return(0f); } vector5.y = -vector5.y; vector6.y = -vector6.y; float num2 = GetParametrization(vector6, vector3, vector4); return((GetParametrization(vector5, vector3, vector4) - num2) * num); }
public static float CalcLineTranslation(Vector2 src, Vector2 dest, Vector3 srcPosition, Vector3 constraintDir) { srcPosition = Handles.matrix.MultiplyPoint(srcPosition); constraintDir = Handles.matrix.MultiplyVector(constraintDir); float num = 1f; Vector3 forward = Camera.current.transform.forward; if (Vector3.Dot(constraintDir, forward) < 0f) { num = -1f; } Vector3 vector = constraintDir; vector.y = -vector.y; Camera current = Camera.current; Vector2 vector2 = EditorGUIUtility.PixelsToPoints(current.WorldToScreenPoint(srcPosition)); Vector2 vector3 = EditorGUIUtility.PixelsToPoints(current.WorldToScreenPoint(srcPosition + constraintDir * num)); Vector2 x = dest; Vector2 x2 = src; float result; if (vector2 == vector3) { result = 0f; } else { x.y = -x.y; x2.y = -x2.y; float parametrization = HandleUtility.GetParametrization(x2, vector2, vector3); float parametrization2 = HandleUtility.GetParametrization(x, vector2, vector3); float num2 = (parametrization2 - parametrization) * num; result = num2; } return result; }
private float ScaleThatFitsTargetInView(Vector2 targetInPixels, Vector2 viewInPoints) { Vector2 vector = EditorGUIUtility.PixelsToPoints(targetInPixels); Vector2 vector2 = new Vector2(viewInPoints.x / vector.x, viewInPoints.y / vector.y); return(Mathf.Min(vector2.x, vector2.y)); }
internal Rect GetConstrainedGameViewRenderRect() { if (base.m_Parent == null) { return(s_MainGameViewRect); } base.m_Pos = base.m_Parent.borderSize.Remove(base.m_Parent.position); return(EditorGUIUtility.PixelsToPoints(GetConstrainedGameViewRenderRect(EditorGUIUtility.PointsToPixels(this.gameViewRenderRect), this.selectedSizeIndex))); }
internal Rect GetConstrainedGameViewRenderRect() { if ((UnityEngine.Object) this.m_Parent == (UnityEngine.Object)null) { return(GameView.s_MainGameViewRect); } this.m_Pos = this.m_Parent.borderSize.Remove(this.m_Parent.position); return(EditorGUIUtility.PixelsToPoints(GameView.GetConstrainedGameViewRenderRect(EditorGUIUtility.PointsToPixels(this.gameViewRenderRect), this.selectedSizeIndex))); }
internal Rect GetConstrainedGameViewRenderRect() { if (this.m_Parent == null) { return(GameView.s_MainGameViewRect); } this.m_Pos = this.m_Parent.borderSize.Remove(this.m_Parent.position); Rect renderRect = EditorGUIUtility.PointsToPixels(this.gameViewRenderRect); Rect constrainedGameViewRenderRect = GameView.GetConstrainedGameViewRenderRect(renderRect, this.selectedSizeIndex); return(EditorGUIUtility.PixelsToPoints(constrainedGameViewRenderRect)); }
public static Vector2 WorldToGUIPoint(Vector3 world) { world = Handles.matrix.MultiplyPoint(world); Camera current = Camera.current; if (current != null) { Vector2 position = current.WorldToScreenPoint(world); position.y = Screen.height - position.y; return(GUIClip.Clip(EditorGUIUtility.PixelsToPoints(position))); } return(new Vector2(world.x, world.y)); }
// Helper function for doing arrows. public static float CalcLineTranslation(Vector2 src, Vector2 dest, Vector3 srcPosition, Vector3 constraintDir) { // Apply handle matrix srcPosition = Handles.matrix.MultiplyPoint(srcPosition); constraintDir = Handles.matrix.MultiplyVector(constraintDir); // The constrained direction is facing towards the camera, THATS BAD when the handle is close to the camera // The srcPosition goes through to the other side of the camera float invert = 1.0F; Vector3 cameraForward = Camera.current == null ? Vector3.forward : Camera.current.transform.forward; if (Vector3.Dot(constraintDir, cameraForward) < 0.0F) { invert = -1.0F; } // Ok - Get the parametrization of the line // p1 = src position, p2 = p1 + ConstraintDir. // we then parametrise the perpendicular position of dest into the line (p1-p2) Vector3 cd = constraintDir; cd.y = -cd.y; Camera cam = Camera.current; // if camera is null, then we are drawing in OnGUI, where y-coordinate goes top-to-bottom Vector2 p1 = cam == null ? Vector2.Scale(srcPosition, new Vector2(1f, -1f)) : EditorGUIUtility.PixelsToPoints(cam.WorldToScreenPoint(srcPosition)); Vector2 p2 = cam == null ? Vector2.Scale(srcPosition + constraintDir *invert, new Vector2(1f, -1f)) : EditorGUIUtility.PixelsToPoints(cam.WorldToScreenPoint(srcPosition + constraintDir * invert)); Vector2 p3 = dest; Vector2 p4 = src; if (p1 == p2) { return(0); } p3.y = -p3.y; p4.y = -p4.y; float t0 = GetParametrization(p4, p1, p2); float t1 = GetParametrization(p3, p1, p2); float output = (t1 - t0) * invert; return(output); }
public static Vector2 WorldToGUIPoint(Vector3 world) { world = Handles.matrix.MultiplyPoint(world); Camera current = Camera.current; if (current) { Vector2 vector = current.WorldToScreenPoint(world); vector.y = (float)Screen.height - vector.y; vector = EditorGUIUtility.PixelsToPoints(vector); return(GUIClip.Clip(vector)); } return(new Vector2(world.x, world.y)); }
// Convert world space point to a 2D GUI position. public static Vector2 WorldToGUIPoint(Vector3 world) { world = Handles.matrix.MultiplyPoint(world); Camera cam = Camera.current; if (cam) { Vector2 pos = cam.WorldToScreenPoint(world); pos.y = Screen.height - pos.y; pos = EditorGUIUtility.PixelsToPoints(pos); return(GUIClip.Clip(pos)); } return(new Vector2(world.x, world.y)); }
// Convert world space point to a 2D GUI position. // Use this version in critical loops. internal static Vector3 WorldToGUIPointWithDepth(Vector3 world, Camera camera, Matrix4x4 matrixHandles, float screenHeight) { world = matrixHandles.MultiplyPoint(world); if (camera) { Vector3 pos = camera.WorldToScreenPoint(world); pos.y = screenHeight - pos.y; Vector2 points = EditorGUIUtility.PixelsToPoints(pos); points = GUIClip.Clip(points); return(new Vector3(points.x, points.y, pos.z)); } return(world); }
// Convert world space point to a 2D GUI position. public static Vector3 WorldToGUIPointWithDepth(Vector3 world) { world = Handles.matrix.MultiplyPoint(world); Camera cam = Camera.current; if (cam) { Vector3 pos = cam.WorldToScreenPoint(world); pos.y = Screen.height - pos.y; Vector2 points = EditorGUIUtility.PixelsToPoints(pos); points = GUIClip.Clip(points); return(new Vector3(points.x, points.y, pos.z)); } return(world); }
static public float CalcLineTranslation(Vector2 src, Vector2 dest, Vector3 srcPosition, Vector3 constraintDir) { srcPosition = Handles.matrix.MultiplyPoint(srcPosition); constraintDir = Handles.matrix.MultiplyVector(constraintDir); float invert = 1.0F; Vector3 cameraForward = Camera.current.transform.forward; if (Vector3.Dot(constraintDir, cameraForward) < 0.0F) { invert = -1.0F; } Vector3 cd = constraintDir; cd.y = -cd.y; Camera cam = Camera.current; Vector2 p1 = EditorGUIUtility.PixelsToPoints(cam.WorldToScreenPoint(srcPosition)); Vector2 p2 = EditorGUIUtility.PixelsToPoints(cam.WorldToScreenPoint(srcPosition + constraintDir * invert)); Vector2 p3 = dest; Vector2 p4 = src; if (p1 == p2) { return(0); } p3.y = -p3.y; p4.y = -p4.y; float t0 = GetParametrization(p4, p1, p2); float t1 = GetParametrization(p3, p1, p2); float output = (t1 - t0) * invert; return(output); }
public Vector2 ScreenToGUIPoint(Vector2 screenPoint) { screenPoint.y = m_ScreenHeight - screenPoint.y; return(GUIClip.Clip(EditorGUIUtility.PixelsToPoints(screenPoint))); }
public Vector2 ScreenToGUIPoint(Vector2 point) { point.y = screen - point.y; return(GUIClip.Clip(EditorGUIUtility.PixelsToPoints(point))); }
private void OnGUI() { bool flag; if (s_GizmoButtonStyle == null) { s_GizmoButtonStyle = "GV Gizmo DropDown"; s_ResolutionWarningStyle = new GUIStyle("PreOverlayLabel"); s_ResolutionWarningStyle.alignment = TextAnchor.UpperLeft; s_ResolutionWarningStyle.padding = new RectOffset(6, 6, 1, 1); } this.DoToolbarGUI(); Rect gameViewRenderRect = this.gameViewRenderRect; Rect rect = GetConstrainedGameViewRenderRect(EditorGUIUtility.PointsToPixels(gameViewRenderRect), this.selectedSizeIndex, out flag); Rect rect4 = EditorGUIUtility.PixelsToPoints(rect); Rect rect5 = GUIClip.Unclip(rect4); Rect cameraRect = EditorGUIUtility.PointsToPixels(rect5); base.SetInternalGameViewRect(rect5); EditorGUIUtility.AddCursorRect(rect4, MouseCursor.CustomCursor); EventType type = Event.current.type; if ((type == EventType.MouseDown) && gameViewRenderRect.Contains(Event.current.mousePosition)) { this.AllowCursorLockAndHide(true); } else if ((type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape)) { Unsupported.SetAllowCursorLock(false); } switch (type) { case EventType.Layout: case EventType.Used: break; case EventType.Repaint: { bool flag2 = EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay); if ((!this.currentGameViewSize.isFreeAspectRatio || !InternalEditorUtility.HasFullscreenCamera()) || !flag2) { GUI.Box(gameViewRenderRect, GUIContent.none, "GameViewBackground"); if (!flag2) { GUI.Label(new Rect((gameViewRenderRect.width / 2f) - 50f, (gameViewRenderRect.height / 2f) - 10f, 200f, 50f), "No camera"); } } Vector2 vector = GUIUtility.s_EditorScreenPointOffset; GUIUtility.s_EditorScreenPointOffset = Vector2.zero; SavedGUIState state = SavedGUIState.Create(); if (this.ShouldShowMultiDisplayOption()) { EditorGUIUtility.RenderGameViewCameras(cameraRect, this.m_TargetDisplay, this.m_Gizmos, true); } else { EditorGUIUtility.RenderGameViewCameras(cameraRect, 0, this.m_Gizmos, true); } GL.sRGBWrite = false; state.ApplyAndForget(); GUIUtility.s_EditorScreenPointOffset = vector; break; } default: { if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused)) { return; } bool flag3 = rect4.Contains(Event.current.mousePosition); if ((Event.current.rawType == EventType.MouseDown) && !flag3) { return; } Vector2 mousePosition = Event.current.mousePosition; Vector2 position = mousePosition - rect4.position; position = EditorGUIUtility.PointsToPixels(position); Event.current.mousePosition = position; EditorGUIUtility.QueueGameViewInputEvent(Event.current); bool flag4 = true; if ((Event.current.rawType == EventType.MouseUp) && !flag3) { flag4 = false; } switch (type) { case EventType.ExecuteCommand: case EventType.ValidateCommand: flag4 = false; break; } if (flag4) { Event.current.Use(); } else { Event.current.mousePosition = mousePosition; } break; } } this.ShowResolutionWarning(new Rect(gameViewRenderRect.x, gameViewRenderRect.y, 200f, 20f), flag, rect.size); if (this.m_Stats) { GameViewGUI.GameViewStatsGUI(); } }
private void OnGUI() { if (GameView.s_GizmoButtonStyle == null) { GameView.s_GizmoButtonStyle = "GV Gizmo DropDown"; GameView.s_ResolutionWarningStyle = new GUIStyle("PreOverlayLabel"); GameView.s_ResolutionWarningStyle.alignment = TextAnchor.UpperLeft; GameView.s_ResolutionWarningStyle.padding = new RectOffset(6, 6, 1, 1); } this.DoToolbarGUI(); Rect gameViewRenderRect = this.gameViewRenderRect; Rect renderRect = EditorGUIUtility.PointsToPixels(gameViewRenderRect); bool fitsInsideRect; Rect constrainedGameViewRenderRect = GameView.GetConstrainedGameViewRenderRect(renderRect, this.selectedSizeIndex, out fitsInsideRect); Rect rect = EditorGUIUtility.PixelsToPoints(constrainedGameViewRenderRect); Rect rect2 = GUIClip.Unclip(rect); Rect cameraRect = EditorGUIUtility.PointsToPixels(rect2); base.SetInternalGameViewRect(rect2); EditorGUIUtility.AddCursorRect(rect, MouseCursor.CustomCursor); EventType type = Event.current.type; if (type == EventType.MouseDown && gameViewRenderRect.Contains(Event.current.mousePosition)) { this.AllowCursorLockAndHide(true); } else if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { Unsupported.SetAllowCursorLock(false); } if (type == EventType.Repaint) { bool flag = EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay); if (!this.currentGameViewSize.isFreeAspectRatio || !InternalEditorUtility.HasFullscreenCamera() || !flag) { GUI.Box(gameViewRenderRect, GUIContent.none, "GameViewBackground"); if (!InternalEditorUtility.HasFullscreenCamera()) { float[] array = new float[] { 30f, gameViewRenderRect.height / 2f - 10f, gameViewRenderRect.height - 10f }; for (int i = 0; i < array.Length; i++) { int num = (int)array[i]; GUI.Label(new Rect(gameViewRenderRect.width / 2f - 100f, (float)num, 300f, 20f), "Scene is missing a fullscreen camera", "WhiteLargeLabel"); } } } Vector2 s_EditorScreenPointOffset = GUIUtility.s_EditorScreenPointOffset; GUIUtility.s_EditorScreenPointOffset = Vector2.zero; SavedGUIState savedGUIState = SavedGUIState.Create(); if (this.ShouldShowMultiDisplayOption()) { EditorGUIUtility.RenderGameViewCamerasInternal(cameraRect, this.m_TargetDisplay, this.m_Gizmos, true); } else { EditorGUIUtility.RenderGameViewCamerasInternal(cameraRect, 0, this.m_Gizmos, true); } GL.sRGBWrite = false; savedGUIState.ApplyAndForget(); GUIUtility.s_EditorScreenPointOffset = s_EditorScreenPointOffset; } else if (type != EventType.Layout && type != EventType.Used) { if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused)) { return; } bool flag2 = rect.Contains(Event.current.mousePosition); if (Event.current.rawType == EventType.MouseDown && !flag2) { return; } Vector2 mousePosition = Event.current.mousePosition; Vector2 vector = mousePosition - rect.position; vector = EditorGUIUtility.PointsToPixels(vector); Event.current.mousePosition = vector; Event.current.displayIndex = this.m_TargetDisplay; EditorGUIUtility.QueueGameViewInputEvent(Event.current); bool flag3 = true; if (Event.current.rawType == EventType.MouseUp && !flag2) { flag3 = false; } if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand) { flag3 = false; } if (flag3) { Event.current.Use(); } else { Event.current.mousePosition = mousePosition; } } this.ShowResolutionWarning(new Rect(gameViewRenderRect.x, gameViewRenderRect.y, 200f, 20f), fitsInsideRect, constrainedGameViewRenderRect.size); if (this.m_Stats) { GameViewGUI.GameViewStatsGUI(); } }