public override void Apply(float blend, EB.Director.Serialization.KeyFrame from, EB.Director.Serialization.KeyFrame to) { if (_parent.IsPaused || DirectorInformation.Paused) { return; } if (_target.GetComponent <Camera>() == null) { _target = _target.GetComponentInChildren <Camera>().gameObject; } if (DirectorInformation.LerpToNextCamera && Application.isPlaying) { _parent.PlayTime = 0f; timeToLerp = DirectorInformation.LerpTime; if (timer < timeToLerp) { timer += Time.deltaTime; float easeInOutValue = EZAnimation.sinusInOut(timer, 0.0f, 1.0f, timeToLerp); var v = Mathf.Lerp(DirectorInformation.LastFOV, from.FloatValue, easeInOutValue); _target.GetComponent <Camera>().fieldOfView = v; DirectorInformation.LastFOV = v; if (timer > timeToLerp) { _target.GetComponent <Camera>().fieldOfView = from.FloatValue; } } return; } if (_target != null && _target.GetComponent <Camera>() != null && !DirectorInformation.LerpToNextCamera) { var v1 = from.FloatValue; var v2 = to.FloatValue; var v = Mathf.Lerp(v1, v2, blend); if (v == 0) { v = 45f; } _target.GetComponent <Camera>().fieldOfView = v; DirectorInformation.LastFOV = v; } }
public static float Blend(EB.Director.BlendMode mode, float t) { switch (mode) { case BlendMode.Cut: { t = 0.0f; // do the cut } break; case BlendMode.EaseIn: { t = EZAnimation.sinusOut(t, 0, 1, 1); } break; case BlendMode.EaseOut: { t = EZAnimation.sinusIn(t, 0, 1, 1); } break; case BlendMode.CubicIn: { t = EZAnimation.cubicIn(t, 0, 1, 1); } break; case BlendMode.CubicOut: { t = EZAnimation.cubicOut(t, 0, 1, 1); } break; case BlendMode.EaseOutIn: { t = EZAnimation.sinusInOut(t, 0, 1, 1); } break; case BlendMode.EaseInOut: { t = EZAnimation.sinusOutIn(t, 0, 1, 1); } break; case BlendMode.CubicInOut: { t = EZAnimation.cubicInOut(t, 0, 1, 1); } break; case BlendMode.CubicOutIn: { t = EZAnimation.cubicOutIn(t, 0, 1, 1); } break; default: // linear break; } return(t); }
public override void Apply(float blend, EB.Director.Serialization.KeyFrame from, EB.Director.Serialization.KeyFrame to) { //EB.Debug.Log("CHECKING: " + _parent.name + " FOR PAUSED"); if (_parent.IsPaused || DirectorInformation.Paused) { return; } //Debug.Log("INSIDE THE DIRECTOR"); if (_playerCar == null) { // ignore cameras Transform playerLocator = GameObject.Find("LOCATOR_PLAYER").transform; int childCount = playerLocator.childCount; for (int i = 0; i < childCount; ++i) { Transform child = playerLocator.GetChild(i); if (child.GetComponent <Camera>() == null) { _playerCar = child.gameObject; break; } } } //EB.Debug.Log("PLAYER CAR EXISTS"); // Set parent to local to world in correct location --- THIS ONLY HAPPENS ONCE if (_target.name == "Director Camera" && frame == 0) { // Only happen if it's the first frame and we're sure this director is supposed to be local to world if (_track.space == SpaceType.LocalToWorld) { if (!DirectorInformation.LocalToWorldDirectors.Contains(_parent)) { DirectorInformation.LocalToWorldDirectors.Add(_parent); } // Find the player car and locator GameObject localToWorldLocator = GameObject.Find("localToWorldLocator"); // If the locator doesn't exist, create it if (localToWorldLocator == null) { localToWorldLocator = new GameObject("localToWorldLocator"); } // Set the position & rotation of the locator to that of the player car localToWorldLocator.transform.position = _playerCar.transform.position; localToWorldLocator.transform.eulerAngles = _playerCar.transform.eulerAngles; // If the camera isn't already a child of the locator, make it so if (_target.transform.parent != localToWorldLocator.transform) { localToWorldLocator.transform.position = _target.transform.parent.position; localToWorldLocator.transform.eulerAngles = _target.transform.parent.eulerAngles; _target.transform.parent = localToWorldLocator.transform; } // Zero out the camera under it's new parent, the locator _target.transform.localPosition = Vector3.zero; _target.transform.localEulerAngles = Vector3.zero; // Act in local space relative to the locator parent _track.space = SpaceType.Local; //EB.Debug.Log("SET L2W CAMERA: " + _parent.name); } // If this director is *not* supposed to be local to world, make sure the camera is a child of the car! else if (_target.transform.parent != null) { if (_target.transform.parent.name == "localToWorldLocator") { //EB.Debug.Log("RESET PLAYERCAR CAMERA: " + _parent.name); _target.transform.parent = _playerCar.transform; DirectorInformation.LastPosition = _target.transform.localPosition; DirectorInformation.LastRotation = _target.transform.localRotation; } } } frame++; //Debug.Log("MOVING FORWARD"); if (DirectorInformation.LerpToNextCamera && Application.isPlaying) { _parent.PlayTime = 0f; timeToLerp = DirectorInformation.LerpTime; if (timer < timeToLerp) { //EB.Debug.Log("LERPING CAMERA: " + _parent.name + " --- TIMER: " + timer + " --- Parent: " + _target.transform.parent.name); timer += Time.deltaTime * ((Time.timeScale != 0) ? 1.0f / Time.timeScale : 0.0f); DirectorInformation.LerpProgress = timer; float easeInOutValue = EZAnimation.sinusInOut(timer, 0.0f, 1.0f, timeToLerp); var v = new QuatPos(); v.pos = Vector3.Lerp(DirectorInformation.LastPosition, from.QuatPosValue.pos, easeInOutValue); v.quat = Quaternion.Lerp(DirectorInformation.LastRotation, from.QuatPosValue.quat, easeInOutValue); v.Apply(_target.transform, _track.space); DirectorInformation.LastPosition = v.pos; DirectorInformation.LastRotation = v.quat; _currentQuatPos.pos = _playerCar.transform.TransformPoint(v.pos); _currentQuatPos.quat = v.quat; if (timer > timeToLerp) { //EB.Debug.Log("LERPED CAMERA: " + _parent.name); _target.transform.localPosition = from.QuatPosValue.pos; _target.transform.localRotation = from.QuatPosValue.quat; DirectorInformation.LerpTime = 1.0f; DirectorInformation.LerpToNextCamera = false; timer = 0f; } } return; } //Debug.Log("NOT LERPING"); // Apply transform tween to target if (_target != null && !DirectorInformation.LerpToNextCamera) { //EB.Debug.Log("BLENDING CAMERA: " + _parent.name + " --- BLEND: " + blend + " --- Parent: " + _target.transform.parent.name); var v1 = from.QuatPosValue; var v2 = to.QuatPosValue; var v = QuatPos.Lerp(v1, v2, blend); v.Apply(_target.transform, _track.space); if (_playerCar != null) { _currentQuatPos.pos = _playerCar.transform.TransformPoint(v.pos); _currentQuatPos.quat = v.quat; DirectorInformation.LastPosition = v.pos; DirectorInformation.LastRotation = v.quat; } } }