예제 #1
0
        /// <summary>
        /// Lerp between CameraStates
        /// </summary>
        /// <param name="to"></param>
        /// <param name="from"></param>
        /// <param name="time"></param>
        public static void Slerp(this ThirdPersonCameraState to, ThirdPersonCameraState 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);

            if (to.fov <= 0)
            {
                to.fov = 1f;
            }
        }
예제 #2
0
        /// <summary>
        /// Change State using look at point if the cameraMode is FixedPoint
        /// </summary>
        /// <param name="stateName"></param>
        /// <param name="pointName"></param>
        /// <param name="hasSmooth"></param>
        public void ChangeState(string stateName, string pointName, bool hasSmooth)
        {
            useSmooth = hasSmooth;
            if (!currentState.Name.Equals(stateName))
            {
                // search for the camera state string name
                var state = CameraStateList.tpCameraStates.Find(obj => obj.Name.Equals(stateName));

                if (state != null)
                {
                    currentStateName        = stateName;
                    currentState.cameraMode = state.cameraMode;
                    transitionState         = state; // set the state of transition (lerpstate) to the state found 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.tpCameraStates.Count > 0)
                    {
                        state                   = CameraStateList.tpCameraStates[0];
                        currentStateName        = state.Name;
                        currentState.cameraMode = state.cameraMode;
                        transitionState         = 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 ThirdPersonCameraState("Null");
                    currentStateName = currentState.Name;
                }

                indexList               = CameraStateList.tpCameraStates.IndexOf(state);
                currentZoom             = state.defaultDistance;
                currentState.fixedAngle = new Vector3(mouseX, mouseY);
                indexLookPoint          = 0;
            }

            if (currentState.cameraMode == TPCameraMode.FixedPoint)
            {
                var point = currentState.lookPoints.Find(obj => obj.pointName.Equals(pointName));
                if (point != null)
                {
                    indexLookPoint = currentState.lookPoints.IndexOf(point);
                }
                else
                {
                    indexLookPoint = 0;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Copy of CameraStates
        /// </summary>
        /// <param name="to"></param>
        /// <param name="from"></param>
        public static void CopyState(this ThirdPersonCameraState to, ThirdPersonCameraState 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;

            if (to.fov <= 0)
            {
                to.fov = 1f;
            }
        }
예제 #4
0
        /// <summary>
        /// Change CameraState
        /// </summary>
        /// <param name="desiredStateName"></param>
        /// <param name="Use smooth"></param>
        public void ChangeState(string desiredStateName, bool hasSmooth)
        {
            useSmooth = (!firstStateIsInit || currentState != null && !currentState.Name.Equals(desiredStateName) || isInit) ? startSmooth : hasSmooth;
            // search for the camera state string name
            ThirdPersonCameraState state = CameraStateList != null?CameraStateList.tpCameraStates.Find(obj => obj.Name.Equals(desiredStateName)) : new ThirdPersonCameraState("Default");

            //If we find the state in the list, then determine if we need to smooth and then set the current state to it.
            if (state != null)
            {
                currentStateName        = desiredStateName;
                currentState.cameraMode = state.cameraMode;
                transitionState         = state; // set the state of transition (lerpstate) to the state found on the list
                if (!firstStateIsInit)
                {
                    currentState.defaultDistance = Vector3.Distance(targetLookAt.position, transform.position);
                    currentState.height          = state.height;
                    currentState.fov             = state.fov;
                    StartCoroutine(ResetFirstState()); // sets firstStateIsInit to true at the end of the frame
                }
                // in case there is no smooth, a copy will be made without the transition values
                if (currentState != null && !useSmooth)
                {
                    currentState.CopyState(state);
                }
            }
            else
            {
                // if we can't find the chosen state, 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;
                    transitionState         = 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 ThirdPersonCameraState("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;
        }