using System;
using UnityEngine;

namespace SceneEditWindow
{
	public class BaseCustomParts
	{
		public BaseCustomParts(Maid maid, TBody.SlotID slotId, string apName)
		{
			this.maid = maid;
			this.slotId = slotId;
			this.apName = ((!string.IsNullOrEmpty(apName)) ? apName : null);
		}

		public Maid maid { get; private set; }

		public TBody.SlotID slotId { get; private set; }

		public string apName { get; private set; }

		public bool enabled
		{
			get
			{
				return this.maid.body0.maid.body0.GetEnableAttachPointEdit(this.slotId, this.apName);
			}
			set
			{
				if (!value)
				{
					this.Reset();
				}
				this.maid.body0.maid.body0.SetEnableAttachPointEdit(value, this.slotId, this.apName);
			}
		}

		public Vector3 position
		{
			get
			{
				Vector3 result;
				Quaternion quaternion;
				Vector3 vector;
				this.maid.body0.GetAttachPointWorld(this.slotId, this.apName, out result, out quaternion, out vector);
				return result;
			}
			set
			{
				Vector3 vector;
				Quaternion qRotWorld;
				Vector3 vScaleRate;
				this.maid.body0.GetAttachPointWorld(this.slotId, this.apName, out vector, out qRotWorld, out vScaleRate);
				this.maid.body0.SetAttachPointWorld(this.slotId, this.apName, value, qRotWorld, vScaleRate);
			}
		}

		public Quaternion rotation
		{
			get
			{
				Vector3 vector;
				Quaternion result;
				Vector3 vector2;
				this.maid.body0.GetAttachPointWorld(this.slotId, this.apName, out vector, out result, out vector2);
				return result;
			}
			set
			{
				Vector3 vPosWorld;
				Quaternion quaternion;
				Vector3 vScaleRate;
				this.maid.body0.GetAttachPointWorld(this.slotId, this.apName, out vPosWorld, out quaternion, out vScaleRate);
				this.maid.body0.SetAttachPointWorld(this.slotId, this.apName, vPosWorld, value, vScaleRate);
			}
		}

		public Vector3 scale
		{
			get
			{
				Vector3 vector;
				Quaternion quaternion;
				Vector3 result;
				this.maid.body0.GetAttachPointWorld(this.slotId, this.apName, out vector, out quaternion, out result);
				return result;
			}
			set
			{
				Vector3 vPosWorld;
				Quaternion qRotWorld;
				Vector3 vector;
				this.maid.body0.GetAttachPointWorld(this.slotId, this.apName, out vPosWorld, out qRotWorld, out vector);
				this.maid.body0.SetAttachPointWorld(this.slotId, this.apName, vPosWorld, qRotWorld, value);
			}
		}

		public void SetTransformData(Transform transform, bool setWorldData = true)
		{
			if (setWorldData)
			{
				this.maid.body0.SetAttachPointWorld(this.slotId, this.apName, transform.position, transform.rotation, transform.localScale);
			}
			else
			{
				this.maid.body0.SetAttachPointLocal(this.slotId, this.apName, transform.localPosition, transform.localRotation, transform.localScale);
			}
		}

		public void SetTransformData(Vector3 position, Quaternion rotation, Vector3 scale, bool setWorldData = true)
		{
			if (setWorldData)
			{
				this.maid.body0.SetAttachPointWorld(this.slotId, this.apName, position, rotation, scale);
			}
			else
			{
				this.maid.body0.SetAttachPointLocal(this.slotId, this.apName, position, rotation, scale);
			}
		}

		public void GetTransformData(out Vector3 position, out Quaternion rotation, out Vector3 scale, bool getWorldData = true)
		{
			if (getWorldData)
			{
				this.maid.body0.GetAttachPointWorld(this.slotId, this.apName, out position, out rotation, out scale);
			}
			else
			{
				this.maid.body0.GetAttachPointLocal(this.slotId, this.apName, out position, out rotation, out scale);
			}
		}

		public void SaveBackup()
		{
			this.maid.body0.CopyAttachPoint(this.slotId, this.apName);
		}

		public void LoadBackup()
		{
			this.maid.body0.PasteAttachPoint(this.slotId, this.apName);
		}

		public void Reset()
		{
			this.maid.body0.ResetAttachPoint(this.slotId, this.apName);
			Vector3 vPosWorld;
			Quaternion qRotWorld;
			Vector3 vScaleRate;
			this.maid.body0.GetAttachPointWorld(this.slotId, this.apName, out vPosWorld, out qRotWorld, out vScaleRate);
			this.maid.body0.SetAttachPointWorld(this.slotId, this.apName, vPosWorld, qRotWorld, vScaleRate);
		}
	}
}
