using System;
using UnityEngine;

public class IKDragPoint : MonoBehaviour
{
	public static bool IsDrag { get; private set; }

	private void Update()
	{
		if (this.axis_obj_ == null || this.target_trans_ == null)
		{
			return;
		}
		if ((this.axis_obj_.is_drag || this.axis_obj_.is_grip) && !this.is_drag_)
		{
			this.OnDragStart();
			IKDragPoint.IsDrag = true;
		}
		else if (this.is_drag_ && !this.axis_obj_.is_drag && !this.axis_obj_.is_grip)
		{
			this.OnDragEnd();
			IKDragPoint.IsDrag = false;
			if (this.PositonCorrectionEnabled)
			{
				this.target_trans_.localPosition = this.backup_local_pos_;
			}
		}
		this.is_drag_ = (this.axis_obj_.is_drag || this.axis_obj_.is_grip);
		if (this.is_drag_)
		{
			this.OnDrag();
			if (this.PositonCorrectionEnabled)
			{
				this.target_trans_.localPosition = this.backup_local_pos_;
			}
			return;
		}
		base.transform.position = this.target_trans_.position;
	}

	public void OnDestroy()
	{
		if (this.axis_obj_ != null)
		{
			UnityEngine.Object.Destroy(this.axis_obj_.gameObject);
		}
		this.axis_obj_ = null;
	}

	public void SetTargetIKPoint(GameObject obj)
	{
		this.target_trans_ = obj.transform;
		this.backup_local_pos_ = this.target_trans_.localPosition;
		this.Update();
	}

	public void SetWorldTransformAxis(WorldTransformAxis axis_obj)
	{
		this.axis_obj_ = axis_obj;
		this.Update();
	}

	public Transform target_ik_point_trans
	{
		get
		{
			return this.target_trans_;
		}
	}

	public WorldTransformAxis axis_obj
	{
		get
		{
			return this.axis_obj_;
		}
	}

	public bool visible
	{
		get
		{
			return this.axis_obj_.Visible;
		}
		set
		{
			this.axis_obj_.Visible = value;
		}
	}

	private void OnDragStart()
	{
		if (this.drag_start_event != null)
		{
			this.drag_start_event();
		}
	}

	private void OnDrag()
	{
		if (this.cur_drag_event != null)
		{
			this.cur_drag_event();
		}
	}

	private void OnDragEnd()
	{
		if (this.drag_end_event != null)
		{
			this.drag_end_event();
		}
	}

	public bool PositonCorrectionEnabled = true;

	public Action cur_drag_event;

	public Action drag_start_event;

	public Action drag_end_event;

	private Transform target_trans_;

	private Vector3 backup_local_pos_;

	private WorldTransformAxis axis_obj_;

	private bool is_drag_;
}
