static bool Prefix(float t, ref float localF, ref int __result, TrailElementCollection __instance) { float num = __instance[__instance.capacity - 2].distance * Mathf.Clamp01(t); int i = 0; while (__instance[i].distance < num && i < __instance.capacity - 1) { i++; } if (i == 0 || i == __instance.capacity - 1) { localF = 0f; __result = 0; } else { TrailElement trailElement = __instance[i - 1]; localF = (num - trailElement.distance) / (__instance[i].distance - trailElement.distance); __result = i - 1; } return(false); }
public override void Init() { if (!_trailRenderer) { _trailRenderer = UnityEngine.Object.Instantiate <SaberTrailRenderer>(_trailRendererPrefab, new Vector3(0, TRAIL_Y_OFFSET), Quaternion.identity); } if (!leftClawRenderer) { leftClawRenderer = UnityEngine.Object.Instantiate <SaberTrailRenderer>(_trailRendererPrefab, new Vector3(-TRAIL_X_OFFSET, TRAIL_Y_OFFSET), Quaternion.identity); } if (!rightClawRenderer) { rightClawRenderer = UnityEngine.Object.Instantiate <SaberTrailRenderer>(_trailRendererPrefab, new Vector3(TRAIL_X_OFFSET, TRAIL_Y_OFFSET), Quaternion.identity); } _sampleStep = 1f / _samplingFrequency; BladeMovementDataElement lastAddedData = _movementData.lastAddedData; Vector3 bottomPos = lastAddedData.bottomPos; Vector3 topPos = lastAddedData.topPos; _lastTrailElementTime = lastAddedData.time; _trailElementCollection = new TrailElementCollection(Mathf.CeilToInt(_samplingFrequency * _trailDuration) + 3, bottomPos, calcNewTopPos(bottomPos, topPos), _lastTrailElementTime); float trailWidth = GetTrailWidth(lastAddedData); _whiteSectionMaxDuration = Math.Min(_whiteSectionMaxDuration, _trailDuration); _lastZScale = transform.lossyScale.z; _trailRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration); leftClawRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration); rightClawRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration); _inited = true; }
public override void Init() { if (!_trailRenderer) { _trailRenderer = Instantiate(_trailRendererPrefab, new Vector3(0, TrailYOffset), Quaternion.identity); } if (!_leftClawRenderer) { _leftClawRenderer = Instantiate(_trailRendererPrefab, new Vector3(-TrailXOffset, TrailYOffset), Quaternion.identity); } if (!_rightClawRenderer) { _rightClawRenderer = Instantiate(_trailRendererPrefab, new Vector3(TrailXOffset, TrailYOffset), Quaternion.identity); } _sampleStep = 1f / _samplingFrequency; var lastAddedData = _movementData.lastAddedData; var bottomPos = lastAddedData.bottomPos; var topPos = lastAddedData.topPos; _lastTrailElementTime = lastAddedData.time; _trailElementCollection = new TrailElementCollection(Mathf.CeilToInt(_samplingFrequency * _trailDuration) + 3, bottomPos, CalcNewTopPos(bottomPos, topPos), _lastTrailElementTime); var trailWidth = GetTrailWidth(lastAddedData); _whiteSectionMaxDuration = Math.Min(_whiteSectionMaxDuration, _trailDuration); _lastZScale = transform.lossyScale.z; _trailRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration); _leftClawRenderer.Init(trailWidth, _trailDuration * 0.5f, _granularity, _whiteSectionMaxDuration * 0.5f); _rightClawRenderer.Init(trailWidth, _trailDuration * 0.5f, _granularity, _whiteSectionMaxDuration * 0.5f); _inited = true; }
public override void LateUpdate() { // wait until the fps is stable const int passThroughFrames = 20; if (_framesPassed <= passThroughFrames) { if (_framesPassed == passThroughFrames) { _samplingFrequency = Mathf.RoundToInt(VRDeviceInfo.Instance.refreshRate); if (VRDeviceInfo.Instance.isPimax) { _samplingFrequency = _samplingFrequency / 2; } Logger.log.Debug($"trail samplingFrequency={_samplingFrequency}"); _sampleStep = 1f / (float)_samplingFrequency; int capacity = Mathf.CeilToInt((float)_samplingFrequency * _trailDuration); _lastTrailElementTime = TimeHelper.time; _trailElementCollection = new TrailElementCollection(capacity, _pointStart.position, _pointEnd.position, _lastTrailElementTime); float trailWidth = (_pointEnd.position - _pointStart.position).magnitude; _whiteSectionMaxDuration = Mathf.Min(_whiteSectionMaxDuration, _trailDuration); _lastZScale = transform.lossyScale.z; _trailRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration); _inited = true; } _framesPassed++; return; } _framesToScaleCheck--; if (_framesToScaleCheck <= 0) { _framesToScaleCheck = 10; if (!Mathf.Approximately(base.transform.lossyScale.z, _lastZScale)) { _lastZScale = base.transform.lossyScale.z; float trailWidth = (_pointEnd.position - _pointStart.position).magnitude; _trailRenderer.SetTrailWidth(trailWidth); } } int num = Mathf.RoundToInt((TimeHelper.time - _lastTrailElementTime) / _sampleStep); for (int i = 0; i < num; i++) { _lastTrailElementTime = TimeHelper.time; _trailElementCollection.MoveTailToHead(); _trailElementCollection.head.SetData(_pointStart.position, _pointEnd.position, _lastTrailElementTime); } _trailElementCollection.UpdateDistances(); _trailRenderer.UpdateMesh(_trailElementCollection, color); }
public override void LateUpdate() { if (_pointStart == null || _pointEnd == null) { return; } // wait until the fps is stable const int passThroughFrames = 4; if (_framesPassed <= passThroughFrames) { if (_framesPassed == passThroughFrames) { _samplingFrequency = Mathf.RoundToInt(VRDeviceInfo.Instance.refreshRate); /* no need after recent steamvr update for pimax? * if (VRDeviceInfo.Instance.isPimax) * { * _samplingFrequency = _samplingFrequency / 2; * } * else */ { _samplingFrequency = Mathf.RoundToInt((float)_samplingFrequency * Settings.Utilities.PluginConfig.Instance.samplingMultiplier); } if (_samplingFrequency == 0) { _samplingFrequency = 60; } _sampleStep = 1f / (float)_samplingFrequency; int capacity = Mathf.CeilToInt((float)_samplingFrequency * _trailDuration); Logger.log.Debug($"trail samplingFrequency={_samplingFrequency}, duration={_trailDuration}, capacity={capacity}"); _lastTrailElementTime = TimeHelper.time; _trailElementCollection = new TrailElementCollection(capacity, _pointStart.position, _pointEnd.position, _lastTrailElementTime); float trailWidth = (_pointEnd.position - _pointStart.position).magnitude; _whiteSectionMaxDuration = Mathf.Min(_whiteSectionMaxDuration, _trailDuration); _lastZScale = transform.lossyScale.z; _trailRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration); _lastPointStart = _pointStart.position; _lastPointEnd = _pointEnd.position; _inited = true; } _framesPassed++; return; } if (TimeHelper.time <= _lastTrailElementTime) { return; } int num = Mathf.FloorToInt((TimeHelper.time - _lastTrailElementTime) / _sampleStep); float time = TimeHelper.time; float lastTime = _lastTrailElementTime; for (int i = 1; i <= num; i++) { _lastTrailElementTime += _sampleStep; float t = (_lastTrailElementTime - lastTime) / (time - lastTime); _lastPointStart = Vector3.LerpUnclamped(_lastPointStart, _pointStart.position, t); _lastPointEnd = Vector3.LerpUnclamped(_lastPointEnd, _pointEnd.position, t); _trailElementCollection.MoveTailToHead(); _trailElementCollection.head.SetData(_lastPointStart, _lastPointEnd, _lastTrailElementTime); } if (num > 0) { _trailElementCollection.UpdateDistances(); _trailRenderer.UpdateMesh(_trailElementCollection, color); } }