void Start() { _currTimeState = TimeState.Playing; _currFrame = 0; _maxFrames = (int)(1f / Time.fixedDeltaTime) * _maxSecondsInitializer; _maxFramesSimulated = 0; AvatarTravelInfo newestAvatarHistory = new AvatarTravelInfo(_newestSelf, _maxFrames); _avatarHistories.Add(newestAvatarHistory); _newestSelf.SimulateMe = true; }
void Update() { if (_currTimeState == TimeState.RewindingBecauseLoop) { if (_currFrame > 0) { _newestSelf.FreezeMotion(); for (int i = 0; i < _avatarHistories.Count - 1; i++) { _avatarHistories[i].entity.SetTo(_avatarHistories[i].timeTravelFrames[_currFrame]); } _currFrame -= _rewindSpeed; } else { _currTimeState = TimeState.Playing; _currFrame = 0; _newestSelf.UnFreezeMotion(); } } if (_currTimeState == TimeState.RewindingBecauseSeen) { if (_currFrame > 0) { _newestSelf.FreezeMotion(); for (int i = 0; i < _avatarHistories.Count; i++) { _avatarHistories[i].entity.SetTo(_avatarHistories[i].timeTravelFrames[_currFrame]); } float volume = GetVolume(_alarmAudioSource); if (volume > 0.2f) { _paradoxTextObject.SetActive(true); } else { _paradoxTextObject.SetActive(false); } _alarmLight.intensity = _alarmLightIntensityCurve.Evaluate(volume); _currFrame -= _paradoxRewindSpeed; } else { if (_indexOfParadox < (_avatarHistories.Count - 1)) { _currFrame = _maxFramesSimulated - 1; // GameObject newest = Instantiate(_newestSelf.gameObject, Vector3.zero, Quaternion.identity) as GameObject; _avatarHistories.RemoveAt(_avatarHistories.Count - 1); Destroy(_avatarHistories[_avatarHistories.Count - 1].entity.gameObject); AvatarTravelInfo oldestHistory = _avatarHistories[_avatarHistories.Count - 1]; oldestHistory.entity = _newestSelf; oldestHistory.entity.SetTo(oldestHistory.timeTravelFrames[0]); // oldestHistory.entity.SimulateMe = false; } else { _currTimeState = TimeState.Playing; _currFrame = 0; _newestSelf.UnFreezeMotion(); _paradoxTextObject.SetActive(false); _alarmLight.intensity = 0f; _alarmAudioSource.Stop(); } } } // if (Input.GetKeyDown (KeyCode.R)) { // _currTimeState = TimeState.Rewinding; // } // if (Input.GetKeyUp (KeyCode.R)) { // _currTimeState = TimeState.Playing; // } }
void FixedUpdate() { _timeText.text = ReadableTime; _deathText.text = _deathCount.ToString(); if (_currTimeState == TimeState.Playing) { for (int i = 0; i < _avatarHistories.Count - 1; i++) { var entityToTest = _avatarHistories[i].entity; if (_newestSelf == entityToTest) { continue; } Vector3 toOther = _newestSelf.EyeLocation - entityToTest.EyeLocation; if (toOther.sqrMagnitude <= _separationToCatch * _separationToCatch) { InitiateParadox(ParadoxCause.TooClose, i); break; } Debug.DrawLine(entityToTest.EyeLocation, entityToTest.EyeLocation + entityToTest.Forward, Color.red); float f = Vector3.Dot(entityToTest.Forward, toOther.normalized); if (f >= _fovToCatch) { Debug.DrawLine(_newestSelf.EyeLocation, entityToTest.EyeLocation, Color.blue); // Debug.Log("In FOV: "+f+"!"); RaycastHit hitInfo; if (Physics.Raycast(entityToTest.EyeLocation, toOther.normalized, out hitInfo, distance: Mathf.Infinity)) { if (hitInfo.collider.gameObject.GetComponent <TimeEntity>() != null) { Debug.DrawLine(_newestSelf.EyeLocation, entityToTest.EyeLocation, Color.yellow); Debug.DrawLine(hitInfo.point, entityToTest.EyeLocation, Color.green); InitiateParadox(ParadoxCause.Seen, i); break; } } } } AvatarTravelInfo oldestHistory = _avatarHistories[_avatarHistories.Count - 1]; if (_currFrame < _maxFrames) { for (int i = 0; i < _avatarHistories.Count - 1; i++) { _avatarHistories[i].entity.SetTo(_avatarHistories[i].timeTravelFrames[_currFrame]); } TimeEntityInfo segment = _newestSelf.Simulate(); oldestHistory.timeTravelFrames[_currFrame] = segment; oldestHistory.framesSimulated = _currFrame + 1; _currFrame++; } else { GameObject newest = Instantiate(_newestSelf.gameObject, Vector3.zero, Quaternion.identity) as GameObject; oldestHistory.entity = newest.GetComponent <TimeEntity>(); oldestHistory.entity.SetTo(oldestHistory.timeTravelFrames[0]); oldestHistory.entity.SimulateMe = false; AvatarTravelInfo newestAvatarHistory = new AvatarTravelInfo(_newestSelf, _maxFrames); _avatarHistories.Add(newestAvatarHistory); _currTimeState = TimeState.RewindingBecauseLoop; _currFrame--; } } _maxFramesSimulated = (int)Mathf.Max(_currFrame, _maxFramesSimulated); }