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

public class AMBinaryProperty : AMBinaryDataBaseObject
{
	public static bool CheckType(AMTrack track)
	{
		if (track == null)
		{
			return false;
		}
		AMPropertyTrack ampropertyTrack = track as AMPropertyTrack;
		if (ampropertyTrack == null || ampropertyTrack.propertyInfo == null)
		{
			return false;
		}
		int[] array = new int[]
		{
			0,
			2,
			5,
			6
		};
		for (int i = 0; i < array.Length; i++)
		{
			if (ampropertyTrack.valueType == array[i])
			{
				return true;
			}
		}
		return false;
	}

	public override void Update(int frame)
	{
		if (Application.isPlaying && GameMain.Instance.VRMode && this.property_name == "fov" && this.component is Camera)
		{
			return;
		}
		int index = base.GetIndex(frame);
		if (this.value_type == AMPropertyTrack.ValueType.Integer)
		{
			this.prop_info.SetValue(this.component, this.int_val_array[index], null);
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Float)
		{
			this.prop_info.SetValue(this.component, this.float_val_array[index], null);
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Vector3)
		{
			this.prop_info.SetValue(this.component, this.vec3_val_array[index], null);
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Color)
		{
			this.prop_info.SetValue(this.component, this.color_val_array[index], null);
		}
	}

	public override void Write(BinaryWriter binary)
	{
		base.Write(binary);
		binary.Write((int)this.value_type);
		binary.Write(this.component_name);
		binary.Write(this.property_name);
		List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>();
		if (this.value_type == AMPropertyTrack.ValueType.Integer)
		{
			this.int_val_array = base.Compression<int>(ref this.int_val_array, out list);
			binary.Write(this.int_val_array.Length);
			for (int i = 0; i < this.int_val_array.Length; i++)
			{
				binary.Write(this.int_val_array[i]);
			}
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Float)
		{
			this.float_val_array = base.Compression<float>(ref this.float_val_array, out list);
			binary.Write(this.float_val_array.Length);
			for (int j = 0; j < this.float_val_array.Length; j++)
			{
				binary.Write(this.float_val_array[j]);
			}
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Vector3)
		{
			this.vec3_val_array = base.Compression<Vector3>(ref this.vec3_val_array, out list);
			binary.Write(this.vec3_val_array.Length);
			for (int k = 0; k < this.vec3_val_array.Length; k++)
			{
				binary.Write(this.vec3_val_array[k].x);
				binary.Write(this.vec3_val_array[k].y);
				binary.Write(this.vec3_val_array[k].z);
			}
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Color)
		{
			this.color_val_array = base.Compression<Color>(ref this.color_val_array, out list);
			binary.Write(this.color_val_array.Length);
			for (int l = 0; l < this.color_val_array.Length; l++)
			{
				binary.Write(this.color_val_array[l].a);
				binary.Write(this.color_val_array[l].r);
				binary.Write(this.color_val_array[l].g);
				binary.Write(this.color_val_array[l].b);
			}
		}
		binary.Write(list.Count);
		for (int m = 0; m < list.Count; m++)
		{
			KeyValuePair<int, int> keyValuePair = list[m];
			binary.Write(keyValuePair.Key);
			binary.Write(keyValuePair.Value);
		}
	}

	public override void Read(BinaryReader binary)
	{
		this.value_type = (AMPropertyTrack.ValueType)(-1);
		this.int_val_array = null;
		this.float_val_array = null;
		this.color_val_array = null;
		this.vec3_val_array = null;
		base.Read(binary);
		this.value_type = (AMPropertyTrack.ValueType)binary.ReadInt32();
		this.component_name = binary.ReadString();
		this.property_name = binary.ReadString();
		if (this.value_type == AMPropertyTrack.ValueType.Integer)
		{
			int num = binary.ReadInt32();
			this.int_val_array = new int[num];
			for (int i = 0; i < this.int_val_array.Length; i++)
			{
				this.int_val_array[i] = binary.ReadInt32();
			}
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Float)
		{
			int num2 = binary.ReadInt32();
			this.float_val_array = new float[num2];
			for (int j = 0; j < this.float_val_array.Length; j++)
			{
				this.float_val_array[j] = binary.ReadSingle();
			}
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Vector3)
		{
			int num3 = binary.ReadInt32();
			this.vec3_val_array = new Vector3[num3];
			for (int k = 0; k < this.vec3_val_array.Length; k++)
			{
				Vector3 zero = Vector3.zero;
				zero.x = binary.ReadSingle();
				zero.y = binary.ReadSingle();
				zero.z = binary.ReadSingle();
				this.vec3_val_array[k] = zero;
			}
		}
		else if (this.value_type == AMPropertyTrack.ValueType.Color)
		{
			int num4 = binary.ReadInt32();
			this.color_val_array = new Color[num4];
			for (int l = 0; l < this.color_val_array.Length; l++)
			{
				Color color;
				color.a = binary.ReadSingle();
				color.r = binary.ReadSingle();
				color.g = binary.ReadSingle();
				color.b = binary.ReadSingle();
				this.color_val_array[l] = color;
			}
		}
		int num5 = binary.ReadInt32();
		this.index_array = new KeyValuePair<int, int>[num5];
		for (int m = 0; m < this.index_array.Length; m++)
		{
			int key = binary.ReadInt32();
			int value = binary.ReadInt32();
			this.index_array[m] = new KeyValuePair<int, int>(key, value);
		}
		this.component = base.obj.GetComponent(this.component_name);
		this.prop_info = this.component.GetType().GetProperty(this.property_name);
	}

	public override void SetGameObject(GameObject new_obj)
	{
		base.obj = new_obj;
		this.component = base.obj.GetComponent(this.component_name);
		this.prop_info = this.component.GetType().GetProperty(this.property_name);
	}

	public override string type_name
	{
		get
		{
			return AMBinaryProperty.kTypeName;
		}
	}

	public static string kTypeName = "Property";

	public AMPropertyTrack.ValueType value_type;

	public string component_name;

	public string property_name;

	public PropertyInfo prop_info;

	public Component component;

	public int[] int_val_array;

	public float[] float_val_array;

	public Color[] color_val_array;

	public Vector3[] vec3_val_array;
}
