SmoothnessVector3.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. namespace SC.XR.Unity {
  8. public class SmoothnessVector3 {
  9. int pool1Size;
  10. public List<Vector3> dataPool1 = new List<Vector3>();
  11. public Vector3 pool1OutVector3 = Vector3.zero;
  12. int currentItem = 0;
  13. private SmoothnessVector3() { }
  14. //const int pool2Size = 50;
  15. //public List<Vector3> dataPool2 = new List<Vector3>(pool2Size);
  16. //public Vector3 pool2OutVector3 = Vector3.zero;
  17. public SmoothnessVector3(Vector3 initValue, int size = 50) {
  18. pool1Size = size;
  19. for(int i = 0; i < pool1Size; i++) {
  20. dataPool1.Add(initValue);
  21. }
  22. }
  23. //int j = 0;
  24. //float timer = 0;
  25. //void Update() {
  26. // timer += Time.deltaTime;
  27. // if (timer < 0.5f)
  28. // return;
  29. // timer = 0;
  30. // //pool1OutVector3 = GetSmoothnessValue(Vector3.one*(j++));
  31. // pool1OutVector3 = Smaoothness();
  32. //}
  33. void UpdatePool(Vector3 item) {
  34. if(currentItem >= pool1Size) {
  35. currentItem = 0;
  36. }
  37. dataPool1[currentItem++] = item;
  38. //for (int i=0;i< pool1Size; i++) {
  39. // //Debug.Log(i+":"+ dataPool1[i]);
  40. //}
  41. }
  42. Vector3 Smaoothness() {
  43. Vector3 sum = Vector3.zero;
  44. foreach(var item in dataPool1) {
  45. sum += item;
  46. }
  47. return sum = sum / pool1Size;
  48. }
  49. public Vector3 GetSmoothnessValue(Vector3 item) {
  50. UpdatePool(item);
  51. return pool1OutVector3 = Smaoothness();
  52. }
  53. }
  54. }