Esempio n. 1
0
    public void OnLeftDown()
    {
        bDown     = true;
        fTimeDown = 0.0f;
        v3Down    = LibView.GetMouseLocation();

        switch (stateLeft)
        {
        case STATELEFT.IDLE:
            stateLeft = STATELEFT.PRESS;
            break;

        case STATELEFT.CLICK:
        case STATELEFT.DOUBLECLICK:
            stateLeft = STATELEFT.DOUBLEPRESS;
            break;
        }
    }
Esempio n. 2
0
    public virtual void Update()
    {
        if (bDown)
        {
            //Note that this uses the real Time.deltaTime as opposed to the ContTime.fDeltaTime
            fTimeDown += Time.deltaTime;
        }
        else
        {
            fTimeUp += Time.deltaTime;
        }

        // Handle time related checks
        switch (stateLeft)
        {
        case STATELEFT.PRESS:
        case STATELEFT.DOUBLEPRESS:
            // Check if it's been pressed long enough to count as holding the mouse
            if (fTimeDown >= fTimeDownDelay)
            {
                bHeld     = true;
                stateLeft = STATELEFT.HELD;

                onMouseStartHold();
            }

            break;

        case STATELEFT.CLICK:
        case STATELEFT.DOUBLECLICK:
            if (fTimeUp >= fTimeDoubleDelay)
            {
                stateLeft = STATELEFT.IDLE;
            }

            break;
        }

        // Handle movement related checks
        switch (stateLeft)
        {
        case STATELEFT.PRESS:
        case STATELEFT.DOUBLEPRESS:
        case STATELEFT.HELD:
            // Check if the mouse has moved far enough to count as dragging
            if (Vector3.Distance(v3Down, LibView.GetMouseLocation()) >= fMinDistDrag)
            {
                stateLeft = STATELEFT.DRAG;

                if (stateLeft != STATELEFT.HELD)
                {
                    onMouseStartHold();
                }
                onMouseStartDrag();
            }

            break;
        }

        if (stateLeft == STATELEFT.DRAG)
        {
            // Check if we've dragged off of our object then released on another object
            if (Input.GetMouseButtonUp(0))
            {
                GameObject goReleasedOver = LibView.GetObjectUnderMouse();
                if (this.gameObject != goReleasedOver)
                {
                    // Then we've released the mouse over a new object after dragging
                    onMouseReleaseOther(goReleasedOver);

                    OnLeftUp();
                }
                //Otherwise we've released the mouse over ourselves, so we'll catch this with StopDrag
            }
        }
    }