123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- internal class DanceObjectDataBinary
- {
- public void ReadData(string file_name)
- {
- file_name = file_name.Replace(Path.GetExtension(file_name), string.Empty);
- if (0 <= file_name.IndexOf("Assets/Resources/"))
- {
- file_name = file_name.Replace("Assets/Resources/", string.Empty);
- }
- TextAsset textAsset = Resources.Load(file_name) as TextAsset;
- if (textAsset == null)
- {
- return;
- }
- MemoryStream input = new MemoryStream(textAsset.bytes);
- BinaryReader binaryReader = new BinaryReader(input);
- int num = binaryReader.ReadInt32();
- this.datas = new DanceObjectDataBinary.Data[num];
- for (int i = 0; i < this.datas.Length; i++)
- {
- DanceObjectDataBinary.Data data = new DanceObjectDataBinary.Data();
- data.target_maid_no = binaryReader.ReadInt32();
- data.object_name = binaryReader.ReadString();
- data.top_object_name = binaryReader.ReadString();
- data.resources_path = binaryReader.ReadString();
- data.tree_path = binaryReader.ReadString();
- data.object_reference_track_id_list = new List<int>();
- int num2 = binaryReader.ReadInt32();
- for (int j = 0; j < num2; j++)
- {
- data.object_reference_track_id_list.Add(binaryReader.ReadInt32());
- }
- this.datas[i] = data;
- }
- }
- public List<GameObject> Restoration(bool create_empty_obj)
- {
- List<GameObject> list = new List<GameObject>();
- if (this.datas == null)
- {
- return list;
- }
- foreach (DanceObjectDataBinary.Data data in this.datas)
- {
- List<string> list2 = new List<string>();
- if (!string.IsNullOrEmpty(data.tree_path))
- {
- string[] array2 = data.tree_path.Split(new char[]
- {
- '/'
- });
- foreach (string item in array2)
- {
- list2.Add(item);
- }
- }
- GameObject gameObject = null;
- if (!string.IsNullOrEmpty(data.top_object_name))
- {
- gameObject = GameObject.Find(data.top_object_name);
- if (gameObject == null)
- {
- gameObject = new GameObject(data.top_object_name);
- list.Add(gameObject);
- }
- foreach (string text in list2)
- {
- GameObject gameObject2 = UTY.GetChildObjectNoError(gameObject, text, false);
- if (gameObject2 == null)
- {
- gameObject2 = new GameObject(text);
- gameObject2.transform.parent = gameObject.transform;
- }
- gameObject = gameObject2;
- }
- }
- GameObject gameObject3;
- if (gameObject == null)
- {
- gameObject3 = GameObject.Find(data.object_name);
- }
- else
- {
- gameObject3 = UTY.GetChildObjectNoError(gameObject, data.object_name, false);
- }
- if (gameObject3 == null)
- {
- if (create_empty_obj)
- {
- gameObject3 = new GameObject(data.object_name);
- }
- else
- {
- GameObject gameObject4 = Resources.Load<GameObject>(data.resources_path);
- if (!gameObject4)
- {
- Debug.LogErrorFormat("{0}が見つかりません", new object[]
- {
- data.object_name
- });
- }
- gameObject3 = UnityEngine.Object.Instantiate<GameObject>(gameObject4);
- gameObject3.name = data.object_name;
- }
- if (gameObject != null)
- {
- gameObject3.transform.SetParent(gameObject.transform, false);
- }
- }
- data.obj = gameObject3;
- }
- return list;
- }
- public void AttachObject(AMTake take_data)
- {
- if (this.datas == null || this.datas.Length <= 0)
- {
- return;
- }
- Dictionary<int, GameObject> dictionary = new Dictionary<int, GameObject>();
- for (int i = 0; i < this.datas.Length; i++)
- {
- foreach (int key in this.datas[i].object_reference_track_id_list)
- {
- if (!dictionary.ContainsKey(key))
- {
- dictionary.Add(key, this.datas[i].obj);
- }
- }
- }
- List<AMTrack> trackValues = take_data.trackValues;
- for (int j = 0; j < trackValues.Count; j++)
- {
- if (dictionary.ContainsKey(trackValues[j].id) && trackValues[j] is AMAnimationTrack)
- {
- AMAnimationTrack amanimationTrack = trackValues[j] as AMAnimationTrack;
- if (amanimationTrack.obj == null)
- {
- amanimationTrack.obj = dictionary[trackValues[j].id];
- }
- amanimationTrack.updateCache();
- }
- }
- }
- public DanceObjectDataBinary.Data[] datas;
- public class Data
- {
- public GameObject obj;
- public int target_maid_no;
- public string object_name;
- public string top_object_name;
- public string resources_path;
- public string tree_path;
- public List<int> object_reference_track_id_list;
- }
- }
|