using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public abstract class AMBinaryDataBaseObject
{
	public abstract void Update(int frame);

	public int GetIndex(int frame)
	{
		if (frame < this.prev_frame)
		{
			this.prev_loop = 0;
			this.prev_index = 0;
		}
		this.prev_frame = frame;
		int value = this.prev_index;
		for (int i = this.prev_loop; i < this.index_array.Length; i++)
		{
			if (frame <= this.index_array[i].Key)
			{
				this.prev_loop = i;
				break;
			}
			value = this.index_array[i].Value;
		}
		this.prev_index = value;
		return value;
	}

	public virtual void Write(BinaryWriter binary)
	{
		binary.Write(this.type_name);
		binary.Write(this.track_id);
		binary.Write(this.total_frame);
		binary.Write(this.object_tree_path);
	}

	public virtual void Read(BinaryReader binary)
	{
		this.track_id = binary.ReadInt32();
		this.total_frame = binary.ReadInt32();
		this.object_tree_path = binary.ReadString();
		string[] array = this.object_tree_path.Split(new char[]
		{
			'/'
		});
		GameObject gameObject = GameObject.Find(array[0]);
		if (gameObject == null)
		{
			NDebug.Assert(array[0] + " がシーン上に見つかりません。", false);
		}
		Transform transform = gameObject.transform;
		for (int i = 1; i < array.Length; i++)
		{
			Transform transform2 = transform.Find(array[i]);
			if (transform2 == null)
			{
				transform = null;
				break;
			}
			transform = transform2;
		}
		this.obj_ = ((!(transform != null)) ? null : transform.gameObject);
		NDebug.Assert(this.obj_, "オブジェクトが見つかりませんでした：" + this.object_tree_path);
		this.index_array = null;
		this.prev_frame = -1;
		this.prev_loop = (this.prev_index = 0);
	}

	public abstract void SetGameObject(GameObject new_obj);

	public bool enabled_index
	{
		get
		{
			return this.index_array != null;
		}
	}

	public T[] Compression<T>(ref T[] val_array, out List<KeyValuePair<int, int>> dest_index_list) where T : struct
	{
		dest_index_list = new List<KeyValuePair<int, int>>();
		dest_index_list.Clear();
		dest_index_list.Add(new KeyValuePair<int, int>(0, 0));
		int num = 0;
		T item = val_array[0];
		List<T> list = new List<T>();
		list.Add(item);
		num++;
		for (int i = 0; i < val_array.Length; i++)
		{
			if (!item.Equals(val_array[i]))
			{
				dest_index_list.Add(new KeyValuePair<int, int>(i - 1, num));
				item = val_array[i];
				list.Add(item);
				num++;
			}
		}
		return list.ToArray();
	}

	public abstract string type_name { get; }

	public GameObject obj
	{
		get
		{
			return this.obj_;
		}
		set
		{
			this.obj_ = value;
		}
	}

	public string object_tree_path;

	public int total_frame;

	public int track_id;

	public KeyValuePair<int, int>[] index_array;

	private GameObject obj_;

	private int prev_frame = -1;

	private int prev_loop;

	private int prev_index;
}
