using UnityEngine;

public class MouseDrag4 : MonoBehaviour
{
    public Transform HandL;
    public int ido;
    public bool isPlay = false;
    public bool isSelect;
    public bool isStop = false;
    public Maid maid = null;
    public GameObject obj;
    public bool reset;
    private Vector3 mouseIti;
    private Vector3 mouseIti2;
    private Vector3 off;
    private Vector3 off2;
    private Vector3 rotate;
    private Vector3 worldPoint;

    public void OnMouseDown()
    {
        if (maid == null)
            return;
        worldPoint = Camera.main.WorldToScreenPoint(transform.position);
        off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
        off2 = new Vector3(obj.transform.position.x - HandL.position.x,
                           obj.transform.position.y - HandL.position.y,
                           obj.transform.position.z - HandL.position.z);
        mouseIti = Input.mousePosition;
        isSelect = true;
        rotate = HandL.localEulerAngles;
    }

    public void OnMouseDrag()
    {
        if (maid == null)
            return;
        if (reset)
        {
            reset = false;
            worldPoint = Camera.main.WorldToScreenPoint(transform.position);
            off = transform.position
                  - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
            off2 = new Vector3(obj.transform.position.x - HandL.position.x,
                               obj.transform.position.y - HandL.position.y,
                               obj.transform.position.z - HandL.position.z);
            rotate = HandL.localEulerAngles;
            mouseIti = Input.mousePosition;
        }

        if (mouseIti != Input.mousePosition)
        {
            Vector3 vector3_1 = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z))
                                + off - off2;
            Vector3 vector3_2 = Input.mousePosition - mouseIti;
            Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
            Vector3 vector3_3 = transform.TransformDirection(Vector3.right);
            Vector3 vector3_4 = transform.TransformDirection(Vector3.forward);
            if (mouseIti2 != Input.mousePosition)
            {
                HandL.localEulerAngles = rotate;
                if (ido == 1)
                {
                    HandL.RotateAround(HandL.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), vector3_2.y / 1f);
                    HandL.RotateAround(HandL.position, new Vector3(vector3_4.x, 0.0f, vector3_4.z), (float) (-(double) vector3_2.x / 1.5));
                }

                if (ido == 2)
                    HandL.localRotation = Quaternion.Euler(HandL.localEulerAngles)
                                          * Quaternion.AngleAxis(vector3_2.x / 1.5f, Vector3.right);
            }
        }

        mouseIti2 = Input.mousePosition;
    }
}