public Vector2 GUIToScreenPoint(Vector2 point) { var pixels = EditorGUIUtility.PointsToPixels(point); pixels.y = screen - pixels.y; return(pixels); }
internal static GameObject PickGameObjectDelegated(Vector2 position, GameObject[] ignore, GameObject[] filter, out int materialIndex) { Camera cam = Camera.current; int layers = cam.cullingMask; position = GUIClip.Unclip(position); position = EditorGUIUtility.PointsToPixels(position); position.y = Screen.height - position.y - cam.pixelRect.yMin; materialIndex = -1; // default if (ignore != null && ignore.Any(go => go == null)) { throw new ArgumentException("ignore may not contain null elements"); } if (filter != null && filter.Any(go => go == null)) { throw new ArgumentException("filter may not contain null elements"); } GameObject picked = null; if (pickClosestGameObjectDelegate != null) { picked = pickClosestGameObjectDelegate(cam, layers, position, ignore, filter, out materialIndex); } if (picked == null) { picked = Internal_PickClosestGO(cam, layers, position, ignore, filter, out materialIndex); } return(picked); }
public Vector2 GUIToScreenPoint(Vector2 guiPoint) { var pixels = EditorGUIUtility.PointsToPixels(guiPoint); pixels.y = m_ScreenHeight - pixels.y; return(pixels); }
internal static GameObject PickGameObjectDelegated(Vector2 position, GameObject[] ignore, GameObject[] filter, out int materialIndex) { Camera cam = Camera.current; int layers = cam.cullingMask; position = GUIClip.Unclip(position); position = EditorGUIUtility.PointsToPixels(position); position.y = Screen.height - position.y - cam.pixelRect.yMin; materialIndex = -1; // default GameObject picked = null; if (pickClosestGameObjectDelegate != null) { picked = pickClosestGameObjectDelegate(cam, layers, position, ignore, filter, out materialIndex); } if (picked == null) { picked = Internal_PickClosestGO(cam, layers, position, ignore, filter, out materialIndex); } return(picked); }
public static Vector2 GUIPointToScreenPixelCoordinate(Vector2 guiPoint) { Vector2 position = GUIClip.Unclip(guiPoint); Vector2 result = EditorGUIUtility.PointsToPixels(position); result.y = (float)Screen.height - result.y; return result; }
internal static bool FindNearestVertex(Vector2 guiPoint, Transform[] objectsToSearch, out Vector3 vertex) { Camera current = Camera.current; Vector2 screenPoint = EditorGUIUtility.PointsToPixels(guiPoint); screenPoint.y = current.pixelRect.yMax - screenPoint.y; return HandleUtility.Internal_FindNearestVertex(current, screenPoint, objectsToSearch, HandleUtility.ignoreRaySnapObjects, out vertex); }
public static Vector2 GUIPointToScreenPixelCoordinate(Vector2 guiPoint) { var unclippedPosition = GUIClip.Unclip(guiPoint); var screenPixelPos = EditorGUIUtility.PointsToPixels(unclippedPosition); screenPixelPos.y = Screen.height - screenPixelPos.y; return(screenPixelPos); }
public void OnOverlayGUI(UnityEngine.Object target, SceneView sceneView) { if (!(target == null)) { Camera camera = (Camera)target; Vector2 mainGameViewTargetSize = GameView.GetMainGameViewTargetSize(); if (mainGameViewTargetSize.x < 0f) { mainGameViewTargetSize.x = sceneView.position.width; mainGameViewTargetSize.y = sceneView.position.height; } Rect rect = camera.rect; mainGameViewTargetSize.x *= Mathf.Max(rect.width, 0f); mainGameViewTargetSize.y *= Mathf.Max(rect.height, 0f); if (mainGameViewTargetSize.x > 0f && mainGameViewTargetSize.y > 0f) { float num = mainGameViewTargetSize.x / mainGameViewTargetSize.y; mainGameViewTargetSize.y = 0.2f * sceneView.position.height; mainGameViewTargetSize.x = mainGameViewTargetSize.y * num; if (mainGameViewTargetSize.y > sceneView.position.height * 0.5f) { mainGameViewTargetSize.y = sceneView.position.height * 0.5f; mainGameViewTargetSize.x = mainGameViewTargetSize.y * num; } if (mainGameViewTargetSize.x > sceneView.position.width * 0.5f) { mainGameViewTargetSize.x = sceneView.position.width * 0.5f; mainGameViewTargetSize.y = mainGameViewTargetSize.x / num; } Rect rect2 = GUILayoutUtility.GetRect(mainGameViewTargetSize.x, mainGameViewTargetSize.y); rect2 = EditorGUIUtility.PointsToPixels(rect2); rect2.y = (sceneView.position.height + 1f) * EditorGUIUtility.pixelsPerPoint - rect2.y - rect2.height; if (Event.current.type == EventType.Repaint) { this.previewCamera.CopyFrom(camera); Skybox component = this.previewCamera.GetComponent <Skybox>(); if (component) { Skybox component2 = camera.GetComponent <Skybox>(); if (component2 && component2.enabled) { component.enabled = true; component.material = component2.material; } else { component.enabled = false; } } this.previewCamera.targetTexture = null; this.previewCamera.pixelRect = rect2; Handles.EmitGUIGeometryForCamera(camera, this.previewCamera); this.previewCamera.Render(); } } } }
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))); }
public void OnOverlayGUI(Object target, SceneView sceneView) { if (target != null) { Camera other = (Camera)target; Vector2 sizeOfMainGameView = GameView.GetSizeOfMainGameView(); if (sizeOfMainGameView.x < 0f) { sizeOfMainGameView.x = sceneView.position.width; sizeOfMainGameView.y = sceneView.position.height; } Rect rect = other.rect; sizeOfMainGameView.x *= Mathf.Max(rect.width, 0f); sizeOfMainGameView.y *= Mathf.Max(rect.height, 0f); if ((sizeOfMainGameView.x > 0f) && (sizeOfMainGameView.y > 0f)) { float num = sizeOfMainGameView.x / sizeOfMainGameView.y; sizeOfMainGameView.y = 0.2f * sceneView.position.height; sizeOfMainGameView.x = sizeOfMainGameView.y * num; if (sizeOfMainGameView.y > (sceneView.position.height * 0.5f)) { sizeOfMainGameView.y = sceneView.position.height * 0.5f; sizeOfMainGameView.x = sizeOfMainGameView.y * num; } if (sizeOfMainGameView.x > (sceneView.position.width * 0.5f)) { sizeOfMainGameView.x = sceneView.position.width * 0.5f; sizeOfMainGameView.y = sizeOfMainGameView.x / num; } Rect rect2 = EditorGUIUtility.PointsToPixels(GUILayoutUtility.GetRect(sizeOfMainGameView.x, sizeOfMainGameView.y)); rect2.y = (((sceneView.position.height + 1f) * EditorGUIUtility.pixelsPerPoint) - rect2.y) - rect2.height; if (Event.current.type == EventType.Repaint) { this.previewCamera.CopyFrom(other); Skybox component = this.previewCamera.GetComponent <Skybox>(); if (component != null) { Skybox skybox2 = other.GetComponent <Skybox>(); if ((skybox2 != null) && skybox2.enabled) { component.enabled = true; component.material = skybox2.material; } else { component.enabled = false; } } this.previewCamera.targetTexture = null; this.previewCamera.pixelRect = rect2; Handles.EmitGUIGeometryForCamera(other, this.previewCamera); this.previewCamera.Render(); } } } }
public static GameObject PickGameObject(Vector2 position, GameObject[] ignore, out int materialIndex) { Camera current = Camera.current; int cullingMask = current.cullingMask; position = GUIClip.Unclip(position); position = EditorGUIUtility.PointsToPixels(position); position.y = (Screen.height - position.y) - current.pixelRect.yMin; return(Internal_PickClosestGO(current, cullingMask, position, ignore, out materialIndex)); }
public static GameObject[] PickRectObjects(Rect rect, bool selectPrefabRootsOnly) { Camera current = Camera.current; rect = EditorGUIUtility.PointsToPixels(rect); rect.x /= (float)current.pixelWidth; rect.width /= (float)current.pixelWidth; rect.y /= (float)current.pixelHeight; rect.height /= (float)current.pixelHeight; return HandleUtility.Internal_PickRectObjects(current, rect, selectPrefabRootsOnly); }
// *undocumented* public static GameObject[] PickRectObjects(Rect rect, bool selectPrefabRootsOnly) { Camera cam = Camera.current; rect = EditorGUIUtility.PointsToPixels(rect); rect.x /= cam.pixelWidth; rect.width /= cam.pixelWidth; rect.y /= cam.pixelHeight; rect.height /= cam.pixelHeight; return(Internal_PickRectObjects(cam, rect, selectPrefabRootsOnly)); }
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 Ray GUIPointToWorldRay(Vector2 position) { if (Camera.current == null) { Debug.LogError("Unable to convert GUI point to world ray if a camera has not been set up!"); return(new Ray(Vector3.zero, Vector3.forward)); } Vector2 vector2 = EditorGUIUtility.PointsToPixels(GUIClip.Unclip(position)); vector2.y = Screen.height - vector2.y; return(Camera.current.ScreenPointToRay((Vector3) new Vector2(vector2.x, vector2.y))); }
/// <summary> /// <para>Convert 2D GUI position to a world space ray.</para> /// </summary> /// <param name="position"></param> public static Ray GUIPointToWorldRay(Vector2 position) { if (!(bool)((Object)Camera.current)) { Debug.LogError((object)"Unable to convert GUI point to world ray if a camera has not been set up!"); return(new Ray(Vector3.zero, Vector3.forward)); } Vector2 pixels = EditorGUIUtility.PointsToPixels(GUIClip.Unclip(position)); pixels.y = (float)Screen.height - pixels.y; return(Camera.current.ScreenPointToRay((Vector3) new Vector2(pixels.x, pixels.y))); }
public static Ray GUIPointToWorldRay(Vector2 position) { if (!Camera.current) { Debug.LogError("Unable to convert GUI point to world ray if a camera has not been set up!"); return(new Ray(Vector3.zero, Vector3.forward)); } Vector2 position2 = GUIClip.Unclip(position); Vector2 vector = EditorGUIUtility.PointsToPixels(position2); vector.y = (float)Screen.height - vector.y; Camera current = Camera.current; return(current.ScreenPointToRay(new Vector2(vector.x, vector.y))); }
internal static GameObject PickGameObjectDelegated(Vector2 position, GameObject[] ignore, GameObject[] filter, out int materialIndex) { Camera current = Camera.current; int cullingMask = current.cullingMask; position = GUIClip.Unclip(position); position = EditorGUIUtility.PointsToPixels(position); position.y = (float)Screen.height - position.y - current.pixelRect.yMin; materialIndex = -1; GameObject gameObject = null; if (HandleUtility.pickClosestGameObjectDelegate != null) { gameObject = HandleUtility.pickClosestGameObjectDelegate(current, cullingMask, position, ignore, filter, out materialIndex); } if (gameObject == null) { gameObject = HandleUtility.Internal_PickClosestGO(current, cullingMask, position, ignore, filter, out materialIndex); } return gameObject; }
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 InitPreview(Rect r) { // If the background colour has changed then we can't make any assumptions // about colour space, otherwise flip to the background colour to the correct one if (colorSpace != QualitySettings.activeColorSpace && (camera.backgroundColor == defaultBackgroundColor || camera.backgroundColor.linear == defaultBackgroundColor.linear)) { camera.backgroundColor = QualitySettings.activeColorSpace == ColorSpace.Linear ? defaultBackgroundColor.linear : defaultBackgroundColor; } m_TargetRect = r; float scaleFac = GetScaleFactor(r.width, r.height); int rtWidth = (int)(r.width * scaleFac); int rtHeight = (int)(r.height * scaleFac); if (!m_RenderTexture || m_RenderTexture.width != rtWidth || m_RenderTexture.height != rtHeight) { if (m_RenderTexture) { Object.DestroyImmediate(m_RenderTexture); m_RenderTexture = null; } // Do not use GetTemporary to manage render textures. Temporary RTs are only // garbage collected each N frames, and in the editor we might be wildly resizing // the inspector, thus using up tons of memory. GraphicsFormat format = camera.allowHDR ? GraphicsFormat.R16G16B16A16_SFloat : GraphicsFormat.R8G8B8A8_UNorm; m_RenderTexture = new RenderTexture(rtWidth, rtHeight, format, SystemInfo.GetGraphicsFormat(DefaultFormat.DepthStencil)); m_RenderTexture.hideFlags = HideFlags.HideAndDontSave; camera.targetTexture = m_RenderTexture; foreach (var light in lights) { light.enabled = true; } } if (Event.current != null && Event.current.type == EventType.Repaint) { camera.pixelRect = new Rect(0, 0, rtWidth, rtHeight); } else if (Event.current != null && Event.current.type == EventType.Layout) { camera.pixelRect = EditorGUIUtility.PointsToPixels(r); } m_SavedState = new SavedRenderTargetState(); EditorGUIUtility.SetRenderTextureNoViewport(m_RenderTexture); GL.LoadOrtho(); GL.LoadPixelMatrix(0, m_RenderTexture.width, m_RenderTexture.height, 0); ShaderUtil.rawViewportRect = new Rect(0, 0, m_RenderTexture.width, m_RenderTexture.height); ShaderUtil.rawScissorRect = new Rect(0, 0, m_RenderTexture.width, m_RenderTexture.height); GL.Clear(true, true, camera.backgroundColor); foreach (var light in lights) { light.enabled = true; } }
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))); }
public void OnOverlayGUI(UnityEngine.Object target, SceneView sceneView) { if (target == (UnityEngine.Object)null) { return; } Camera camera = (Camera)target; Vector2 sizeOfMainGameView = GameView.GetSizeOfMainGameView(); if ((double)sizeOfMainGameView.x < 0.0) { sizeOfMainGameView.x = sceneView.position.width; sizeOfMainGameView.y = sceneView.position.height; } Rect rect = camera.rect; sizeOfMainGameView.x *= Mathf.Max(rect.width, 0.0f); sizeOfMainGameView.y *= Mathf.Max(rect.height, 0.0f); if ((double)sizeOfMainGameView.x <= 0.0 || (double)sizeOfMainGameView.y <= 0.0) { return; } float num = sizeOfMainGameView.x / sizeOfMainGameView.y; sizeOfMainGameView.y = 0.2f * sceneView.position.height; sizeOfMainGameView.x = sizeOfMainGameView.y * num; if ((double)sizeOfMainGameView.y > (double)sceneView.position.height * 0.5) { sizeOfMainGameView.y = sceneView.position.height * 0.5f; sizeOfMainGameView.x = sizeOfMainGameView.y * num; } if ((double)sizeOfMainGameView.x > (double)sceneView.position.width * 0.5) { sizeOfMainGameView.x = sceneView.position.width * 0.5f; sizeOfMainGameView.y = sizeOfMainGameView.x / num; } Rect pixels = EditorGUIUtility.PointsToPixels(GUILayoutUtility.GetRect(sizeOfMainGameView.x, sizeOfMainGameView.y)); pixels.y = (sceneView.position.height + 1f) * EditorGUIUtility.pixelsPerPoint - pixels.y - pixels.height; if (Event.current.type != EventType.Repaint) { return; } this.previewCamera.CopyFrom(camera); Skybox component1 = this.previewCamera.GetComponent <Skybox>(); if ((bool)((UnityEngine.Object)component1)) { Skybox component2 = camera.GetComponent <Skybox>(); if ((bool)((UnityEngine.Object)component2) && component2.enabled) { component1.enabled = true; component1.material = component2.material; } else { component1.enabled = false; } } this.previewCamera.targetTexture = (RenderTexture)null; this.previewCamera.pixelRect = pixels; Handles.EmitGUIGeometryForCamera(camera, this.previewCamera); this.previewCamera.Render(); }
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(); } }