123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using wf;
- public class AWReadBinaryData
- {
- public AWReadBinaryData()
- {
- this.file_name_ = string.Empty;
- }
- public static float FrameToTime(int frame, float frameRate)
- {
- return (float)System.Math.Round((double)((float)frame / frameRate), 2);
- }
- public static int TimeToFrame(float time, float frameRate)
- {
- return Mathf.FloorToInt(time * frameRate);
- }
- public void ReadFile(string file_name)
- {
- this.file_name_ = string.Empty;
- this.binary_data_list_.Clear();
- if (string.IsNullOrEmpty(file_name))
- {
- return;
- }
- this.file_name_ = file_name.Replace(Path.GetExtension(file_name), string.Empty);
- if (0 <= this.file_name_.IndexOf("Assets/Resources/"))
- {
- this.file_name_ = this.file_name_.Replace("Assets/Resources/", string.Empty);
- }
- TextAsset textAsset = Resources.Load(this.file_name_) as TextAsset;
- MemoryStream input = new MemoryStream(textAsset.bytes);
- BinaryReader binaryReader = new BinaryReader(input);
- string text = binaryReader.ReadString();
- if (text != "BaseData")
- {
- this.file_name_ = string.Empty;
- return;
- }
- this.total_frame_ = binaryReader.ReadInt32();
- this.frame_rate_ = binaryReader.ReadInt32();
- text = binaryReader.ReadString();
- while (text != "Finish")
- {
- AMBinaryDataBaseObject ambinaryDataBaseObject = null;
- if (AMBinaryTranslation.kTypeName == text)
- {
- AMBinaryTranslation ambinaryTranslation = new AMBinaryTranslation();
- ambinaryDataBaseObject = ambinaryTranslation;
- }
- else if (AMBinaryRotation.kTypeName == text)
- {
- AMBinaryRotation ambinaryRotation = new AMBinaryRotation();
- ambinaryDataBaseObject = ambinaryRotation;
- }
- else if (AMBinaryProperty.kTypeName == text)
- {
- AMBinaryProperty ambinaryProperty = new AMBinaryProperty();
- ambinaryDataBaseObject = ambinaryProperty;
- }
- else if (AMBinaryMethod.kTypeName == text)
- {
- AMBinaryMethod ambinaryMethod = new AMBinaryMethod();
- ambinaryDataBaseObject = ambinaryMethod;
- }
- if (ambinaryDataBaseObject != null)
- {
- ambinaryDataBaseObject.Read(binaryReader);
- this.binary_data_list_.Add(ambinaryDataBaseObject);
- }
- text = binaryReader.ReadString();
- }
- }
- public void Update(float time)
- {
- if (!this.enabled)
- {
- return;
- }
- int frame = wf.Math.RoundMinMax(AWReadBinaryData.TimeToFrame(time, (float)this.frame_rate), 0, this.total_frame - 1);
- for (int i = 0; i < this.binary_data_list_.Count; i++)
- {
- this.binary_data_list_[i].Update(frame);
- }
- }
- public List<int> GetTrackIDList()
- {
- List<int> list = new List<int>();
- if (this.enabled)
- {
- for (int i = 0; i < this.binary_data_list_.Count; i++)
- {
- list.Add(this.binary_data_list_[i].track_id);
- }
- }
- return list;
- }
- public bool IsExistTrackID(int track_id)
- {
- for (int i = 0; i < this.binary_data_list_.Count; i++)
- {
- if (this.binary_data_list_[i].track_id == track_id)
- {
- return true;
- }
- }
- return false;
- }
- public bool enabled
- {
- get
- {
- return !string.IsNullOrEmpty(this.file_name_);
- }
- }
- public int total_frame
- {
- get
- {
- return this.total_frame_;
- }
- }
- public int frame_rate
- {
- get
- {
- return this.frame_rate_;
- }
- }
- public AMBinaryDataBaseObject[] binary_data_list
- {
- get
- {
- return this.binary_data_list_.ToArray();
- }
- }
- private List<AMBinaryDataBaseObject> binary_data_list_ = new List<AMBinaryDataBaseObject>();
- private string file_name_;
- private int total_frame_;
- private int frame_rate_;
- }
|