| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| . | public class MeleeWeaponTrail : MonoBehaviour |
| public class MeleeWeaponTrail : MonoBehaviour, IMonoUpdater |
| { |
| { |
| public bool Emit |
| public bool Emit |
| { |
| { |
| set |
| set |
| { |
| { |
| this._emit = value; |
| this._emit = value; |
| } |
| } |
| } |
| } |
| |
| |
| public bool Use |
| public bool Use |
| { |
| { |
| set |
| set |
| { |
| { |
| this._use = value; |
| this._use = value; |
| } |
| } |
| } |
| } |
| |
| |
| . | |
| private void Awake() |
| |
| { |
| |
| this._trailMesh = new Mesh(); |
| |
| this._trailMesh.name = base.name + "TrailMesh"; |
| |
| } |
| |
| |
| private void Start() |
| private void Start() |
| { |
| { |
| this._lastPosition = base.transform.position; |
| this._lastPosition = base.transform.position; |
| this._trailObject = new GameObject("Trail"); |
| this._trailObject = new GameObject("Trail"); |
| this._trailObject.transform.parent = null; |
| this._trailObject.transform.parent = null; |
| this._trailObject.transform.position = Vector3.zero; |
| this._trailObject.transform.position = Vector3.zero; |
| this._trailObject.transform.rotation = Quaternion.identity; |
| this._trailObject.transform.rotation = Quaternion.identity; |
| this._trailObject.transform.localScale = Vector3.one; |
| this._trailObject.transform.localScale = Vector3.one; |
| this._trailObject.AddComponent(typeof(MeshFilter)); |
| this._trailObject.AddComponent(typeof(MeshFilter)); |
| this._trailObject.AddComponent(typeof(MeshRenderer)); |
| this._trailObject.AddComponent(typeof(MeshRenderer)); |
| this._trailObject.GetComponent<Renderer>().material = this._material; |
| this._trailObject.GetComponent<Renderer>().material = this._material; |
| . | this._trailMesh = new Mesh(); |
| |
| this._trailMesh.name = base.name + "TrailMesh"; |
| |
| this._trailObject.GetComponent<MeshFilter>().mesh = this._trailMesh; |
| this._trailObject.GetComponent<MeshFilter>().mesh = this._trailMesh; |
| this._minVertexDistanceSqr = this._minVertexDistance * this._minVertexDistance; |
| this._minVertexDistanceSqr = this._minVertexDistance * this._minVertexDistance; |
| this._maxVertexDistanceSqr = this._maxVertexDistance * this._maxVertexDistance; |
| this._maxVertexDistanceSqr = this._maxVertexDistance * this._maxVertexDistance; |
| } |
| } |
| |
| |
| . | |
| private void OnEnable() |
| |
| { |
| |
| if (!MeleeWeaponTrail.Instances.Contains(this)) |
| |
| { |
| |
| MeleeWeaponTrail.Instances.Add(this); |
| |
| } |
| |
| } |
| |
| |
| private void OnDisable() |
| private void OnDisable() |
| { |
| { |
| . | |
| MeleeWeaponTrail.Instances.Remove(this); |
| UnityEngine.Object.Destroy(this._trailObject); |
| UnityEngine.Object.Destroy(this._trailObject); |
| } |
| } |
| |
| |
| . | private void FixedUpdate() |
| public void CustomFixedUpdate(float fixedDeltaTime) |
| { |
| { |
| if (!this._use) |
| if (!this._use) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this._emit && this._emitTime != 0f) |
| if (this._emit && this._emitTime != 0f) |
| { |
| { |
| . | this._emitTime -= Time.fixedDeltaTime; |
| this._emitTime -= fixedDeltaTime; |
| if (this._emitTime == 0f) |
| if (this._emitTime == 0f) |
| { |
| { |
| this._emitTime = -1f; |
| this._emitTime = -1f; |
| } |
| } |
| if (this._emitTime < 0f) |
| if (this._emitTime < 0f) |
| { |
| { |
| this._emit = false; |
| this._emit = false; |
| } |
| } |
| } |
| } |
| if (!this._emit && this._points.Count == 0 && this._autoDestruct) |
| if (!this._emit && this._points.Count == 0 && this._autoDestruct) |
| { |
| { |
| UnityEngine.Object.Destroy(this._trailObject); |
| UnityEngine.Object.Destroy(this._trailObject); |
| UnityEngine.Object.Destroy(base.gameObject); |
| UnityEngine.Object.Destroy(base.gameObject); |
| } |
| } |
| if (Utils.GetMainCamera() == null) |
| if (Utils.GetMainCamera() == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| . | |
| float time = Time.time; |
| float sqrMagnitude = (this._lastPosition - base.transform.position).sqrMagnitude; |
| float sqrMagnitude = (this._lastPosition - base.transform.position).sqrMagnitude; |
| if (this._emit) |
| if (this._emit) |
| { |
| { |
| if (sqrMagnitude > this._minVertexDistanceSqr) |
| if (sqrMagnitude > this._minVertexDistanceSqr) |
| { |
| { |
| bool flag = false; |
| bool flag = false; |
| if (this._points.Count < 3) |
| if (this._points.Count < 3) |
| { |
| { |
| flag = true; |
| flag = true; |
| } |
| } |
| else |
| else |
| { |
| { |
| Vector3 vector = this._points[this._points.Count - 2].tipPosition - this._points[this._points.Count - 3].tipPosition; |
| Vector3 vector = this._points[this._points.Count - 2].tipPosition - this._points[this._points.Count - 3].tipPosition; |
| Vector3 vector2 = this._points[this._points.Count - 1].tipPosition - this._points[this._points.Count - 2].tipPosition; |
| Vector3 vector2 = this._points[this._points.Count - 1].tipPosition - this._points[this._points.Count - 2].tipPosition; |
| if (Vector3.Angle(vector, vector2) > this._maxAngle || sqrMagnitude > this._maxVertexDistanceSqr) |
| if (Vector3.Angle(vector, vector2) > this._maxAngle || sqrMagnitude > this._maxVertexDistanceSqr) |
| { |
| { |
| flag = true; |
| flag = true; |
| } |
| } |
| } |
| } |
| if (flag) |
| if (flag) |
| { |
| { |
| MeleeWeaponTrail.Point point = new MeleeWeaponTrail.Point(); |
| MeleeWeaponTrail.Point point = new MeleeWeaponTrail.Point(); |
| point.basePosition = this._base.position; |
| point.basePosition = this._base.position; |
| point.tipPosition = this._tip.position; |
| point.tipPosition = this._tip.position; |
| . | point.timeCreated = Time.time; |
| point.timeCreated = time; |
| this._points.Add(point); |
| this._points.Add(point); |
| this._lastPosition = base.transform.position; |
| this._lastPosition = base.transform.position; |
| if (this._points.Count == 1) |
| if (this._points.Count == 1) |
| { |
| { |
| this._smoothedPoints.Add(point); |
| this._smoothedPoints.Add(point); |
| } |
| } |
| else if (this._points.Count > 1) |
| else if (this._points.Count > 1) |
| { |
| { |
| for (int i = 0; i < 1 + this.subdivisions; i++) |
| for (int i = 0; i < 1 + this.subdivisions; i++) |
| { |
| { |
| this._smoothedPoints.Add(point); |
| this._smoothedPoints.Add(point); |
| } |
| } |
| } |
| } |
| if (this._points.Count >= 4) |
| if (this._points.Count >= 4) |
| { |
| { |
| IEnumerable<Vector3> enumerable = Interpolate.NewCatmullRom(new Vector3[] |
| IEnumerable<Vector3> enumerable = Interpolate.NewCatmullRom(new Vector3[] |
| { |
| { |
| this._points[this._points.Count - 4].tipPosition, |
| this._points[this._points.Count - 4].tipPosition, |
| this._points[this._points.Count - 3].tipPosition, |
| this._points[this._points.Count - 3].tipPosition, |
| this._points[this._points.Count - 2].tipPosition, |
| this._points[this._points.Count - 2].tipPosition, |
| this._points[this._points.Count - 1].tipPosition |
| this._points[this._points.Count - 1].tipPosition |
| }, this.subdivisions, false); |
| }, this.subdivisions, false); |
| IEnumerable<Vector3> enumerable2 = Interpolate.NewCatmullRom(new Vector3[] |
| IEnumerable<Vector3> enumerable2 = Interpolate.NewCatmullRom(new Vector3[] |
| { |
| { |
| this._points[this._points.Count - 4].basePosition, |
| this._points[this._points.Count - 4].basePosition, |
| this._points[this._points.Count - 3].basePosition, |
| this._points[this._points.Count - 3].basePosition, |
| this._points[this._points.Count - 2].basePosition, |
| this._points[this._points.Count - 2].basePosition, |
| this._points[this._points.Count - 1].basePosition |
| this._points[this._points.Count - 1].basePosition |
| }, this.subdivisions, false); |
| }, this.subdivisions, false); |
| List<Vector3> list = new List<Vector3>(enumerable); |
| List<Vector3> list = new List<Vector3>(enumerable); |
| List<Vector3> list2 = new List<Vector3>(enumerable2); |
| List<Vector3> list2 = new List<Vector3>(enumerable2); |
| float timeCreated = this._points[this._points.Count - 4].timeCreated; |
| float timeCreated = this._points[this._points.Count - 4].timeCreated; |
| float timeCreated2 = this._points[this._points.Count - 1].timeCreated; |
| float timeCreated2 = this._points[this._points.Count - 1].timeCreated; |
| for (int j = 0; j < list.Count; j++) |
| for (int j = 0; j < list.Count; j++) |
| { |
| { |
| int num = this._smoothedPoints.Count - (list.Count - j); |
| int num = this._smoothedPoints.Count - (list.Count - j); |
| if (num > -1 && num < this._smoothedPoints.Count) |
| if (num > -1 && num < this._smoothedPoints.Count) |
| { |
| { |
| MeleeWeaponTrail.Point point2 = new MeleeWeaponTrail.Point(); |
| MeleeWeaponTrail.Point point2 = new MeleeWeaponTrail.Point(); |
| point2.basePosition = list2[j]; |
| point2.basePosition = list2[j]; |
| point2.tipPosition = list[j]; |
| point2.tipPosition = list[j]; |
| point2.timeCreated = Mathf.Lerp(timeCreated, timeCreated2, (float)j / (float)list.Count); |
| point2.timeCreated = Mathf.Lerp(timeCreated, timeCreated2, (float)j / (float)list.Count); |
| this._smoothedPoints[num] = point2; |
| this._smoothedPoints[num] = point2; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| this._points[this._points.Count - 1].basePosition = this._base.position; |
| this._points[this._points.Count - 1].basePosition = this._base.position; |
| this._points[this._points.Count - 1].tipPosition = this._tip.position; |
| this._points[this._points.Count - 1].tipPosition = this._tip.position; |
| this._smoothedPoints[this._smoothedPoints.Count - 1].basePosition = this._base.position; |
| this._smoothedPoints[this._smoothedPoints.Count - 1].basePosition = this._base.position; |
| this._smoothedPoints[this._smoothedPoints.Count - 1].tipPosition = this._tip.position; |
| this._smoothedPoints[this._smoothedPoints.Count - 1].tipPosition = this._tip.position; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| if (this._points.Count > 0) |
| if (this._points.Count > 0) |
| { |
| { |
| this._points[this._points.Count - 1].basePosition = this._base.position; |
| this._points[this._points.Count - 1].basePosition = this._base.position; |
| this._points[this._points.Count - 1].tipPosition = this._tip.position; |
| this._points[this._points.Count - 1].tipPosition = this._tip.position; |
| } |
| } |
| if (this._smoothedPoints.Count > 0) |
| if (this._smoothedPoints.Count > 0) |
| { |
| { |
| this._smoothedPoints[this._smoothedPoints.Count - 1].basePosition = this._base.position; |
| this._smoothedPoints[this._smoothedPoints.Count - 1].basePosition = this._base.position; |
| this._smoothedPoints[this._smoothedPoints.Count - 1].tipPosition = this._tip.position; |
| this._smoothedPoints[this._smoothedPoints.Count - 1].tipPosition = this._tip.position; |
| } |
| } |
| } |
| } |
| } |
| } |
| this.RemoveOldPoints(this._points); |
| this.RemoveOldPoints(this._points); |
| if (this._points.Count == 0) |
| if (this._points.Count == 0) |
| { |
| { |
| this._trailMesh.Clear(); |
| this._trailMesh.Clear(); |
| } |
| } |
| this.RemoveOldPoints(this._smoothedPoints); |
| this.RemoveOldPoints(this._smoothedPoints); |
| if (this._smoothedPoints.Count == 0) |
| if (this._smoothedPoints.Count == 0) |
| { |
| { |
| this._trailMesh.Clear(); |
| this._trailMesh.Clear(); |
| } |
| } |
| List<MeleeWeaponTrail.Point> smoothedPoints = this._smoothedPoints; |
| List<MeleeWeaponTrail.Point> smoothedPoints = this._smoothedPoints; |
| if (smoothedPoints.Count > 1) |
| if (smoothedPoints.Count > 1) |
| { |
| { |
| Vector3[] array = new Vector3[smoothedPoints.Count * 2]; |
| Vector3[] array = new Vector3[smoothedPoints.Count * 2]; |
| Vector2[] array2 = new Vector2[smoothedPoints.Count * 2]; |
| Vector2[] array2 = new Vector2[smoothedPoints.Count * 2]; |
| int[] array3 = new int[(smoothedPoints.Count - 1) * 6]; |
| int[] array3 = new int[(smoothedPoints.Count - 1) * 6]; |
| Color[] array4 = new Color[smoothedPoints.Count * 2]; |
| Color[] array4 = new Color[smoothedPoints.Count * 2]; |
| for (int k = 0; k < smoothedPoints.Count; k++) |
| for (int k = 0; k < smoothedPoints.Count; k++) |
| { |
| { |
| MeleeWeaponTrail.Point point3 = smoothedPoints[k]; |
| MeleeWeaponTrail.Point point3 = smoothedPoints[k]; |
| . | float num2 = (Time.time - point3.timeCreated) / this._lifeTime; |
| float num2 = (time - point3.timeCreated) / this._lifeTime; |
| Color color = Color.Lerp(Color.white, Color.clear, num2); |
| Color color = Color.Lerp(Color.white, Color.clear, num2); |
| if (this._colors != null && this._colors.Length != 0) |
| if (this._colors != null && this._colors.Length != 0) |
| { |
| { |
| float num3 = num2 * (float)(this._colors.Length - 1); |
| float num3 = num2 * (float)(this._colors.Length - 1); |
| float num4 = Mathf.Floor(num3); |
| float num4 = Mathf.Floor(num3); |
| float num5 = Mathf.Clamp(Mathf.Ceil(num3), 1f, (float)(this._colors.Length - 1)); |
| float num5 = Mathf.Clamp(Mathf.Ceil(num3), 1f, (float)(this._colors.Length - 1)); |
| float num6 = Mathf.InverseLerp(num4, num5, num3); |
| float num6 = Mathf.InverseLerp(num4, num5, num3); |
| if (num4 >= (float)this._colors.Length) |
| if (num4 >= (float)this._colors.Length) |
| { |
| { |
| num4 = (float)(this._colors.Length - 1); |
| num4 = (float)(this._colors.Length - 1); |
| } |
| } |
| if (num4 < 0f) |
| if (num4 < 0f) |
| { |
| { |
| num4 = 0f; |
| num4 = 0f; |
| } |
| } |
| if (num5 >= (float)this._colors.Length) |
| if (num5 >= (float)this._colors.Length) |
| { |
| { |
| num5 = (float)(this._colors.Length - 1); |
| num5 = (float)(this._colors.Length - 1); |
| } |
| } |
| if (num5 < 0f) |
| if (num5 < 0f) |
| { |
| { |
| num5 = 0f; |
| num5 = 0f; |
| } |
| } |
| color = Color.Lerp(this._colors[(int)num4], this._colors[(int)num5], num6); |
| color = Color.Lerp(this._colors[(int)num4], this._colors[(int)num5], num6); |
| } |
| } |
| float num7 = 0f; |
| float num7 = 0f; |
| if (this._sizes != null && this._sizes.Length != 0) |
| if (this._sizes != null && this._sizes.Length != 0) |
| { |
| { |
| float num8 = num2 * (float)(this._sizes.Length - 1); |
| float num8 = num2 * (float)(this._sizes.Length - 1); |
| float num9 = Mathf.Floor(num8); |
| float num9 = Mathf.Floor(num8); |
| float num10 = Mathf.Clamp(Mathf.Ceil(num8), 1f, (float)(this._sizes.Length - 1)); |
| float num10 = Mathf.Clamp(Mathf.Ceil(num8), 1f, (float)(this._sizes.Length - 1)); |
| float num11 = Mathf.InverseLerp(num9, num10, num8); |
| float num11 = Mathf.InverseLerp(num9, num10, num8); |
| if (num9 >= (float)this._sizes.Length) |
| if (num9 >= (float)this._sizes.Length) |
| { |
| { |
| num9 = (float)(this._sizes.Length - 1); |
| num9 = (float)(this._sizes.Length - 1); |
| } |
| } |
| if (num9 < 0f) |
| if (num9 < 0f) |
| { |
| { |
| num9 = 0f; |
| num9 = 0f; |
| } |
| } |
| if (num10 >= (float)this._sizes.Length) |
| if (num10 >= (float)this._sizes.Length) |
| { |
| { |
| num10 = (float)(this._sizes.Length - 1); |
| num10 = (float)(this._sizes.Length - 1); |
| } |
| } |
| if (num10 < 0f) |
| if (num10 < 0f) |
| { |
| { |
| num10 = 0f; |
| num10 = 0f; |
| } |
| } |
| num7 = Mathf.Lerp(this._sizes[(int)num9], this._sizes[(int)num10], num11); |
| num7 = Mathf.Lerp(this._sizes[(int)num9], this._sizes[(int)num10], num11); |
| } |
| } |
| Vector3 vector3 = point3.tipPosition - point3.basePosition; |
| Vector3 vector3 = point3.tipPosition - point3.basePosition; |
| array[k * 2] = point3.basePosition - vector3 * (num7 * 0.5f); |
| array[k * 2] = point3.basePosition - vector3 * (num7 * 0.5f); |
| array[k * 2 + 1] = point3.tipPosition + vector3 * (num7 * 0.5f); |
| array[k * 2 + 1] = point3.tipPosition + vector3 * (num7 * 0.5f); |
| array4[k * 2] = (array4[k * 2 + 1] = color); |
| array4[k * 2] = (array4[k * 2 + 1] = color); |
| float num12 = (float)k / (float)smoothedPoints.Count; |
| float num12 = (float)k / (float)smoothedPoints.Count; |
| array2[k * 2] = new Vector2(num12, 0f); |
| array2[k * 2] = new Vector2(num12, 0f); |
| array2[k * 2 + 1] = new Vector2(num12, 1f); |
| array2[k * 2 + 1] = new Vector2(num12, 1f); |
| if (k > 0) |
| if (k > 0) |
| { |
| { |
| array3[(k - 1) * 6] = k * 2 - 2; |
| array3[(k - 1) * 6] = k * 2 - 2; |
| array3[(k - 1) * 6 + 1] = k * 2 - 1; |
| array3[(k - 1) * 6 + 1] = k * 2 - 1; |
| array3[(k - 1) * 6 + 2] = k * 2; |
| array3[(k - 1) * 6 + 2] = k * 2; |
| array3[(k - 1) * 6 + 3] = k * 2 + 1; |
| array3[(k - 1) * 6 + 3] = k * 2 + 1; |
| array3[(k - 1) * 6 + 4] = k * 2; |
| array3[(k - 1) * 6 + 4] = k * 2; |
| array3[(k - 1) * 6 + 5] = k * 2 - 1; |
| array3[(k - 1) * 6 + 5] = k * 2 - 1; |
| } |
| } |
| } |
| } |
| this._trailMesh.Clear(); |
| this._trailMesh.Clear(); |
| this._trailMesh.vertices = array; |
| this._trailMesh.vertices = array; |
| this._trailMesh.colors = array4; |
| this._trailMesh.colors = array4; |
| this._trailMesh.uv = array2; |
| this._trailMesh.uv = array2; |
| this._trailMesh.triangles = array3; |
| this._trailMesh.triangles = array3; |
| } |
| } |
| } |
| } |
| |
| |
| private void RemoveOldPoints(List<MeleeWeaponTrail.Point> pointList) |
| private void RemoveOldPoints(List<MeleeWeaponTrail.Point> pointList) |
| { |
| { |
| pointList.RemoveAll((MeleeWeaponTrail.Point p) => Time.time - p.timeCreated > this._lifeTime); |
| pointList.RemoveAll((MeleeWeaponTrail.Point p) => Time.time - p.timeCreated > this._lifeTime); |
| } |
| } |
| . | |
| |
| |
| public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>(); |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private bool _emit = true; |
| private bool _emit = true; |
| |
| |
| private bool _use = true; |
| private bool _use = true; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private float _emitTime; |
| private float _emitTime; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private Material _material; |
| private Material _material; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private float _lifeTime = 1f; |
| private float _lifeTime = 1f; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private Color[] _colors; |
| private Color[] _colors; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private float[] _sizes; |
| private float[] _sizes; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private float _minVertexDistance = 0.1f; |
| private float _minVertexDistance = 0.1f; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private float _maxVertexDistance = 10f; |
| private float _maxVertexDistance = 10f; |
| |
| |
| private float _minVertexDistanceSqr; |
| private float _minVertexDistanceSqr; |
| |
| |
| private float _maxVertexDistanceSqr; |
| private float _maxVertexDistanceSqr; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private float _maxAngle = 3f; |
| private float _maxAngle = 3f; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private bool _autoDestruct; |
| private bool _autoDestruct; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private int subdivisions = 4; |
| private int subdivisions = 4; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private Transform _base; |
| private Transform _base; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private Transform _tip; |
| private Transform _tip; |
| |
| |
| private List<MeleeWeaponTrail.Point> _points = new List<MeleeWeaponTrail.Point>(); |
| private List<MeleeWeaponTrail.Point> _points = new List<MeleeWeaponTrail.Point>(); |
| |
| |
| private List<MeleeWeaponTrail.Point> _smoothedPoints = new List<MeleeWeaponTrail.Point>(); |
| private List<MeleeWeaponTrail.Point> _smoothedPoints = new List<MeleeWeaponTrail.Point>(); |
| |
| |
| private GameObject _trailObject; |
| private GameObject _trailObject; |
| |
| |
| private Mesh _trailMesh; |
| private Mesh _trailMesh; |
| |
| |
| private Vector3 _lastPosition; |
| private Vector3 _lastPosition; |
| |
| |
| [Serializable] |
| [Serializable] |
| public class Point |
| public class Point |
| { |
| { |
| public float timeCreated; |
| public float timeCreated; |
| |
| |
| public Vector3 basePosition; |
| public Vector3 basePosition; |
| |
| |
| public Vector3 tipPosition; |
| public Vector3 tipPosition; |
| } |
| } |
| } |
| } |
| |
| |