No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BaseCullingStrategy.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. namespace UnityEngine.U2D.IK
  4. {
  5. /// <summary>
  6. /// Base class used for defining culling strategies for IKManager2D.
  7. /// </summary>
  8. internal abstract class BaseCullingStrategy
  9. {
  10. public bool enabled => m_IsCullingEnabled;
  11. bool m_IsCullingEnabled;
  12. HashSet<object> m_RequestingManagers;
  13. /// <summary>
  14. /// Used to check if bone transforms should be culled.
  15. /// </summary>
  16. /// <param name="transformIds">A collection of bones' transform ids.</param>
  17. /// <returns>True if any bone is visible.</returns>
  18. public abstract bool AreBonesVisible(IList<int> transformIds);
  19. public void AddRequestingObject(object requestingObject)
  20. {
  21. if (!m_IsCullingEnabled)
  22. {
  23. m_IsCullingEnabled = true;
  24. Initialize();
  25. }
  26. m_RequestingManagers.Add(requestingObject);
  27. }
  28. public void RemoveRequestingObject(object requestingObject)
  29. {
  30. if (m_RequestingManagers.Remove(requestingObject) && m_RequestingManagers.Count == 0)
  31. {
  32. m_IsCullingEnabled = false;
  33. Disable();
  34. }
  35. }
  36. public void Initialize()
  37. {
  38. m_RequestingManagers = new HashSet<object>();
  39. OnInitialize();
  40. }
  41. public void Update()
  42. {
  43. OnUpdate();
  44. }
  45. public void Disable()
  46. {
  47. OnDisable();
  48. }
  49. protected virtual void OnInitialize() { }
  50. protected virtual void OnUpdate() { }
  51. protected virtual void OnDisable() { }
  52. }
  53. }