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

public class PhotoTransTargetObject : IComparable<PhotoTransTargetObject>
{
	public PhotoTransTargetObject(GameObject target, string draw_name, PhotoTransTargetObject.Type type, Vector2 scaleMinMax)
	{
		this.obj = target;
		if (target != null)
		{
			this.default_parent = target.transform.parent;
			this.init_pos = target.transform.localPosition;
			this.init_rotate = target.transform.rotation;
		}
		this.draw_name = draw_name;
		this.type = type;
		this.guid = Guid.NewGuid().ToString();
		this.attachi_point = PhotoTransTargetObject.AttachPoint.Null;
		this.Create(scaleMinMax);
	}

	public void Create(Vector2 scaleMinMax)
	{
		if (this.obj == null)
		{
			return;
		}
		if (this.rotate_obj == null)
		{
			this.rotate_obj = PhotoWindowManager.CreateWorldTransformRotate(this.obj, false);
			this.rotate_obj.Visible = false;
		}
		if (this.axis_obj == null)
		{
			this.axis_obj = PhotoWindowManager.CreateWorldTransformAxis(this.obj, false, false);
			this.axis_obj.Visible = false;
			this.axis_obj.ScaleMinMax = scaleMinMax;
		}
	}

	public void Delete()
	{
		if (this.obj == null)
		{
			return;
		}
		if (this.axis_obj != null)
		{
			UnityEngine.Object.DestroyImmediate(this.axis_obj.gameObject);
		}
		this.axis_obj = null;
		if (this.rotate_obj != null)
		{
			UnityEngine.Object.DestroyImmediate(this.rotate_obj);
		}
		this.rotate_obj = null;
	}

	public string Attach(PhotoTransTargetObject.AttachPoint point, bool worldPositionStays, Maid targetMaid)
	{
		if (this.obj == null)
		{
			return "設定不可";
		}
		if (targetMaid == null)
		{
			if (point != PhotoTransTargetObject.AttachPoint.Null)
			{
				Debug.LogError("アタッチ先のメイドがみつかりません");
			}
			point = PhotoTransTargetObject.AttachPoint.Null;
		}
		this.attachi_point = point;
		this.attach_maid_guid = string.Empty;
		Transform attachPointTransform = this.default_parent;
		if (this.attachi_point != PhotoTransTargetObject.AttachPoint.Null)
		{
			attachPointTransform = this.GetAttachPointTransform(targetMaid, point);
			this.attach_maid_guid = targetMaid.status.guid;
		}
		string text = string.Empty;
		if (targetMaid != null)
		{
			text = targetMaid.status.lastName + " " + targetMaid.status.firstName + " : ";
		}
		text += this.AttachPointToString(point);
		if (attachPointTransform == null || attachPointTransform == this.obj.transform.parent)
		{
			return text;
		}
		Vector3 position = this.obj.transform.position;
		Quaternion rotation = this.obj.transform.rotation;
		this.obj.transform.SetParent(attachPointTransform, worldPositionStays);
		if (worldPositionStays)
		{
			this.obj.transform.position = position;
			this.obj.transform.rotation = rotation;
		}
		else
		{
			this.obj.transform.localPosition = this.init_pos;
			this.obj.transform.rotation = this.init_rotate;
		}
		return text;
	}

	public Transform GetAttachPointTransform(Maid targetMaid, PhotoTransTargetObject.AttachPoint point)
	{
		if (PhotoTransTargetObject.subsTable.Count == 0)
		{
			Func<IKManager.BoneType, string, KeyValuePair<IKManager.BoneType, string>> func = (IKManager.BoneType type, string name) => new KeyValuePair<IKManager.BoneType, string>(type, name);
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Null, func(IKManager.BoneType.TopFixed, "設定なし"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Fix, func(IKManager.BoneType.TopFixed, "固定"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Root, func(IKManager.BoneType.Root, "原点"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Head, func(IKManager.BoneType.Head, "頭"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Neck, func(IKManager.BoneType.Neck, "首元"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Mune_R, func(IKManager.BoneType.Bust_R, "右胸"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.UpperArm_R, func(IKManager.BoneType.UpperArm_R, "右肩"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Forearm_R, func(IKManager.BoneType.Forearm_R, "右肘"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Hand_R, func(IKManager.BoneType.Hand_R, "右手首"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Thigh_R, func(IKManager.BoneType.Thigh_R, "右足付け根"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Calf_R, func(IKManager.BoneType.Calf_R, "右膝"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Foot_R, func(IKManager.BoneType.Foot_R, "右足首"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Mune_L, func(IKManager.BoneType.Bust_L, "左胸"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.UpperArm_L, func(IKManager.BoneType.UpperArm_L, "左肩"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Forearm_L, func(IKManager.BoneType.Forearm_L, "左肘"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Hand_L, func(IKManager.BoneType.Hand_L, "左手首"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Thigh_L, func(IKManager.BoneType.Thigh_L, "左足付け根"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Calf_L, func(IKManager.BoneType.Calf_L, "左膝"));
			PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Foot_L, func(IKManager.BoneType.Foot_L, "左足首"));
		}
		if (targetMaid == null)
		{
			return null;
		}
		IKManager maidIKManager = PoseEditWindow.GetMaidIKManager(targetMaid);
		return maidIKManager.GetBone(PhotoTransTargetObject.subsTable[point].Key).transform;
	}

	public string AttachPointToString(PhotoTransTargetObject.AttachPoint point)
	{
		if (PhotoTransTargetObject.subsTable.Count == 0)
		{
			this.GetAttachPointTransform(null, PhotoTransTargetObject.AttachPoint.Null);
		}
		return PhotoTransTargetObject.subsTable[point].Value;
	}

	public int CompareTo(PhotoTransTargetObject comp_obj)
	{
		if (this.type != comp_obj.type)
		{
			int num = (int)comp_obj.type;
			return num.CompareTo((int)this.type);
		}
		string text = string.Empty;
		string strB = string.Empty;
		if (comp_obj.obj != null)
		{
			text = comp_obj.obj.name;
		}
		if (this.obj != null)
		{
			strB = this.obj.name;
		}
		return text.CompareTo(strB);
	}

	public GameObject obj;

	public Transform default_parent;

	public Vector3 init_pos;

	public Quaternion init_rotate;

	public string draw_name;

	public PhotoTransTargetObject.Type type;

	public WorldTransformAxis axis_obj;

	public GizmoRender rotate_obj;

	public string guid;

	public PhotoTransTargetObject.AttachPoint attachi_point;

	public string attach_maid_guid = string.Empty;

	public Vector3 attachi_local_pos;

	public Quaternion attachi_local_rotate;

	private static Dictionary<PhotoTransTargetObject.AttachPoint, KeyValuePair<IKManager.BoneType, string>> subsTable = new Dictionary<PhotoTransTargetObject.AttachPoint, KeyValuePair<IKManager.BoneType, string>>();

	public enum AttachPoint
	{
		Null,
		Fix,
		Root,
		Head,
		Neck,
		Mune_R,
		UpperArm_R,
		Forearm_R,
		Hand_R,
		Thigh_R,
		Calf_R,
		Foot_R,
		Mune_L,
		UpperArm_L,
		Forearm_L,
		Hand_L,
		Thigh_L,
		Calf_L,
		Foot_L
	}

	public enum Type
	{
		Maid,
		BG,
		Prefab,
		Light
	}
}
