InfraredSpotSettings.cs 905 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Unity.VisualScripting;
  5. using UnityEngine;
  6. [CreateAssetMenu(fileName = "InfraredSpotSettings", menuName = "ScriptableObjects/InfraredSpotSettings", order = 1)]
  7. public class InfraredSpotSettings : ScriptableObject
  8. {
  9. public float RadiusThreshold = 100f; // 初始阈值参考价值不大,每个环境都不一样?
  10. List<float> data;
  11. public InfraredSpotSettings()
  12. {
  13. data = new List<float>(50);
  14. data.AddRange(Enumerable.Repeat(RadiusThreshold, 3));
  15. }
  16. public void UpdateThreshold(float data)
  17. {
  18. var sum = RadiusThreshold * this.data.Count() + data;
  19. if (this.data.Count >= 100)
  20. {
  21. sum -= this.data[0];
  22. this.data.RemoveAt(0);
  23. }
  24. this.data.Add(data);
  25. RadiusThreshold = sum / this.data.Count();
  26. }
  27. }