AMBinaryDataBaseObject.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public abstract class AMBinaryDataBaseObject
  6. {
  7. public abstract void Update(int frame);
  8. public int GetIndex(int frame)
  9. {
  10. if (frame < this.prev_frame)
  11. {
  12. this.prev_loop = 0;
  13. this.prev_index = 0;
  14. }
  15. this.prev_frame = frame;
  16. int value = this.prev_index;
  17. for (int i = this.prev_loop; i < this.index_array.Length; i++)
  18. {
  19. if (frame <= this.index_array[i].Key)
  20. {
  21. this.prev_loop = i;
  22. break;
  23. }
  24. value = this.index_array[i].Value;
  25. }
  26. this.prev_index = value;
  27. return value;
  28. }
  29. public virtual void Write(BinaryWriter binary)
  30. {
  31. binary.Write(this.type_name);
  32. binary.Write(this.track_id);
  33. binary.Write(this.total_frame);
  34. binary.Write(this.object_tree_path);
  35. }
  36. public virtual void Read(BinaryReader binary)
  37. {
  38. this.track_id = binary.ReadInt32();
  39. this.total_frame = binary.ReadInt32();
  40. this.object_tree_path = binary.ReadString();
  41. string[] array = this.object_tree_path.Split(new char[]
  42. {
  43. '/'
  44. });
  45. GameObject gameObject = GameObject.Find(array[0]);
  46. if (gameObject == null)
  47. {
  48. NDebug.Assert(array[0] + " がシーン上に見つかりません。", false);
  49. }
  50. Transform transform = gameObject.transform;
  51. for (int i = 1; i < array.Length; i++)
  52. {
  53. Transform transform2 = transform.Find(array[i]);
  54. if (transform2 == null)
  55. {
  56. transform = null;
  57. break;
  58. }
  59. transform = transform2;
  60. }
  61. this.obj_ = ((!(transform != null)) ? null : transform.gameObject);
  62. NDebug.Assert(this.obj_, "オブジェクトが見つかりませんでした:" + this.object_tree_path);
  63. this.index_array = null;
  64. this.prev_frame = -1;
  65. this.prev_loop = (this.prev_index = 0);
  66. }
  67. public abstract void SetGameObject(GameObject new_obj);
  68. public bool enabled_index
  69. {
  70. get
  71. {
  72. return this.index_array != null;
  73. }
  74. }
  75. public T[] Compression<T>(ref T[] val_array, out List<KeyValuePair<int, int>> dest_index_list) where T : struct
  76. {
  77. dest_index_list = new List<KeyValuePair<int, int>>();
  78. dest_index_list.Clear();
  79. dest_index_list.Add(new KeyValuePair<int, int>(0, 0));
  80. int num = 0;
  81. T item = val_array[0];
  82. List<T> list = new List<T>();
  83. list.Add(item);
  84. num++;
  85. for (int i = 0; i < val_array.Length; i++)
  86. {
  87. if (!item.Equals(val_array[i]))
  88. {
  89. dest_index_list.Add(new KeyValuePair<int, int>(i - 1, num));
  90. item = val_array[i];
  91. list.Add(item);
  92. num++;
  93. }
  94. }
  95. return list.ToArray();
  96. }
  97. public abstract string type_name { get; }
  98. public GameObject obj
  99. {
  100. get
  101. {
  102. return this.obj_;
  103. }
  104. set
  105. {
  106. this.obj_ = value;
  107. }
  108. }
  109. public string object_tree_path;
  110. public int total_frame;
  111. public int track_id;
  112. public KeyValuePair<int, int>[] index_array;
  113. private GameObject obj_;
  114. private int prev_frame = -1;
  115. private int prev_loop;
  116. private int prev_index;
  117. }