AMBinaryProperty.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using UnityEngine;
  6. public class AMBinaryProperty : AMBinaryDataBaseObject
  7. {
  8. public static bool CheckType(AMTrack track)
  9. {
  10. if (track == null)
  11. {
  12. return false;
  13. }
  14. AMPropertyTrack ampropertyTrack = track as AMPropertyTrack;
  15. if (ampropertyTrack == null || ampropertyTrack.propertyInfo == null)
  16. {
  17. return false;
  18. }
  19. int[] array = new int[]
  20. {
  21. 0,
  22. 2,
  23. 5,
  24. 6
  25. };
  26. for (int i = 0; i < array.Length; i++)
  27. {
  28. if (ampropertyTrack.valueType == array[i])
  29. {
  30. return true;
  31. }
  32. }
  33. return false;
  34. }
  35. public override void Update(int frame)
  36. {
  37. if (Application.isPlaying && GameMain.Instance.VRMode && this.property_name == "fov" && this.component is Camera)
  38. {
  39. return;
  40. }
  41. int index = base.GetIndex(frame);
  42. if (this.value_type == AMPropertyTrack.ValueType.Integer)
  43. {
  44. this.prop_info.SetValue(this.component, this.int_val_array[index], null);
  45. }
  46. else if (this.value_type == AMPropertyTrack.ValueType.Float)
  47. {
  48. this.prop_info.SetValue(this.component, this.float_val_array[index], null);
  49. }
  50. else if (this.value_type == AMPropertyTrack.ValueType.Vector3)
  51. {
  52. this.prop_info.SetValue(this.component, this.vec3_val_array[index], null);
  53. }
  54. else if (this.value_type == AMPropertyTrack.ValueType.Color)
  55. {
  56. this.prop_info.SetValue(this.component, this.color_val_array[index], null);
  57. }
  58. }
  59. public override void Write(BinaryWriter binary)
  60. {
  61. base.Write(binary);
  62. binary.Write((int)this.value_type);
  63. binary.Write(this.component_name);
  64. binary.Write(this.property_name);
  65. List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>();
  66. if (this.value_type == AMPropertyTrack.ValueType.Integer)
  67. {
  68. this.int_val_array = base.Compression<int>(ref this.int_val_array, out list);
  69. binary.Write(this.int_val_array.Length);
  70. for (int i = 0; i < this.int_val_array.Length; i++)
  71. {
  72. binary.Write(this.int_val_array[i]);
  73. }
  74. }
  75. else if (this.value_type == AMPropertyTrack.ValueType.Float)
  76. {
  77. this.float_val_array = base.Compression<float>(ref this.float_val_array, out list);
  78. binary.Write(this.float_val_array.Length);
  79. for (int j = 0; j < this.float_val_array.Length; j++)
  80. {
  81. binary.Write(this.float_val_array[j]);
  82. }
  83. }
  84. else if (this.value_type == AMPropertyTrack.ValueType.Vector3)
  85. {
  86. this.vec3_val_array = base.Compression<Vector3>(ref this.vec3_val_array, out list);
  87. binary.Write(this.vec3_val_array.Length);
  88. for (int k = 0; k < this.vec3_val_array.Length; k++)
  89. {
  90. binary.Write(this.vec3_val_array[k].x);
  91. binary.Write(this.vec3_val_array[k].y);
  92. binary.Write(this.vec3_val_array[k].z);
  93. }
  94. }
  95. else if (this.value_type == AMPropertyTrack.ValueType.Color)
  96. {
  97. this.color_val_array = base.Compression<Color>(ref this.color_val_array, out list);
  98. binary.Write(this.color_val_array.Length);
  99. for (int l = 0; l < this.color_val_array.Length; l++)
  100. {
  101. binary.Write(this.color_val_array[l].a);
  102. binary.Write(this.color_val_array[l].r);
  103. binary.Write(this.color_val_array[l].g);
  104. binary.Write(this.color_val_array[l].b);
  105. }
  106. }
  107. binary.Write(list.Count);
  108. for (int m = 0; m < list.Count; m++)
  109. {
  110. KeyValuePair<int, int> keyValuePair = list[m];
  111. binary.Write(keyValuePair.Key);
  112. binary.Write(keyValuePair.Value);
  113. }
  114. }
  115. public override void Read(BinaryReader binary)
  116. {
  117. this.value_type = (AMPropertyTrack.ValueType)(-1);
  118. this.int_val_array = null;
  119. this.float_val_array = null;
  120. this.color_val_array = null;
  121. this.vec3_val_array = null;
  122. base.Read(binary);
  123. this.value_type = (AMPropertyTrack.ValueType)binary.ReadInt32();
  124. this.component_name = binary.ReadString();
  125. this.property_name = binary.ReadString();
  126. if (this.value_type == AMPropertyTrack.ValueType.Integer)
  127. {
  128. int num = binary.ReadInt32();
  129. this.int_val_array = new int[num];
  130. for (int i = 0; i < this.int_val_array.Length; i++)
  131. {
  132. this.int_val_array[i] = binary.ReadInt32();
  133. }
  134. }
  135. else if (this.value_type == AMPropertyTrack.ValueType.Float)
  136. {
  137. int num2 = binary.ReadInt32();
  138. this.float_val_array = new float[num2];
  139. for (int j = 0; j < this.float_val_array.Length; j++)
  140. {
  141. this.float_val_array[j] = binary.ReadSingle();
  142. }
  143. }
  144. else if (this.value_type == AMPropertyTrack.ValueType.Vector3)
  145. {
  146. int num3 = binary.ReadInt32();
  147. this.vec3_val_array = new Vector3[num3];
  148. for (int k = 0; k < this.vec3_val_array.Length; k++)
  149. {
  150. Vector3 zero = Vector3.zero;
  151. zero.x = binary.ReadSingle();
  152. zero.y = binary.ReadSingle();
  153. zero.z = binary.ReadSingle();
  154. this.vec3_val_array[k] = zero;
  155. }
  156. }
  157. else if (this.value_type == AMPropertyTrack.ValueType.Color)
  158. {
  159. int num4 = binary.ReadInt32();
  160. this.color_val_array = new Color[num4];
  161. for (int l = 0; l < this.color_val_array.Length; l++)
  162. {
  163. Color color;
  164. color.a = binary.ReadSingle();
  165. color.r = binary.ReadSingle();
  166. color.g = binary.ReadSingle();
  167. color.b = binary.ReadSingle();
  168. this.color_val_array[l] = color;
  169. }
  170. }
  171. int num5 = binary.ReadInt32();
  172. this.index_array = new KeyValuePair<int, int>[num5];
  173. for (int m = 0; m < this.index_array.Length; m++)
  174. {
  175. int key = binary.ReadInt32();
  176. int value = binary.ReadInt32();
  177. this.index_array[m] = new KeyValuePair<int, int>(key, value);
  178. }
  179. this.component = base.obj.GetComponent(this.component_name);
  180. this.prop_info = this.component.GetType().GetProperty(this.property_name);
  181. }
  182. public override void SetGameObject(GameObject new_obj)
  183. {
  184. base.obj = new_obj;
  185. this.component = base.obj.GetComponent(this.component_name);
  186. this.prop_info = this.component.GetType().GetProperty(this.property_name);
  187. }
  188. public override string type_name
  189. {
  190. get
  191. {
  192. return AMBinaryProperty.kTypeName;
  193. }
  194. }
  195. public static string kTypeName = "Property";
  196. public AMPropertyTrack.ValueType value_type;
  197. public string component_name;
  198. public string property_name;
  199. public PropertyInfo prop_info;
  200. public Component component;
  201. public int[] int_val_array;
  202. public float[] float_val_array;
  203. public Color[] color_val_array;
  204. public Vector3[] vec3_val_array;
  205. }