1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using UnityEngine;
- namespace SC.XR.Unity {
- public class SmoothnessVector3 {
- int pool1Size;
- public List<Vector3> dataPool1 = new List<Vector3>();
- public Vector3 pool1OutVector3 = Vector3.zero;
- int currentItem = 0;
- private SmoothnessVector3() { }
- //const int pool2Size = 50;
- //public List<Vector3> dataPool2 = new List<Vector3>(pool2Size);
- //public Vector3 pool2OutVector3 = Vector3.zero;
- public SmoothnessVector3(Vector3 initValue, int size = 50) {
- pool1Size = size;
- for(int i = 0; i < pool1Size; i++) {
- dataPool1.Add(initValue);
- }
- }
- //int j = 0;
- //float timer = 0;
- //void Update() {
- // timer += Time.deltaTime;
- // if (timer < 0.5f)
- // return;
- // timer = 0;
- // //pool1OutVector3 = GetSmoothnessValue(Vector3.one*(j++));
- // pool1OutVector3 = Smaoothness();
- //}
- void UpdatePool(Vector3 item) {
- if(currentItem >= pool1Size) {
- currentItem = 0;
- }
- dataPool1[currentItem++] = item;
- //for (int i=0;i< pool1Size; i++) {
- // //Debug.Log(i+":"+ dataPool1[i]);
- //}
- }
- Vector3 Smaoothness() {
- Vector3 sum = Vector3.zero;
- foreach(var item in dataPool1) {
- sum += item;
- }
- return sum = sum / pool1Size;
- }
- public Vector3 GetSmoothnessValue(Vector3 item) {
- UpdatePool(item);
- return pool1OutVector3 = Smaoothness();
- }
- }
- }
|