Exemple #1
0
    /*
     * Update method called once per frame
     */
    void FixedUpdate()
    {
        // if the player is dragging the logic gate, log the movement of the player
        if (dragging)
        {
            // get mouse position
            Vector3 localMousePos = Input.mousePosition;
            Vector3 mousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(localMousePos.x, localMousePos.y, Camera.main.nearClipPlane));
            Vector3 diff          = mousePosWorld - prevMousePos;
            transform.Translate(diff);

            // if the dropzone exits, log the draggable item as dragging
            if (dropZone != null)
            {
                dropZone.OnItemDrag(this);
            }
            prevMousePos = mousePosWorld;
        }

        // if the player is moving their mouse
        if (moving)
        {
            // transform the item position
            transform.position = Vector3.Lerp(transform.position, target, 0.1f);
            // if the distance moved is very small, log the player as stopped moving
            if (Vector3.Distance(transform.position, target) < 0.01f)
            {
                moving = false;
            }
        }
    }
Exemple #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // Handle dragging
        if (dragging)
        {
            Vector3 localMousePos = Input.mousePosition;
            Vector3 mousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(localMousePos.x, localMousePos.y, Camera.main.nearClipPlane));

            Vector3 diff = mousePosWorld - prevMousePos;

            var isoTransform = GetComponent <IsoTransform>();
            if (isoTransform != null)
            {
                isoTransform.transform.Translate(diff);
            }
            else
            {
                transform.Translate(diff);
            }

            if (dropZone != null)
            {
                dropZone.OnItemDrag(this);
            }

            prevMousePos = mousePosWorld;

            if (newDropZones.Count > 0)
            {
                newDropZones[0].OnDragEnter(this);
            }
        }


        if (moving)
        {
            // Move back to home position
            var tdiff = t;
            t += Time.deltaTime / seconds;
            if (t >= 1)
            {
                moving = false;

                // Reset t so position is not overshot
                t = 1;
            }
            tdiff = t - tdiff;

            (transform as RectTransform).anchoredPosition += new Vector2((tdiff * target).x, (tdiff * target).y);
        }
    }
Exemple #3
0
    void FixedUpdate()
    {
        // Handle dragging
        if (dragging)
        {
            Vector3 localMousePos = Input.mousePosition;
            Vector3 mousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(localMousePos.x, localMousePos.y, Camera.main.nearClipPlane));

            Vector3 diff = mousePosWorld - prevMousePos;

            var isoTransform = GetComponent <IsoTransform>();
            if (isoTransform != null)
            {
                isoTransform.transform.Translate(diff);
            }
            else
            {
                transform.Translate(diff);
            }

            // Notify the current drop zone of movement
            if (dropZone != null)
            {
                dropZone.OnItemDrag(this);
            }

            prevMousePos = mousePosWorld;
        }

        if (moving)
        {
            // Move back to home position

            var tdiff = t;
            t += Time.deltaTime / seconds;
            if (t >= 1)
            {
                moving = false;

                // Reset t so position is not overshot
                t = 1;
            }
            tdiff = t - tdiff;

            transform.position += tdiff * target;
        }
    }