コード例 #1
0
    private void HandleTouch(int touchFingerId, Ray touchPosition, TouchPhase touchPhase)
    {
        RaycastHit hit;

        if (Physics.Raycast(CameraRef.transform.position, touchPosition.direction * 10f, out hit))
        {
            var normalizedPoint = hit.point;

            if (normalizedPoint.x > 4.5f)
            {
                normalizedPoint.x -= 9f;
            }
            if (normalizedPoint.x < -4.5f)
            {
                normalizedPoint.x += 9f;
            }
            if (normalizedPoint.z > 8f)
            {
                normalizedPoint.z -= 16f;
            }
            if (normalizedPoint.z < -8f)
            {
                normalizedPoint.z += 16f;
            }

            // Inform any manager of input
            var colliders = Physics.OverlapSphere(normalizedPoint, 0.01f);

            // TODO: do overlap sphere for UI elements too

            foreach (var overlapCollider in colliders)
            {
                // Depending on the tag of the object, send information
                if (overlapCollider.gameObject.CompareTag("Paintable"))
                {
                    if (touchPhase == TouchPhase.Began || touchPhase == TouchPhase.Moved)
                    {
                        _directionPainter.SendClickDrag(normalizedPoint);
                    }

                    if (touchPhase == TouchPhase.Ended)
                    {
                        _directionPainter.SendRelease(normalizedPoint);
                    }

                    break;
                }
            }
        }
    }