private static void SetupToolbar() { int menuType = 0; CameraPathAnimator.orientationModes orientationMode; orientationMode = (_animator != null) ? _animator.orientationMode : CameraPathAnimator.orientationModes.none; switch (orientationMode) { case CameraPathAnimator.orientationModes.custom: menuType = 1; break; case CameraPathAnimator.orientationModes.followpath: menuType = 2; break; case CameraPathAnimator.orientationModes.reverseFollowpath: menuType = 2; break; default: menuType = 0; break; } int menuLengthA = 0; int menuLengthB = 0; string[] menuStringA = new string[0]; string[] menuStringB = new string[0]; Texture2D[] toolbarTexturesA = new Texture2D[0]; Texture2D[] toolbarTexturesB = new Texture2D[0]; switch (menuType) { default: menuLengthA = 4; menuLengthB = 4; menuStringA = new[] { "Path Points", "Control Points", "FOV", "Speed" }; menuStringB = new[] { "Delays", "Ease", "Events", "Options" }; toolbarTexturesA = new Texture2D[menuLengthA]; toolbarTexturesB = new Texture2D[menuLengthB]; toolbarTexturesA[0] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/pathpoints.png", typeof(Texture2D)); toolbarTexturesA[1] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/controlpoints.png", typeof(Texture2D)); toolbarTexturesA[2] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/fov.png", typeof(Texture2D)); toolbarTexturesA[3] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/speed.png", typeof(Texture2D)); toolbarTexturesB[0] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/delay.png", typeof(Texture2D)); toolbarTexturesB[1] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/easecurves.png", typeof(Texture2D)); toolbarTexturesB[2] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/events.png", typeof(Texture2D)); toolbarTexturesB[3] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/options.png", typeof(Texture2D)); break; case 1: menuLengthA = 4; menuLengthB = 5; menuStringA = new[] { "Path Points", "Control Points", "FOV", "Speed" }; menuStringB = new[] { "Delays", "Ease", "Events", "Orientations", "Options" }; toolbarTexturesA = new Texture2D[menuLengthA]; toolbarTexturesB = new Texture2D[menuLengthB]; toolbarTexturesA[0] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/pathpoints.png", typeof(Texture2D)); toolbarTexturesA[1] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/controlpoints.png", typeof(Texture2D)); toolbarTexturesA[2] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/fov.png", typeof(Texture2D)); toolbarTexturesA[3] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/speed.png", typeof(Texture2D)); toolbarTexturesB[0] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/delay.png", typeof(Texture2D)); toolbarTexturesB[1] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/easecurves.png", typeof(Texture2D)); toolbarTexturesB[2] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/events.png", typeof(Texture2D)); toolbarTexturesB[3] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/orientation.png", typeof(Texture2D)); toolbarTexturesB[4] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/options.png", typeof(Texture2D)); break; case 2: menuLengthA = 4; menuLengthB = 5; menuStringA = new[] { "Path Points", "Control Points", "FOV", "Speed" }; menuStringB = new[] { "Delays", "Ease", "Events", "Tilt", "Options" }; toolbarTexturesA = new Texture2D[menuLengthA]; toolbarTexturesB = new Texture2D[menuLengthB]; toolbarTexturesA[0] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/pathpoints.png", typeof(Texture2D)); toolbarTexturesA[1] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/controlpoints.png", typeof(Texture2D)); toolbarTexturesA[2] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/fov.png", typeof(Texture2D)); toolbarTexturesA[3] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/speed.png", typeof(Texture2D)); toolbarTexturesB[0] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/delay.png", typeof(Texture2D)); toolbarTexturesB[1] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/easecurves.png", typeof(Texture2D)); toolbarTexturesB[2] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/events.png", typeof(Texture2D)); toolbarTexturesB[3] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/tilt.png", typeof(Texture2D)); toolbarTexturesB[4] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/CameraPath3/Icons/options.png", typeof(Texture2D)); break; } _toolBarGUIContentA = new GUIContent[menuLengthA]; for (int i = 0; i < menuLengthA; i++) _toolBarGUIContentA[i] = new GUIContent(toolbarTexturesA[i], menuStringA[i]); _toolBarGUIContentB = new GUIContent[menuLengthB]; for (int i = 0; i < menuLengthB; i++) _toolBarGUIContentB[i] = new GUIContent(toolbarTexturesB[i], menuStringB[i]); if (_animator != null) _orientationmode = _animator.orientationMode; }
public override void OnInspectorGUI() { if (_cameraPath.transform.rotation != Quaternion.identity) { EditorGUILayout.HelpBox("Camera Path does not support rotations of the main game object.", MessageType.Error); if (GUILayout.Button("Reset Rotation")) { _cameraPath.transform.rotation = Quaternion.identity; } return; } Undo.RecordObject(_animator, "Modified Animator"); bool noPath = _cameraPath.realNumberOfPoints < 2; EditorGUILayout.BeginVertical(GUILayout.Width(400)); RenderPreview(); bool isFollowingTargetTransform = _animator.orientationMode == CameraPathAnimator.orientationModes.followTransform; if (isFollowingTargetTransform) { EditorGUILayout.HelpBox("The Follow Transform mode animates the object to the closest point on the path so it is not based on time.", MessageType.Info); } EditorGUI.BeginDisabledGroup(isFollowingTargetTransform); EditorGUILayout.BeginHorizontal(); float inputPercent = _animator.editorPercentage * 100; float outputPercent = EditorGUILayout.Slider(inputPercent, 0, 100) * 0.01f; _animator.editorPercentage = outputPercent; EditorGUILayout.LabelField("%", GUILayout.Width(20)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (_cameraPath.normalised) { EditorGUILayout.LabelField("Normalised Percentage Value: " + (_cameraPath.CalculateNormalisedPercentage(outputPercent) * 100).ToString("F1") + "%"); } EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); AnimateInEditor(); //Get animation values and apply them to the preview camera _previewCamPos = _cameraPath.GetPathPosition(_animator.editorPercentage); _previewCamRot = _animator.GetAnimatedOrientation(_animator.editorPercentage, false); //ANIMATION TARGETS EditorGUILayout.BeginVertical("Box"); if (_animator.animationObject == null) { EditorGUILayout.HelpBox("Animation has no target to animate", MessageType.Error); } _animator.animationObject = (Transform)EditorGUILayout.ObjectField("Animate Object", _animator.animationObject, typeof(Transform), true); if (_animator.animationObject != null) { Rigidbody[] rigidBodies = _animator.animationObject.GetComponentsInChildren <Rigidbody>(); if (rigidBodies.Length > 0) { EditorGUILayout.HelpBox("Animation target object contains Rigidbodies. These could produce stuttering animations unless you select 'isKinematic' in the Rigidbody options.", MessageType.Warning); } } if (_animator.orientationMode == CameraPathAnimator.orientationModes.followTransform || _animator.orientationMode == CameraPathAnimator.orientationModes.target) { if (_animator.orientationTarget == null) { EditorGUILayout.HelpBox("Orientation target is null", MessageType.Error); } _animator.orientationTarget = (Transform)EditorGUILayout.ObjectField("Orientation CameraPathOnRailsTarget", _animator.orientationTarget, typeof(Transform), true); _animator.targetModeUp = EditorGUILayout.Vector3Field("Up Vector", _animator.targetModeUp); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Animate Scene Object in Editor"); _animator.animateSceneObjectInEditor = EditorGUILayout.Toggle(_animator.animateSceneObjectInEditor); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //ANIMATION SETTINGS EditorGUILayout.BeginVertical("Box"); _animator.playOnStart = EditorGUILayout.Toggle("Play on start", _animator.playOnStart); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Start Percent", GUILayout.Width(80)); float startPercent = _animator.startPercent * 100; startPercent = EditorGUILayout.Slider(startPercent, 0, 100); _animator.startPercent = startPercent / 100; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Animation Mode"); CameraPathAnimator.animationModes newAnimMode = (CameraPathAnimator.animationModes)EditorGUILayout.EnumPopup(_animator.animationMode); EditorGUILayout.EndHorizontal(); if (newAnimMode != _animator.animationMode) { _animator.animationMode = newAnimMode; _cameraPath.RecalculateStoredValues(); // EditorUtility.SetDirty(_cameraPath); // EditorUtility.SetDirty(_animator); } //Help texts explaining the animation modes switch (_animator.animationMode) { case CameraPathAnimator.animationModes.once: EditorGUILayout.HelpBox("The animation will run once through, begining at the start of the path and terminating at the end.", MessageType.None); break; case CameraPathAnimator.animationModes.loop: EditorGUILayout.HelpBox("The animation will run continuously, restarting from the beginning once it reaches the end.", MessageType.None); break; case CameraPathAnimator.animationModes.pingPong: EditorGUILayout.HelpBox("The animation will run continuously, reversing the direction of the animation when it reaches the end or start of the path.", MessageType.None); break; case CameraPathAnimator.animationModes.reverse: EditorGUILayout.HelpBox("The animation will run once through, starting at the end and finishing at the start.", MessageType.None); break; case CameraPathAnimator.animationModes.reverseLoop: EditorGUILayout.HelpBox("The animation will run continuously from end to start of the path and restarting once complete.", MessageType.None); break; case CameraPathAnimator.animationModes.still: EditorGUILayout.HelpBox("The animation will run for a set amount of time but the target will not move from position.", MessageType.None); break; } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Orientation Mode"); CameraPathAnimator.orientationModes newOrinMode = (CameraPathAnimator.orientationModes)EditorGUILayout.EnumPopup(_animator.orientationMode); EditorGUILayout.EndHorizontal(); if (newOrinMode != _animator.orientationMode) { // if(newOrinMode == CameraPathAnimator.orientationModes.twoDimentions) // { // if(EditorUtility.DisplayDialog("Switch to 2D", "Do you want to reset the FOV points to reflect the current orthographic size?", "yes", "no")) // { // int fovPoints = _cameraPath.fovList.realNumberOfPoints; // float orthSize = (_animator.isCamera) ? _animator.animationObject.GetComponent<Camera>().orthographicSize : 10; // for(int i = 0; i < fovPoints; i++) // _cameraPath.fovList[i].FOV = orthSize; // } // } // // if(_animator.orientationMode == CameraPathAnimator.orientationModes.twoDimentions) // { // if (EditorUtility.DisplayDialog("Switch to 3D", "Do you want to reset the FOV points to reflect the current camera field of view?", "yes", "no")) // { // int fovPoints = _cameraPath.fovList.realNumberOfPoints; // float fov = (_animator.isCamera) ? _animator.animationObject.GetComponent<Camera>().fieldOfView : 60; // for (int i = 0; i < fovPoints; i++) // _cameraPath.fovList[i].FOV = fov; // } // } _animator.orientationMode = newOrinMode; _cameraPath.pointMode = CameraPath.PointModes.Transform; _cameraPath.RecalculateStoredValues(); // EditorUtility.SetDirty(_cameraPath); // EditorUtility.SetDirty(_animator); GUI.changed = true; } //Help texts explaining the orienation modes switch (_animator.orientationMode) { case CameraPathAnimator.orientationModes.custom: EditorGUILayout.HelpBox("The orientation of the animated object will follow the custom rotations set out in the path.", MessageType.None); break; case CameraPathAnimator.orientationModes.followTransform: EditorGUILayout.HelpBox("The orientation of the animated object will always face the specified target and will position itself at the nearest point on the path to the target object.", MessageType.None); break; case CameraPathAnimator.orientationModes.followpath: EditorGUILayout.HelpBox("The orientation will match the direction the path is taking from its current position.", MessageType.None); break; case CameraPathAnimator.orientationModes.mouselook: EditorGUILayout.HelpBox("The orientation will be controlled by the user at runtime using the mouse.", MessageType.None); break; case CameraPathAnimator.orientationModes.reverseFollowpath: EditorGUILayout.HelpBox("The orientation will match the reverse direction of the path at its current position.", MessageType.None); break; case CameraPathAnimator.orientationModes.target: EditorGUILayout.HelpBox("The orientation of the animated object will always face the specified target.", MessageType.None); break; case CameraPathAnimator.orientationModes.twoDimentions: EditorGUILayout.HelpBox("The orientation of the animated object will remain facing the Z for a 2D animation.", MessageType.None); break; case CameraPathAnimator.orientationModes.fixedOrientation: EditorGUILayout.HelpBox("The orientation of the animated object will remain at the fixed rotation you specify.", MessageType.None); break; case CameraPathAnimator.orientationModes.none: EditorGUILayout.HelpBox("The orientation of the animated object will not be modified.", MessageType.None); break; } EditorGUILayout.EndVertical(); if (_animator.animationMode != CameraPathAnimator.animationModes.still) { //NORMALISATION EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); _animator.normalised = EditorGUILayout.Toggle("Normalised Path", _animator.normalised); EditorGUILayout.HelpBox("Set this if you want to start another camera path animation once this has completed", MessageType.Info); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Box"); bool usingSpeed = _cameraPath.speedList.listEnabled; if (usingSpeed || noPath) { EditorGUILayout.HelpBox("Using path based speed values.", MessageType.Info); } EditorGUI.BeginDisabledGroup(usingSpeed); EditorGUI.BeginDisabledGroup(noPath); EditorGUILayout.BeginHorizontal(); float newPathSpeed = EditorGUILayout.FloatField("Animation Speed", _animator.pathSpeed); if (!noPath && !usingSpeed) { _animator.pathSpeed = newPathSpeed; } EditorGUILayout.LabelField("m/sec", GUILayout.Width(25)); EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); EditorGUI.EndDisabledGroup(); } else { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); _animator.animationTime = EditorGUILayout.FloatField("Animation Time", _animator.animationTime); EditorGUILayout.LabelField("sec", GUILayout.Width(25)); EditorGUILayout.EndHorizontal(); } if (!_cameraPath.speedList.listEnabled) { if (_cameraPath.storedPointResolution > _animator.pathSpeed / 10) { EditorGUILayout.HelpBox("The current stored point resolution is possibly too high. Lower it to less than the speed you're using in the options tab", MessageType.Error); } } else { if (_cameraPath.storedPointResolution > _cameraPath.speedList.GetLowesetSpeed() / 10) { EditorGUILayout.HelpBox("The current stored point resolution is possibly too high. Lower it to less than the lowest speed you're using in the options tab", MessageType.Error); } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); if (_animator.orientationMode == CameraPathAnimator.orientationModes.mouselook) { EditorGUILayout.HelpBox("Alter the mouse sensitivity here", MessageType.Info); _animator.sensitivity = EditorGUILayout.Slider("Mouse Sensitivity", _animator.sensitivity, 0.1f, 2.0f); EditorGUILayout.HelpBox("Restrict the vertical viewable area here.", MessageType.Info); EditorGUILayout.LabelField("Mouse Y Restriction"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(((int)_animator.minX).ToString("F1"), GUILayout.Width(30)); EditorGUILayout.MinMaxSlider(ref _animator.minX, ref _animator.maxX, -180, 180); EditorGUILayout.LabelField(((int)_animator.maxX).ToString("F1"), GUILayout.Width(30)); EditorGUILayout.EndHorizontal(); } if (_animator.orientationMode == CameraPathAnimator.orientationModes.fixedOrientation) { EditorGUILayout.HelpBox("The Orientation will be fixed on this direction", MessageType.Info); _animator.fixedOrientaion = EditorGUILayout.Vector3Field("Fixed Orientation Direction", _animator.fixedOrientaion); } if (GUI.changed) { UpdateGui(); } EditorGUILayout.EndVertical(); }
public Quaternion GetOrientation(CameraPathAnimator.orientationModes mode, float percent, bool ignoreNormalisation) { Quaternion quaternion = Quaternion.get_identity(); switch (mode) { case CameraPathAnimator.orientationModes.custom: quaternion = this.cameraPath.GetPathRotation(percent, ignoreNormalisation); break; case CameraPathAnimator.orientationModes.target: { Vector3 pathPosition = this.cameraPath.GetPathPosition(percent); Vector3 vector; if (this.orientationTarget != null) { vector = this.orientationTarget.get_transform().get_position() - pathPosition; } else { vector = Vector3.get_forward(); } quaternion = Quaternion.LookRotation(vector, this.targetModeUp); break; } case CameraPathAnimator.orientationModes.mouselook: if (!Application.get_isPlaying()) { quaternion = Quaternion.LookRotation(this.cameraPath.GetPathDirection(percent)); quaternion *= Quaternion.Euler(base.get_transform().get_forward() * -this.cameraPath.GetPathTilt(percent)); } else { quaternion = Quaternion.LookRotation(this.cameraPath.GetPathDirection(percent)); quaternion *= this.GetMouseLook(); } break; case CameraPathAnimator.orientationModes.followpath: quaternion = Quaternion.LookRotation(this.cameraPath.GetPathDirection(percent)); quaternion *= Quaternion.Euler(base.get_transform().get_forward() * -this.cameraPath.GetPathTilt(percent)); break; case CameraPathAnimator.orientationModes.reverseFollowpath: quaternion = Quaternion.LookRotation(-this.cameraPath.GetPathDirection(percent)); quaternion *= Quaternion.Euler(base.get_transform().get_forward() * -this.cameraPath.GetPathTilt(percent)); break; case CameraPathAnimator.orientationModes.followTransform: { if (this.orientationTarget == null) { return(Quaternion.get_identity()); } float num = this.cameraPath.GetNearestPoint(this.orientationTarget.get_position()); num = Mathf.Clamp01(num + this.nearestOffset); Vector3 pathPosition = this.cameraPath.GetPathPosition(num); Vector3 vector = this.orientationTarget.get_transform().get_position() - pathPosition; quaternion = Quaternion.LookRotation(vector); break; } case CameraPathAnimator.orientationModes.twoDimentions: quaternion = Quaternion.LookRotation(Vector3.get_forward()); break; case CameraPathAnimator.orientationModes.fixedOrientation: quaternion = Quaternion.LookRotation(this.fixedOrientaion); break; case CameraPathAnimator.orientationModes.none: quaternion = this.animationObject.get_rotation(); break; } return(quaternion); }