using System.Collections.Generic;
using UnityEngine;

public class MouseDrag6 : MonoBehaviour
{
    public Vector3 angles;
    public int count;
    public bool del;
    public int ido;
    public bool isAlt;
    public bool isClick;
    public bool isIdo;
    public bool isOn;
    public bool isScale = false;
    public bool isScale2 = false;
    public bool isSelect;
    public GameObject maid = null;
    public GameObject[] maidArray = null;
    public MouseDrag6[] mArray = null;
    public GameObject obj;
    public bool reset;
    public Vector3 scale;
    public Vector3 scale2;
    private float doubleTapTime;
    private int idoOld;
    private Vector3 mouseIti;
    private Vector3 mouseIti2;
    private Vector3 off;
    private Vector3 off2;
    private Vector3 rotate;
    private float size;
    private Vector3 worldPoint;
    private List<float> xList = new List<float>();
    private List<float> yList = new List<float>();
    private List<float> zList = new List<float>();

    public void Update()
    {
        doubleTapTime += Time.deltaTime;
    }

    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 - maid.transform.position.x,
                           obj.transform.position.y - maid.transform.position.y,
                           obj.transform.position.z - maid.transform.position.z);
        mouseIti = Input.mousePosition;
        if (doubleTapTime < 0.300000011920929 && isClick && ido == idoOld)
        {
            if (ido == 5)
                maid.transform.localScale = !isScale2 ? new Vector3(1f, 1f, 1f) : scale2;
            if (ido == 4 || ido == 6)
                maid.transform.eulerAngles = new Vector3(angles.x, maid.transform.eulerAngles.y, angles.z);
        }

        if (doubleTapTime >= 0.300000011920929 && isClick)
            isClick = false;
        doubleTapTime = 0.0f;
        rotate = maid.transform.localEulerAngles;
        size = maid.transform.localScale.x;
        isSelect = true;
        isOn = true;
        if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
            isAlt = !isAlt;
        xList = new List<float>();
        yList = new List<float>();
        zList = new List<float>();
        if (maidArray != null)
            for (int index = 0; index < maidArray.Length; ++index)
            {
                xList.Add(maid.transform.position.x - maidArray[index].transform.position.x);
                yList.Add(maid.transform.position.y - maidArray[index].transform.position.y);
                zList.Add(maid.transform.position.z - maidArray[index].transform.position.z);
            }
    }

    public void OnMouseUp()
    {
        if (!(maid != null))
            return;
        isOn = false;
        if (doubleTapTime < 0.300000011920929)
        {
            isClick = true;
            doubleTapTime = 0.0f;
            idoOld = ido;
        }

        if (ido == 7)
            del = true;
    }

    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 - maid.transform.position.x,
                               obj.transform.position.y - maid.transform.position.y,
                               obj.transform.position.z - maid.transform.position.z);
            rotate = maid.transform.localEulerAngles;
            size = maid.transform.localScale.x;
            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;
            isIdo = false;
            if (ido == 1)
            {
                maid.transform.position = new Vector3(vector3_1.x, maid.transform.position.y, vector3_1.z);
                if (maidArray != null)
                    for (int index = 0; index < maidArray.Length; ++index)
                        if (mArray[index].isAlt)
                            maidArray[index].transform.position = new Vector3(vector3_1.x - xList[index],
                                                                              maidArray[index].transform.position.y,
                                                                              vector3_1.z - zList[index]);
                isIdo = true;
            }

            if (ido == 2)
            {
                maid.transform.position = new Vector3(maid.transform.position.x, vector3_1.y, maid.transform.position.z);
                if (maidArray != null)
                    for (int index = 0; index < maidArray.Length; ++index)
                        if (mArray[index].isAlt)
                            maidArray[index].transform.position = new Vector3(maidArray[index].transform.position.x,
                                                                              vector3_1.y - yList[index],
                                                                              maidArray[index].transform.position.z);
                isIdo = true;
            }

            Vector3 vector3_2;
            if (ido == 3)
            {
                vector3_2 = Input.mousePosition - mouseIti;
                maid.transform.eulerAngles =
                        new Vector3(maid.transform.eulerAngles.x, rotate.y - vector3_2.x / 2.2f, maid.transform.eulerAngles.z);
            }

            Vector3 vector3_3;
            if (ido == 4)
            {
                vector3_2 = Input.mousePosition - mouseIti;
                Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
                vector3_3 = transform.TransformDirection(Vector3.right);
                Vector3 vector3_4 = transform.TransformDirection(Vector3.forward);
                if (mouseIti2 != Input.mousePosition)
                {
                    maid.transform.localEulerAngles = rotate;
                    maid.transform.RotateAround(maid.transform.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), vector3_2.y / 4f);
                    maid.transform.RotateAround(maid.transform.position,
                                                new Vector3(vector3_4.x, 0.0f, vector3_4.z),
                                                (float) (-(double) vector3_2.x / 6.0));
                }

                isIdo = true;
                mouseIti2 = Input.mousePosition;
            }

            if (ido == 6)
            {
                vector3_2 = Input.mousePosition - mouseIti;
                Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
                vector3_3 = transform.TransformDirection(Vector3.right);
                transform.TransformDirection(Vector3.forward);
                if (mouseIti2 != Input.mousePosition)
                {
                    maid.transform.localEulerAngles = rotate;
                    maid.transform.localRotation = Quaternion.Euler(maid.transform.localEulerAngles)
                                                   * Quaternion.AngleAxis((float) (-(double) vector3_2.x / 2.20000004768372), Vector3.up);
                }

                isIdo = true;
                mouseIti2 = Input.mousePosition;
            }

            if (ido == 5)
            {
                vector3_2 = Input.mousePosition - mouseIti;
                float num = size + vector3_2.y / 200f;
                if (num < 0.00999999977648258)
                    num = 0.01f;
                maid.transform.localScale =
                        !isScale ? new Vector3(num, num, num) : new Vector3(scale.x * num, scale.y * num, scale.z * num);
            }

            if (ido == 15)
            {
                vector3_2 = Input.mousePosition - mouseIti;
                float num = size + vector3_2.y / 2f;
                if (num < 0.00999999977648258)
                    num = 0.01f;
                if (num > 150.0)
                    num = 150f;
                maid.transform.localScale = new Vector3(num, num, num);
            }
        }
    }
}