HandModelsManager.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace NRKernal.NRExamples
  6. {
  7. public class HandModelsManager : MonoBehaviour
  8. {
  9. [Serializable]
  10. public class HandModelsGroup
  11. {
  12. public GameObject rightHandModel;
  13. public GameObject leftHandModel;
  14. public void SetActive(bool isActive)
  15. {
  16. if (leftHandModel)
  17. {
  18. leftHandModel.SetActive(isActive);
  19. }
  20. if (rightHandModel)
  21. {
  22. rightHandModel.SetActive(isActive);
  23. }
  24. }
  25. }
  26. public HandModelsGroup[] modelsGroups;
  27. private int m_CurrentIndex;
  28. private void Start()
  29. {
  30. OnRefresh();
  31. }
  32. public void ToggleHandModelsGroup()
  33. {
  34. m_CurrentIndex = (m_CurrentIndex + 1) % modelsGroups.Length;
  35. OnRefresh();
  36. }
  37. private void OnRefresh()
  38. {
  39. for (int i = 0; i < modelsGroups.Length; i++)
  40. {
  41. var group = modelsGroups[i];
  42. if (group == null)
  43. continue;
  44. group.SetActive(i == m_CurrentIndex);
  45. }
  46. }
  47. }
  48. }