void StateData(vThirdPersonCameraState camState) { EditorGUILayout.Space(); camState.cameraMode = (TPCameraMode)EditorGUILayout.EnumPopup("Camera Mode", camState.cameraMode); camState.Name = EditorGUILayout.TextField("State Name", camState.Name); if (CheckName(camState.Name, tpCamera.indexList)) { EditorGUILayout.HelpBox("This name already exist, choose another one", MessageType.Error); } switch (camState.cameraMode) { case TPCameraMode.FreeDirectional: FreeDirectionalMode(camState); break; case TPCameraMode.FixedAngle: FixedAngleMode(camState); break; case TPCameraMode.FixedPoint: FixedPointMode(camState); break; } }
/// <summary> /// Copy of CameraStates /// </summary> /// <param name="to"></param> /// <param name="from"></param> public static void CopyState(this vThirdPersonCameraState to, vThirdPersonCameraState from) { to.Name = from.Name; to.forward = from.forward; to.right = from.right; to.defaultDistance = from.defaultDistance; to.maxDistance = from.maxDistance; to.minDistance = from.minDistance; to.height = from.height; to.fixedAngle = from.fixedAngle; to.lookPoints = from.lookPoints; to.smoothFollow = from.smoothFollow; to.xMouseSensitivity = from.xMouseSensitivity; to.yMouseSensitivity = from.yMouseSensitivity; to.yMinLimit = from.yMinLimit; to.yMaxLimit = from.yMaxLimit; to.xMinLimit = from.xMinLimit; to.xMaxLimit = from.xMaxLimit; to.rotationOffSet = from.rotationOffSet; to.cullingHeight = from.cullingHeight; to.cullingMinDist = from.cullingMinDist; to.cameraMode = from.cameraMode; to.useZoom = from.useZoom; to.fov = from.fov; }
/// <summary> /// Lerp between CameraStates /// </summary> /// <param name="to"></param> /// <param name="from"></param> /// <param name="time"></param> public static void Slerp(this vThirdPersonCameraState to, vThirdPersonCameraState from, float time) { to.Name = from.Name; to.forward = Mathf.Lerp(to.forward, from.forward, time); to.right = Mathf.Lerp(to.right, from.right, time); to.defaultDistance = Mathf.Lerp(to.defaultDistance, from.defaultDistance, time); to.maxDistance = Mathf.Lerp(to.maxDistance, from.maxDistance, time); to.minDistance = Mathf.Lerp(to.minDistance, from.minDistance, time); to.height = Mathf.Lerp(to.height, from.height, time); to.fixedAngle = Vector2.Lerp(to.fixedAngle, from.fixedAngle, time); to.smoothFollow = Mathf.Lerp(to.smoothFollow, from.smoothFollow, time); to.xMouseSensitivity = Mathf.Lerp(to.xMouseSensitivity, from.xMouseSensitivity, time); to.yMouseSensitivity = Mathf.Lerp(to.yMouseSensitivity, from.yMouseSensitivity, time); to.yMinLimit = Mathf.Lerp(to.yMinLimit, from.yMinLimit, time); to.yMaxLimit = Mathf.Lerp(to.yMaxLimit, from.yMaxLimit, time); to.xMinLimit = Mathf.Lerp(to.xMinLimit, from.xMinLimit, time); to.xMaxLimit = Mathf.Lerp(to.xMaxLimit, from.xMaxLimit, time); to.rotationOffSet = Vector3.Lerp(to.rotationOffSet, from.rotationOffSet, time); to.cullingHeight = Mathf.Lerp(to.cullingHeight, from.cullingHeight, time); to.cullingMinDist = Mathf.Lerp(to.cullingMinDist, from.cullingMinDist, time); to.cameraMode = from.cameraMode; to.useZoom = from.useZoom; to.lookPoints = from.lookPoints; to.fov = Mathf.Lerp(to.fov, from.fov, time); }
void FixedPointMode(vThirdPersonCameraState camState) { camState.smoothFollow = EditorGUILayout.FloatField("Smooth Follow", camState.smoothFollow); camState.fov = EditorGUILayout.Slider("Field of View", camState.fov, 1, 179); camState.fixedAngle.x = 0; camState.fixedAngle.y = 0; DrawLookPoint(camState); }
/// <summary> /// Change CameraState /// </summary> /// <param name="stateName"></param> /// <param name="Use smoth"></param> public void ChangeState(string stateName, bool hasSmooth) { if (currentState != null && currentState.Name.Equals(stateName)) { return; } // search for the camera state string name vThirdPersonCameraState state = CameraStateList != null?CameraStateList.tpCameraStates.Find(delegate(vThirdPersonCameraState obj) { return(obj.Name.Equals(stateName)); }) : new vThirdPersonCameraState("Default"); if (state != null) { currentStateName = stateName; currentState.cameraMode = state.cameraMode; lerpState = state; // set the state of transition (lerpstate) to the state finded on the list // in case there is no smooth, a copy will be make without the transition values if (currentState != null && !hasSmooth) { currentState.CopyState(state); } } else { // if the state choosed if not real, the first state will be set up as default if (CameraStateList != null && CameraStateList.tpCameraStates.Count > 0) { state = CameraStateList.tpCameraStates[0]; currentStateName = state.Name; currentState.cameraMode = state.cameraMode; lerpState = state; if (currentState != null && !hasSmooth) { currentState.CopyState(state); } } } // in case a list of states does not exist, a default state will be created if (currentState == null) { currentState = new vThirdPersonCameraState("Null"); currentStateName = currentState.Name; } if (CameraStateList != null) { indexList = CameraStateList.tpCameraStates.IndexOf(state); } currentZoom = state.defaultDistance; currentState.fixedAngle = new Vector3(mouseX, mouseY); useSmooth = hasSmooth; indexLookPoint = 0; }
void FixedAngleMode(vThirdPersonCameraState camState) { camState.defaultDistance = EditorGUILayout.FloatField("Distance", camState.defaultDistance); camState.useZoom = EditorGUILayout.Toggle("Use Zoom", camState.useZoom); if (camState.useZoom) { camState.maxDistance = EditorGUILayout.FloatField("Max Distance", camState.maxDistance); camState.minDistance = EditorGUILayout.FloatField("Min Distance", camState.minDistance); } camState.height = EditorGUILayout.FloatField("Height", camState.height); camState.fov = EditorGUILayout.Slider("Field of View", camState.fov, 1, 179); camState.smoothFollow = EditorGUILayout.FloatField("Smooth Follow", camState.smoothFollow); camState.cullingHeight = EditorGUILayout.FloatField("Culling Height", camState.cullingHeight); camState.right = EditorGUILayout.Slider("Right", camState.right, -3f, 3f); camState.fixedAngle.x = EditorGUILayout.Slider("Angle X", camState.fixedAngle.x, -360, 360); camState.fixedAngle.y = EditorGUILayout.Slider("Angle Y", camState.fixedAngle.y, -360, 360); }
void FreeDirectionalMode(vThirdPersonCameraState camState) { camState.forward = (float)((int)EditorGUILayout.Slider("Forward", camState.forward, -1f, 1f)); camState.right = EditorGUILayout.Slider("Right", camState.right, -3f, 3f); camState.defaultDistance = EditorGUILayout.FloatField("Distance", camState.defaultDistance); camState.useZoom = EditorGUILayout.Toggle("Use Zoom", camState.useZoom); if (camState.useZoom) { camState.maxDistance = EditorGUILayout.FloatField("Max Distance", camState.maxDistance); camState.minDistance = EditorGUILayout.FloatField("Min Distance", camState.minDistance); } camState.height = EditorGUILayout.FloatField("Height", camState.height); camState.fov = EditorGUILayout.Slider("Field of View", camState.fov, 1, 179); camState.smoothFollow = EditorGUILayout.FloatField("Smooth Follow", camState.smoothFollow); camState.cullingHeight = EditorGUILayout.FloatField("Culling Height", camState.cullingHeight); camState.rotationOffSet = EditorGUILayout.Vector3Field("Rotation OffSet", camState.rotationOffSet); camState.xMouseSensitivity = EditorGUILayout.FloatField("MouseSensitivity X", camState.xMouseSensitivity); camState.yMouseSensitivity = EditorGUILayout.FloatField("MouseSensitivity Y", camState.yMouseSensitivity); MinMaxSlider("Limit Angle X", ref camState.xMinLimit, ref camState.xMaxLimit, -360, 360); MinMaxSlider("Limit Angle Y", ref camState.yMinLimit, ref camState.yMaxLimit, -180, 180); }
void DrawLookPoint(vThirdPersonCameraState camState) { if (camState.lookPoints == null) { camState.lookPoints = new List <LookPoint>(); } if (camState.lookPoints.Count > 0) { EditorGUILayout.HelpBox("You can create multiple camera points and change them using the TriggerChangeCameraState script.", MessageType.Info); if (tpCamera.indexLookPoint > camState.lookPoints.Count - 1) { tpCamera.indexLookPoint = 0; } if (tpCamera.indexLookPoint < 0) { tpCamera.indexLookPoint = camState.lookPoints.Count - 1; } GUILayout.BeginHorizontal("box"); GUILayout.Label("Fixed Points"); GUILayout.FlexibleSpace(); if (GUILayout.Button("<", GUILayout.Width(20))) { if (tpCamera.indexLookPoint - 1 < 0) { tpCamera.indexLookPoint = camState.lookPoints.Count - 1; } else { tpCamera.indexLookPoint--; } tpCamera.transform.position = camState.lookPoints[tpCamera.indexLookPoint].positionPoint; tpCamera.transform.rotation = Quaternion.Euler(camState.lookPoints[tpCamera.indexLookPoint].eulerAngle); indexSelected = tpCamera.indexLookPoint; } GUILayout.Box((tpCamera.indexLookPoint + 1).ToString("00") + "/" + camState.lookPoints.Count.ToString("00")); if (GUILayout.Button(">", GUILayout.Width(20))) { if (tpCamera.indexLookPoint + 1 > camState.lookPoints.Count - 1) { tpCamera.indexLookPoint = 0; } else { tpCamera.indexLookPoint++; } tpCamera.transform.position = camState.lookPoints[tpCamera.indexLookPoint].positionPoint; tpCamera.transform.rotation = Quaternion.Euler(camState.lookPoints[tpCamera.indexLookPoint].eulerAngle); indexSelected = tpCamera.indexLookPoint; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal("box"); GUILayout.Label("Point Name"); camState.lookPoints[tpCamera.indexLookPoint].pointName = GUILayout.TextField(camState.lookPoints[tpCamera.indexLookPoint].pointName, 100); GUILayout.EndHorizontal(); EditorGUILayout.HelpBox("Check 'Static Camera' to create a static point and leave uncheck to look at the Player.", MessageType.Info); camState.lookPoints[tpCamera.indexLookPoint].freeRotation = EditorGUILayout.Toggle("Static Camera", camState.lookPoints[tpCamera.indexLookPoint].freeRotation); EditorGUILayout.Space(); } GUILayout.BeginHorizontal("box"); if (GUILayout.Button("New Point")) { LookPoint p = new LookPoint(); p.pointName = "point_" + (camState.lookPoints.Count + 1).ToString("00"); p.positionPoint = tpCamera.transform.position; p.eulerAngle = (tpCamera.target) ? tpCamera.target.position : (tpCamera.transform.position + tpCamera.transform.forward); camState.lookPoints.Add(p); tpCamera.indexLookPoint = camState.lookPoints.Count - 1; tpCamera.transform.position = camState.lookPoints[tpCamera.indexLookPoint].positionPoint; indexSelected = tpCamera.indexLookPoint; } if (GUILayout.Button("Remove current point ")) { if (camState.lookPoints.Count > 0) { camState.lookPoints.RemoveAt(tpCamera.indexLookPoint); tpCamera.indexLookPoint--; if (tpCamera.indexLookPoint > camState.lookPoints.Count - 1) { tpCamera.indexLookPoint = 0; } if (tpCamera.indexLookPoint < 0) { tpCamera.indexLookPoint = camState.lookPoints.Count - 1; } if (camState.lookPoints.Count > 0) { tpCamera.transform.position = camState.lookPoints[tpCamera.indexLookPoint].positionPoint; } indexSelected = tpCamera.indexLookPoint; } } GUILayout.EndHorizontal(); EditorGUILayout.Space(); }
/// <summary> /// Change CameraState /// </summary> /// <param name="stateName"></param> /// <param name="Use smoth"></param> public void ChangeState(string stateName, bool hasSmooth) { if (currentState != null && currentState.Name.Equals(stateName) || !isInit && firstStateIsInit) { if (firstStateIsInit) { useSmooth = hasSmooth; } return; } useSmooth = !firstStateIsInit ? startSmooth : hasSmooth; // search for the camera state string name vThirdPersonCameraState state = CameraStateList != null?CameraStateList.tpCameraStates.Find(delegate(vThirdPersonCameraState obj) { return(obj.Name.Equals(stateName)); }) : new vThirdPersonCameraState("Default"); if (state != null) { currentStateName = stateName; currentState.cameraMode = state.cameraMode; lerpState = state; // set the state of transition (lerpstate) to the state finded on the list if (!firstStateIsInit) { currentState.defaultDistance = Vector3.Distance(targetLookAt.position, transform.position); currentState.forward = lerpState.forward; currentState.height = state.height; currentState.fov = state.fov; if (useSmooth) { StartCoroutine(ResetFirstState()); } else { distance = lerpState.defaultDistance; firstStateIsInit = true; } } // in case there is no smooth, a copy will be make without the transition values if (currentState != null && !useSmooth) { currentState.CopyState(state); } } else { // if the state choosed if not real, the first state will be set up as default if (CameraStateList != null && CameraStateList.tpCameraStates.Count > 0) { state = CameraStateList.tpCameraStates[0]; currentStateName = state.Name; currentState.cameraMode = state.cameraMode; lerpState = state; if (currentState != null && !useSmooth) { currentState.CopyState(state); } } } // in case a list of states does not exist, a default state will be created if (currentState == null) { currentState = new vThirdPersonCameraState("Null"); currentStateName = currentState.Name; } if (CameraStateList != null) { indexList = CameraStateList.tpCameraStates.IndexOf(state); } currentZoom = state.defaultDistance; if (currentState.cameraMode == TPCameraMode.FixedAngle) { mouseX = currentState.fixedAngle.x; mouseY = currentState.fixedAngle.y; } currentState.fixedAngle = new Vector3(mouseX, mouseY); indexLookPoint = 0; if (!isInit) { CameraMovement(true); } }