public override void RestoreState() { if (_target != null) { _state.Apply(_target.transform, _track.space); } }
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; } } }