AMBinaryMethod.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using UnityEngine;
  6. public class AMBinaryMethod : AMBinaryDataBaseObject
  7. {
  8. public static bool CheckType(AMTrack track)
  9. {
  10. return !(track == null) && track.getTrackType() == AMBinaryMethod.kTypeName;
  11. }
  12. public override void Update(int frame)
  13. {
  14. if (frame < this.prev_frame)
  15. {
  16. this.prev_loop = 0;
  17. }
  18. this.prev_frame = frame;
  19. for (int i = this.prev_loop; i < this.method_data_array.Length; i++)
  20. {
  21. if (this.method_data_array[i].start_flame > frame)
  22. {
  23. this.prev_loop = i;
  24. break;
  25. }
  26. if (!this.method_data_array[i].has_execution)
  27. {
  28. this.method_data_array[i].has_execution = true;
  29. this.method_data_array[i].method_info.Invoke(this.method_data_array[i].component, this.method_data_array[i].object_param_array);
  30. }
  31. }
  32. }
  33. public override void Write(BinaryWriter binary)
  34. {
  35. base.Write(binary);
  36. binary.Write(this.method_data_array.Length);
  37. for (int i = 0; i < this.method_data_array.Length; i++)
  38. {
  39. binary.Write(this.method_data_array[i].start_flame);
  40. binary.Write(this.method_data_array[i].component_name);
  41. binary.Write(this.method_data_array[i].method_name);
  42. bool flag = this.method_data_array[i].param_list != null && 0 < this.method_data_array[i].param_list.Count;
  43. binary.Write(flag);
  44. if (flag)
  45. {
  46. binary.Write(this.method_data_array[i].param_list.Count);
  47. for (int j = 0; j < this.method_data_array[i].param_list.Count; j++)
  48. {
  49. this.method_data_array[i].param_list[j].Write(binary);
  50. }
  51. }
  52. }
  53. }
  54. public override void Read(BinaryReader binary)
  55. {
  56. this.prev_frame = -1;
  57. this.prev_loop = 0;
  58. base.Read(binary);
  59. int num = binary.ReadInt32();
  60. this.method_data_array = new AMBinaryMethod.MethodData[num];
  61. for (int i = 0; i < this.method_data_array.Length; i++)
  62. {
  63. AMBinaryMethod.MethodData methodData = default(AMBinaryMethod.MethodData);
  64. methodData.start_flame = binary.ReadInt32();
  65. methodData.component_name = binary.ReadString();
  66. methodData.method_name = binary.ReadString();
  67. methodData.component = base.obj.GetComponent(methodData.component_name);
  68. methodData.method_info = methodData.component.GetType().GetMethod(methodData.method_name);
  69. NDebug.AssertNull(methodData.method_info != null);
  70. methodData.param_list = null;
  71. methodData.object_param_array = null;
  72. bool flag = binary.ReadBoolean();
  73. if (flag)
  74. {
  75. num = binary.ReadInt32();
  76. methodData.object_param_array = new object[num];
  77. for (int j = 0; j < num; j++)
  78. {
  79. AMEventParameter ameventParameter = ScriptableObject.CreateInstance<AMEventParameter>();
  80. ameventParameter.Read(binary);
  81. if (!ameventParameter.isArray())
  82. {
  83. methodData.object_param_array[j] = ameventParameter.toObject();
  84. }
  85. else
  86. {
  87. methodData.object_param_array[j] = ameventParameter.toArray();
  88. }
  89. }
  90. }
  91. this.method_data_array[i] = methodData;
  92. }
  93. }
  94. public override void SetGameObject(GameObject new_obj)
  95. {
  96. base.obj = new_obj;
  97. for (int i = 0; i < this.method_data_array.Length; i++)
  98. {
  99. this.method_data_array[i].component = base.obj.GetComponent(this.method_data_array[i].component_name);
  100. this.method_data_array[i].method_info = this.method_data_array[i].component.GetType().GetMethod(this.method_data_array[i].method_name);
  101. NDebug.AssertNull(this.method_data_array[i].method_info != null);
  102. }
  103. }
  104. public override string type_name
  105. {
  106. get
  107. {
  108. return AMBinaryMethod.kTypeName;
  109. }
  110. }
  111. public static string kTypeName = "Event";
  112. public AMBinaryMethod.MethodData[] method_data_array;
  113. private int prev_frame = -1;
  114. private int prev_loop;
  115. public struct MethodData
  116. {
  117. public bool has_execution;
  118. public int start_flame;
  119. public string component_name;
  120. public string method_name;
  121. public MethodInfo method_info;
  122. public Component component;
  123. public List<AMEventParameter> param_list;
  124. public object[] object_param_array;
  125. }
  126. }