AMEventTrack.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. [Serializable]
  6. public class AMEventTrack : AMTrack
  7. {
  8. public override string getTrackType()
  9. {
  10. return "Event";
  11. }
  12. public override void updateCache()
  13. {
  14. base.destroyCache();
  15. this.cache = new List<AMAction>();
  16. base.sortKeys();
  17. for (int i = 0; i < this.keys.Count; i++)
  18. {
  19. AMEventAction ameventAction = ScriptableObject.CreateInstance<AMEventAction>();
  20. ameventAction.startFrame = this.keys[i].frame;
  21. ameventAction.component = (this.keys[i] as AMEventKey).component;
  22. ameventAction.methodInfo = (this.keys[i] as AMEventKey).methodInfo;
  23. ameventAction.parameters = (this.keys[i] as AMEventKey).parameters;
  24. ameventAction.useSendMessage = (this.keys[i] as AMEventKey).useSendMessage;
  25. this.cache.Add(ameventAction);
  26. }
  27. base.updateCache();
  28. }
  29. public void setObject(GameObject obj)
  30. {
  31. this.obj = obj;
  32. }
  33. public bool isObjectUnique(GameObject obj)
  34. {
  35. return this.obj != obj;
  36. }
  37. public void addKey(int _frame)
  38. {
  39. foreach (AMKey amkey in this.keys)
  40. {
  41. AMEventKey ameventKey = (AMEventKey)amkey;
  42. if (ameventKey.frame == _frame)
  43. {
  44. return;
  45. }
  46. }
  47. AMEventKey ameventKey2 = ScriptableObject.CreateInstance<AMEventKey>();
  48. ameventKey2.frame = _frame;
  49. ameventKey2.component = null;
  50. ameventKey2.methodName = null;
  51. ameventKey2.parameters = null;
  52. this.keys.Add(ameventKey2);
  53. this.updateCache();
  54. }
  55. public bool hasSameEventsAs(AMEventTrack _track)
  56. {
  57. return _track.obj == this.obj;
  58. }
  59. public override AnimatorTimeline.JSONInit getJSONInit()
  60. {
  61. return null;
  62. }
  63. public override List<GameObject> getDependencies()
  64. {
  65. List<GameObject> list = new List<GameObject>();
  66. if (this.obj)
  67. {
  68. list.Add(this.obj);
  69. }
  70. foreach (AMKey amkey in this.keys)
  71. {
  72. AMEventKey ameventKey = (AMEventKey)amkey;
  73. list = list.Union(ameventKey.getDependencies()).ToList<GameObject>();
  74. }
  75. return list;
  76. }
  77. public override List<GameObject> updateDependencies(List<GameObject> newReferences, List<GameObject> oldReferences)
  78. {
  79. bool flag = false;
  80. bool flag2 = false;
  81. if (this.obj)
  82. {
  83. for (int i = 0; i < oldReferences.Count; i++)
  84. {
  85. if (oldReferences[i] == this.obj)
  86. {
  87. foreach (AMKey amkey in this.keys)
  88. {
  89. AMEventKey ameventKey = (AMEventKey)amkey;
  90. string name = ameventKey.component.GetType().Name;
  91. if (ameventKey.component && newReferences[i].GetComponent(name) == null)
  92. {
  93. Debug.LogWarning(string.Concat(new string[]
  94. {
  95. "Animator: Event Track component '",
  96. name,
  97. "' not found on new reference for GameObject '",
  98. this.obj.name,
  99. "'. Duplicate not replaced."
  100. }));
  101. return new List<GameObject>
  102. {
  103. oldReferences[i]
  104. };
  105. }
  106. }
  107. this.obj = newReferences[i];
  108. flag = true;
  109. break;
  110. }
  111. }
  112. }
  113. foreach (AMKey amkey2 in this.keys)
  114. {
  115. AMEventKey ameventKey2 = (AMEventKey)amkey2;
  116. if (ameventKey2.updateDependencies(newReferences, oldReferences, flag, this.obj) && !flag2)
  117. {
  118. flag2 = true;
  119. }
  120. }
  121. if (flag || flag2)
  122. {
  123. this.updateCache();
  124. }
  125. return new List<GameObject>();
  126. }
  127. public GameObject obj;
  128. }