/// <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; }
/// <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); } }