コード例 #1
0
    private IEnumerator handleMomentum(dfGestureBase gesture)
    {
        isMouseDown = false;

        const float SPEED = 10f;

        var direction = (Vector3)(gesture.CurrentPosition - gesture.StartPosition) * control.PixelsToUnits();
        var planes    = GeometryUtility.CalculateFrustumPlanes(control.GetCamera());

        var startTime = Time.realtimeSinceStartup;

        while (!isMouseDown)
        {
            var timeNow = Time.realtimeSinceStartup;
            var elapsed = timeNow - startTime;
            if (elapsed > 1f)
            {
                break;
            }

            control.transform.position += direction * Time.deltaTime * SPEED * (1f - elapsed);

            yield return(null);
        }

        if (!GeometryUtility.TestPlanesAABB(planes, control.GetComponent <Collider>().bounds))
        {
            control.enabled = false;
            DestroyImmediate(gameObject);
        }
    }