public void OnSceneGUI() { Camera camera = (Camera)base.target; if (CameraEditor.IsViewPortRectValidToRender(camera.rect)) { SceneViewOverlay.Window(new GUIContent("Camera Preview"), new SceneViewOverlay.WindowFunction(this.OnOverlayGUI), -100, base.target, SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget); Color color = Handles.color; Color color2 = CameraEditor.kGizmoCamera; color2.a *= 2f; Handles.color = color2; Vector3[] array = new Vector3[4]; float num; if (CameraEditor.GetFrustum(camera, null, array, out num)) { Vector3 vector = array[0]; Vector3 vector2 = array[1]; Vector3 vector3 = array[2]; Vector3 vector4 = array[3]; bool changed = GUI.changed; Vector3 vector5 = Vector3.Lerp(vector, vector3, 0.5f); float num2 = -1f; Vector3 a = CameraEditor.MidPointPositionSlider(vector2, vector3, camera.transform.up); if (!GUI.changed) { a = CameraEditor.MidPointPositionSlider(vector, vector4, -camera.transform.up); } if (GUI.changed) { num2 = (a - vector5).magnitude; } GUI.changed = false; a = CameraEditor.MidPointPositionSlider(vector4, vector3, camera.transform.right); if (!GUI.changed) { a = CameraEditor.MidPointPositionSlider(vector, vector2, -camera.transform.right); } if (GUI.changed) { num2 = (a - vector5).magnitude / num; } if (num2 >= 0f) { Undo.RecordObject(camera, "Adjust Camera"); if (camera.orthographic) { camera.orthographicSize = num2; } else { Vector3 a2 = vector5 + camera.transform.up * num2; camera.fieldOfView = Vector3.Angle(camera.transform.forward, a2 - camera.transform.position) * 2f; } changed = true; } GUI.changed = changed; Handles.color = color; } } }
private static bool GetFrustum(Camera camera, Vector3[] near, Vector3[] far, out float frustumAspect) { frustumAspect = CameraEditor.GetFrustumAspectRatio(camera); if ((double)frustumAspect < 0.0) { return(false); } if (far != null) { far[0] = new Vector3(0.0f, 0.0f, camera.farClipPlane); far[1] = new Vector3(0.0f, 1f, camera.farClipPlane); far[2] = new Vector3(1f, 1f, camera.farClipPlane); far[3] = new Vector3(1f, 0.0f, camera.farClipPlane); for (int index = 0; index < 4; ++index) { far[index] = camera.ViewportToWorldPoint(far[index]); } } if (near != null) { near[0] = new Vector3(0.0f, 0.0f, camera.nearClipPlane); near[1] = new Vector3(0.0f, 1f, camera.nearClipPlane); near[2] = new Vector3(1f, 1f, camera.nearClipPlane); near[3] = new Vector3(1f, 0.0f, camera.nearClipPlane); for (int index = 0; index < 4; ++index) { near[index] = camera.ViewportToWorldPoint(near[index]); } } return(true); }
private static bool GetFrustum(Camera camera, Vector3[] near, Vector3[] far, out float frustumAspect) { frustumAspect = CameraEditor.GetFrustumAspectRatio(camera); if (frustumAspect < 0f) { return(false); } if (far != null) { far[0] = new Vector3(0f, 0f, camera.farClipPlane); far[1] = new Vector3(0f, 1f, camera.farClipPlane); far[2] = new Vector3(1f, 1f, camera.farClipPlane); far[3] = new Vector3(1f, 0f, camera.farClipPlane); for (int i = 0; i < 4; i++) { far[i] = camera.ViewportToWorldPoint(far[i]); } } if (near != null) { near[0] = new Vector3(0f, 0f, camera.nearClipPlane); near[1] = new Vector3(0f, 1f, camera.nearClipPlane); near[2] = new Vector3(1f, 1f, camera.nearClipPlane); near[3] = new Vector3(1f, 0f, camera.nearClipPlane); for (int j = 0; j < 4; j++) { near[j] = camera.ViewportToWorldPoint(near[j]); } } return(true); }
private void CommandBufferGUI() { if (this.targets.Length != 1) { return; } Camera target = this.target as Camera; if ((UnityEngine.Object)target == (UnityEngine.Object)null) { return; } int commandBufferCount = target.commandBufferCount; if (commandBufferCount == 0) { return; } this.m_CommandBuffersShown = GUILayout.Toggle(this.m_CommandBuffersShown, GUIContent.Temp(commandBufferCount.ToString() + " command buffers"), EditorStyles.foldout, new GUILayoutOption[0]); if (!this.m_CommandBuffersShown) { return; } ++EditorGUI.indentLevel; foreach (CameraEvent evt in (CameraEvent[])Enum.GetValues(typeof(CameraEvent))) { foreach (CommandBuffer commandBuffer in target.GetCommandBuffers(evt)) { using (new GUILayout.HorizontalScope(new GUILayoutOption[0])) { Rect rect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.miniLabel); rect.xMin += EditorGUI.indent; Rect removeButtonRect = CameraEditor.GetRemoveButtonRect(rect); rect.xMax = removeButtonRect.x; GUI.Label(rect, string.Format("{0}: {1} ({2})", (object)evt, (object)commandBuffer.name, (object)EditorUtility.FormatBytes(commandBuffer.sizeInBytes)), EditorStyles.miniLabel); if (GUI.Button(removeButtonRect, CameraEditor.Styles.iconRemove, CameraEditor.Styles.invisibleButton)) { target.RemoveCommandBuffer(evt, commandBuffer); SceneView.RepaintAll(); GameView.RepaintAll(); GUIUtility.ExitGUI(); } } } } using (new GUILayout.HorizontalScope(new GUILayoutOption[0])) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove all", EditorStyles.miniButton, new GUILayoutOption[0])) { target.RemoveAllCommandBuffers(); SceneView.RepaintAll(); GameView.RepaintAll(); } } --EditorGUI.indentLevel; }
private static void DrawCameraBound(Camera camera, GizmoType gizmoType) { SceneView currentDrawingSceneView = SceneView.currentDrawingSceneView; if (currentDrawingSceneView != null && currentDrawingSceneView.in2DMode && camera == Camera.main && camera.orthographic) { CameraEditor.RenderGizmo(camera); } }
private static bool GetFrustum(Camera camera, Vector3[] near, Vector3[] far, out float frustumAspect) { frustumAspect = CameraEditor.GetFrustumAspectRatio(camera); if (frustumAspect < 0f) { return(false); } float num3; float num4; float num5; float num6; if (!camera.orthographic) { float num = Mathf.Tan(camera.fieldOfView * 0.0174532924f * 0.5f); float num2 = num * frustumAspect; num3 = num2 * camera.farClipPlane; num4 = num * camera.farClipPlane; num5 = num2 * camera.nearClipPlane; num6 = num * camera.nearClipPlane; } else { float num = camera.orthographicSize; float num2 = num * frustumAspect; num3 = num2; num4 = num; num5 = num2; num6 = num; } Matrix4x4 matrix4x = Matrix4x4.TRS(camera.transform.position, camera.transform.rotation, Vector3.one); if (far != null) { far[0] = new Vector3(-num3, -num4, camera.farClipPlane); far[1] = new Vector3(-num3, num4, camera.farClipPlane); far[2] = new Vector3(num3, num4, camera.farClipPlane); far[3] = new Vector3(num3, -num4, camera.farClipPlane); for (int i = 0; i < 4; i++) { far[i] = matrix4x.MultiplyPoint(far[i]); } } if (near != null) { near[0] = new Vector3(-num5, -num6, camera.nearClipPlane); near[1] = new Vector3(-num5, num6, camera.nearClipPlane); near[2] = new Vector3(num5, num6, camera.nearClipPlane); near[3] = new Vector3(num5, -num6, camera.nearClipPlane); for (int j = 0; j < 4; j++) { near[j] = matrix4x.MultiplyPoint(near[j]); } } return(true); }
private void CommandBufferGUI() { if (base.targets.Length == 1) { Camera camera = base.target as Camera; if (!(camera == null)) { int commandBufferCount = camera.commandBufferCount; if (commandBufferCount != 0) { this.m_CommandBuffersShown = GUILayout.Toggle(this.m_CommandBuffersShown, GUIContent.Temp(commandBufferCount + " command buffers"), EditorStyles.foldout, new GUILayoutOption[0]); if (this.m_CommandBuffersShown) { EditorGUI.indentLevel++; CameraEvent[] array = (CameraEvent[])Enum.GetValues(typeof(CameraEvent)); for (int i = 0; i < array.Length; i++) { CameraEvent cameraEvent = array[i]; CommandBuffer[] commandBuffers = camera.GetCommandBuffers(cameraEvent); CommandBuffer[] array2 = commandBuffers; for (int j = 0; j < array2.Length; j++) { CommandBuffer commandBuffer = array2[j]; using (new GUILayout.HorizontalScope(new GUILayoutOption[0])) { Rect rect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.miniLabel); rect.xMin += EditorGUI.indent; Rect removeButtonRect = CameraEditor.GetRemoveButtonRect(rect); rect.xMax = removeButtonRect.x; GUI.Label(rect, string.Format("{0}: {1} ({2})", cameraEvent, commandBuffer.name, EditorUtility.FormatBytes(commandBuffer.sizeInBytes)), EditorStyles.miniLabel); if (GUI.Button(removeButtonRect, CameraEditor.Styles.iconRemove, CameraEditor.Styles.invisibleButton)) { camera.RemoveCommandBuffer(cameraEvent, commandBuffer); SceneView.RepaintAll(); GameView.RepaintAll(); GUIUtility.ExitGUI(); } } } } using (new GUILayout.HorizontalScope(new GUILayoutOption[0])) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove all", EditorStyles.miniButton, new GUILayoutOption[0])) { camera.RemoveAllCommandBuffers(); SceneView.RepaintAll(); GameView.RepaintAll(); } } EditorGUI.indentLevel--; } } } } }
private static float GetFrustumAspectRatio(Camera camera) { Rect rect = camera.rect; if ((double)rect.width <= 0.0 || (double)rect.height <= 0.0) { return(-1f); } return(CameraEditor.GetGameViewAspectRatio() * (rect.width / rect.height)); }
private static void DrawCameraBound(Camera camera, GizmoType gizmoType) { SceneView drawingSceneView = SceneView.currentDrawingSceneView; if (!((UnityEngine.Object)drawingSceneView != (UnityEngine.Object)null) || !drawingSceneView.in2DMode || (!((UnityEngine.Object)camera == (UnityEngine.Object)Camera.main) || !camera.orthographic)) { return; } CameraEditor.RenderGizmo(camera); }
static void DrawCameraBound(Camera camera, GizmoType gizmoType) { var sv = SceneView.currentDrawingSceneView; if (sv != null && sv.in2DMode) { if (camera == Camera.main && camera.orthographic) { CameraEditor.RenderGizmo(camera); } } }
private static float GetFrustumAspectRatio(Camera camera) { Rect rect = camera.rect; if (rect.width <= 0f || rect.height <= 0f) { return(-1f); } float num = rect.width / rect.height; return(CameraEditor.GetGameViewAspectRatio() * num); }
private static float GetFrustumAspectRatio(Camera camera) { Rect rect = camera.rect; float result; if (rect.width <= 0f || rect.height <= 0f) { result = -1f; } else { float num = rect.width / rect.height; result = CameraEditor.GetGameViewAspectRatio() * num; } return(result); }
internal static void RenderGizmo(Camera camera) { Vector3[] array = new Vector3[4]; Vector3[] array2 = new Vector3[4]; float num; if (CameraEditor.GetFrustum(camera, array, array2, out num)) { Color color = Handles.color; Handles.color = CameraEditor.kGizmoCamera; for (int i = 0; i < 4; i++) { Handles.DrawLine(array[i], array[(i + 1) % 4]); Handles.DrawLine(array2[i], array2[(i + 1) % 4]); Handles.DrawLine(array[i], array2[i]); } Handles.color = color; } }
internal static void RenderGizmo(Camera camera) { Vector3[] near = new Vector3[4]; Vector3[] far = new Vector3[4]; float frustumAspect; if (!CameraEditor.GetFrustum(camera, near, far, out frustumAspect)) { return; } Color color = Handles.color; Handles.color = CameraEditor.kGizmoCamera; for (int index = 0; index < 4; ++index) { Handles.DrawLine(near[index], near[(index + 1) % 4]); Handles.DrawLine(far[index], far[(index + 1) % 4]); Handles.DrawLine(near[index], far[index]); } Handles.color = color; }
public void OnSceneGUI() { Camera target = (Camera)this.target; if (!CameraEditor.IsViewPortRectValidToRender(target.rect)) { return; } SceneViewOverlay.Window(new GUIContent("Camera Preview"), new SceneViewOverlay.WindowFunction(this.OnOverlayGUI), -100, this.target, SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget); Color color = Handles.color; Color kGizmoCamera = CameraEditor.kGizmoCamera; kGizmoCamera.a *= 2f; Handles.color = kGizmoCamera; Vector3[] far = new Vector3[4]; float frustumAspect; if (!CameraEditor.GetFrustum(target, (Vector3[])null, far, out frustumAspect)) { return; } Vector3 vector3_1 = far[0]; Vector3 vector3_2 = far[1]; Vector3 vector3_3 = far[2]; Vector3 vector3_4 = far[3]; bool flag = GUI.changed; Vector3 vector3_5 = Vector3.Lerp(vector3_1, vector3_3, 0.5f); float num = -1f; Vector3 vector3_6 = CameraEditor.MidPointPositionSlider(vector3_2, vector3_3, target.transform.up); if (!GUI.changed) { vector3_6 = CameraEditor.MidPointPositionSlider(vector3_1, vector3_4, -target.transform.up); } if (GUI.changed) { num = (vector3_6 - vector3_5).magnitude; } GUI.changed = false; Vector3 vector3_7 = CameraEditor.MidPointPositionSlider(vector3_4, vector3_3, target.transform.right); if (!GUI.changed) { vector3_7 = CameraEditor.MidPointPositionSlider(vector3_1, vector3_2, -target.transform.right); } if (GUI.changed) { num = (vector3_7 - vector3_5).magnitude / frustumAspect; } if ((double)num >= 0.0) { Undo.RecordObject((UnityEngine.Object)target, "Adjust Camera"); if (target.orthographic) { target.orthographicSize = num; } else { Vector3 vector3_8 = vector3_5 + target.transform.up * num; target.fieldOfView = Vector3.Angle(target.transform.forward, vector3_8 - target.transform.position) * 2f; } flag = true; } GUI.changed = flag; Handles.color = color; }