DanceObjectDataBinary.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. internal class DanceObjectDataBinary
  6. {
  7. public void ReadData(string file_name)
  8. {
  9. file_name = file_name.Replace(Path.GetExtension(file_name), string.Empty);
  10. if (0 <= file_name.IndexOf("Assets/Resources/"))
  11. {
  12. file_name = file_name.Replace("Assets/Resources/", string.Empty);
  13. }
  14. TextAsset textAsset = Resources.Load(file_name) as TextAsset;
  15. if (textAsset == null)
  16. {
  17. return;
  18. }
  19. MemoryStream input = new MemoryStream(textAsset.bytes);
  20. BinaryReader binaryReader = new BinaryReader(input);
  21. int num = binaryReader.ReadInt32();
  22. this.datas = new DanceObjectDataBinary.Data[num];
  23. for (int i = 0; i < this.datas.Length; i++)
  24. {
  25. DanceObjectDataBinary.Data data = new DanceObjectDataBinary.Data();
  26. data.target_maid_no = binaryReader.ReadInt32();
  27. data.object_name = binaryReader.ReadString();
  28. data.top_object_name = binaryReader.ReadString();
  29. data.resources_path = binaryReader.ReadString();
  30. data.tree_path = binaryReader.ReadString();
  31. data.object_reference_track_id_list = new List<int>();
  32. int num2 = binaryReader.ReadInt32();
  33. for (int j = 0; j < num2; j++)
  34. {
  35. data.object_reference_track_id_list.Add(binaryReader.ReadInt32());
  36. }
  37. this.datas[i] = data;
  38. }
  39. }
  40. public List<GameObject> Restoration(bool create_empty_obj)
  41. {
  42. List<GameObject> list = new List<GameObject>();
  43. if (this.datas == null)
  44. {
  45. return list;
  46. }
  47. foreach (DanceObjectDataBinary.Data data in this.datas)
  48. {
  49. List<string> list2 = new List<string>();
  50. if (!string.IsNullOrEmpty(data.tree_path))
  51. {
  52. string[] array2 = data.tree_path.Split(new char[]
  53. {
  54. '/'
  55. });
  56. foreach (string item in array2)
  57. {
  58. list2.Add(item);
  59. }
  60. }
  61. GameObject gameObject = null;
  62. if (!string.IsNullOrEmpty(data.top_object_name))
  63. {
  64. gameObject = GameObject.Find(data.top_object_name);
  65. if (gameObject == null)
  66. {
  67. gameObject = new GameObject(data.top_object_name);
  68. list.Add(gameObject);
  69. }
  70. foreach (string text in list2)
  71. {
  72. GameObject gameObject2 = UTY.GetChildObjectNoError(gameObject, text, false);
  73. if (gameObject2 == null)
  74. {
  75. gameObject2 = new GameObject(text);
  76. gameObject2.transform.parent = gameObject.transform;
  77. }
  78. gameObject = gameObject2;
  79. }
  80. }
  81. GameObject gameObject3;
  82. if (gameObject == null)
  83. {
  84. gameObject3 = GameObject.Find(data.object_name);
  85. }
  86. else
  87. {
  88. gameObject3 = UTY.GetChildObjectNoError(gameObject, data.object_name, false);
  89. }
  90. if (gameObject3 == null)
  91. {
  92. if (create_empty_obj)
  93. {
  94. gameObject3 = new GameObject(data.object_name);
  95. }
  96. else
  97. {
  98. GameObject gameObject4 = Resources.Load<GameObject>(data.resources_path);
  99. if (!gameObject4)
  100. {
  101. Debug.LogErrorFormat("{0}が見つかりません", new object[]
  102. {
  103. data.object_name
  104. });
  105. }
  106. gameObject3 = UnityEngine.Object.Instantiate<GameObject>(gameObject4);
  107. gameObject3.name = data.object_name;
  108. }
  109. if (gameObject != null)
  110. {
  111. gameObject3.transform.SetParent(gameObject.transform, false);
  112. }
  113. }
  114. data.obj = gameObject3;
  115. }
  116. return list;
  117. }
  118. public void AttachObject(AMTake take_data)
  119. {
  120. if (this.datas == null || this.datas.Length <= 0)
  121. {
  122. return;
  123. }
  124. Dictionary<int, GameObject> dictionary = new Dictionary<int, GameObject>();
  125. for (int i = 0; i < this.datas.Length; i++)
  126. {
  127. foreach (int key in this.datas[i].object_reference_track_id_list)
  128. {
  129. if (!dictionary.ContainsKey(key))
  130. {
  131. dictionary.Add(key, this.datas[i].obj);
  132. }
  133. }
  134. }
  135. List<AMTrack> trackValues = take_data.trackValues;
  136. for (int j = 0; j < trackValues.Count; j++)
  137. {
  138. if (dictionary.ContainsKey(trackValues[j].id) && trackValues[j] is AMAnimationTrack)
  139. {
  140. AMAnimationTrack amanimationTrack = trackValues[j] as AMAnimationTrack;
  141. if (amanimationTrack.obj == null)
  142. {
  143. amanimationTrack.obj = dictionary[trackValues[j].id];
  144. }
  145. amanimationTrack.updateCache();
  146. }
  147. }
  148. }
  149. public DanceObjectDataBinary.Data[] datas;
  150. public class Data
  151. {
  152. public GameObject obj;
  153. public int target_maid_no;
  154. public string object_name;
  155. public string top_object_name;
  156. public string resources_path;
  157. public string tree_path;
  158. public List<int> object_reference_track_id_list;
  159. }
  160. }