private void UpdateMotorType(ICameraMotorType motorType) { this.spCameraMotorType.objectReferenceValue = motorType; this.spCameraMotorType.objectReferenceValue.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy; this.cameraMotorEditor = (ICameraMotorTypeEditor)Editor.CreateEditor(this.spCameraMotorType.objectReferenceValue); serializedObject.ApplyModifiedProperties(); serializedObject.Update(); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (!this.cameraMotorEditor.ShowPreviewCamera()) { return; } if (UnityEngine.Event.current.type == EventType.Repaint) { if (this.previewRect != r) { Vector2 size1 = new Vector2(r.width, r.width / this.previewAR); Vector2 size2 = new Vector2(r.height * this.previewAR, r.height); float scale1 = Mathf.Min(r.width / size1.x, r.height / size1.y); float scale2 = Mathf.Min(r.width / size2.x, r.height / size2.y); Vector2 size = (scale1 < scale2 ? size1 * scale1 : size2 * scale2); this.previewTexture = new RenderTexture( (int)size.x * Mathf.CeilToInt(EditorGUIUtility.pixelsPerPoint), (int)size.y * Mathf.CeilToInt(EditorGUIUtility.pixelsPerPoint), 24, RenderTextureFormat.Default ); this.previewTexture.Create(); this.previewCamera.targetTexture = this.previewTexture; } this.previewCamera.transform.SetPositionAndRotation( this.cameraMotor.transform.position, this.cameraMotor.transform.rotation ); ICameraMotorType motorType = this.cameraMotor.cameraMotorType; bool orthographic = ( motorType.setCameraProperties && motorType.projection == ICameraMotorType.Projection.Orthographic ); this.previewCamera.orthographic = orthographic; this.previewCamera.orthographicSize = (orthographic && motorType.setCameraProperties ? motorType.cameraSize : 5f ); this.previewCamera.fieldOfView = (!orthographic && motorType.setCameraProperties ? motorType.fieldOfView : 60f ); this.previewCamera.Render(); GUI.DrawTexture(r, this.previewTexture, ScaleMode.ScaleToFit, false); } }
private void ChangeMotorType() { if (this.spCameraMotorType.objectReferenceValue != null) { DestroyImmediate(this.spCameraMotorType.objectReferenceValue); } Type type = this.cameraMotorsClasses.types[this.selectMotorIndex]; ICameraMotorType motorType = (ICameraMotorType)this.cameraMotor.gameObject.AddComponent(type); this.UpdateMotorType(motorType); this.cameraMotorEditor.OnCreate(this.cameraMotor.transform); }
private void UpdateProperties() { if (!this.currentCameraMotor.cameraMotorType.setCameraProperties) { return; } float elapsedTime = Mathf.Max(Time.time - this.transitionTime, 0.0f); float t = (this.transitionDuration <= 0.0f ? 1.0f : elapsedTime / this.transitionDuration); ICameraMotorType motor = this.currentCameraMotor.cameraMotorType; Camera cam = HookCamera.Instance.Get <Camera>(); bool orthographic = motor.projection == ICameraMotorType.Projection.Orthographic; if (orthographic != cam.orthographic || t >= 1.0f) { switch (orthographic) { case true: cam.orthographicSize = motor.cameraSize; break; case false: cam.fieldOfView = motor.fieldOfView; break; } cam.orthographic = orthographic; } else { switch (cam.orthographic) { case true: cam.orthographicSize = Mathf.Lerp( cam.orthographicSize, motor.cameraSize, t ); break; case false: cam.fieldOfView = Mathf.Lerp( cam.fieldOfView, motor.fieldOfView, t ); break; } } }
private void OnValidate() { if (this.cameraMotorType == null) { return; } if (this.cameraMotorType.gameObject.GetInstanceID() != this.gameObject.GetInstanceID()) { ICameraMotorType newCameraMotorType = gameObject.AddComponent( this.cameraMotorType.GetType() ) as ICameraMotorType; EditorUtility.CopySerialized(this.cameraMotorType, newCameraMotorType); SerializedObject serializedObject = new SerializedObject(this); serializedObject.FindProperty("cameraMotorType").objectReferenceValue = newCameraMotorType; serializedObject.ApplyModifiedPropertiesWithoutUndo(); } }