AniDriver_ActiveObjs.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using ChivaXR;
  5. using System;
  6. using System.Text;
  7. /// <summary>
  8. /// 动画驱动器-显示隐藏物体
  9. /// </summary>
  10. public class AniDriver_ActiveObjs : AnimationDriverBase
  11. {
  12. public List<GameObject> objs = new List<GameObject>();
  13. public bool activeObjs;
  14. public override void FinishedState()
  15. {
  16. foreach (var item in objs)
  17. {
  18. if (item != null)
  19. {
  20. item.SetActive(activeObjs);
  21. }
  22. else
  23. {
  24. Debug.LogError("AniDriver_ActiveObjs模型引用丢失");
  25. }
  26. }
  27. }
  28. public override void InitState()
  29. {
  30. foreach (var item in objs)
  31. {
  32. if (item != null)
  33. {
  34. item.SetActive(!activeObjs);
  35. }
  36. else
  37. {
  38. Debug.LogError("AniDriver_ActiveObjs模型引用丢失");
  39. }
  40. }
  41. }
  42. public override void StartPlay(Action finishedCallBack = null)
  43. {
  44. foreach (var item in objs)
  45. {
  46. item.SetActive(activeObjs);
  47. }
  48. finishedCallBack?.Invoke();
  49. }
  50. public override string AnimationDescription()
  51. {
  52. return animationSequence.ToString() + (activeObjs ? "--显示物体:" : "--隐藏物体:") + GetObjsName();
  53. }
  54. public string GetObjsName()
  55. {
  56. StringBuilder stringBuilder = new StringBuilder();
  57. for (int i = 0; i < objs.Count; i++)
  58. {
  59. if (objs[i] == null) continue;
  60. stringBuilder.Append(objs[i].name);
  61. if (i < objs.Count - 1)
  62. {
  63. stringBuilder.Append("/");
  64. }
  65. }
  66. return stringBuilder.ToString();
  67. }
  68. }