private void SubmitHit(bool preview)
        {
            if (pointA != null && pointB != null)
            {
                var vector        = pointB.position - pointA.position;
                var maxDistance   = vector.magnitude;
                var ray           = new Ray(pointA.position, vector);
                var hit2D         = Physics2D.GetRayIntersection(ray, float.PositiveInfinity, layers);
                var hit3D         = default(RaycastHit);
                var finalPosition = default(Vector3);
                var finalRotation = default(Quaternion);

                // Hit 3D?
                if (Physics.Raycast(ray, out hit3D, maxDistance, layers) == true && (hit2D.collider == null || hit3D.distance < hit2D.distance))
                {
                    CalcHitData(hit3D.point, hit3D.normal, ray, out finalPosition, out finalRotation);

                    fraction = (hit3D.distance + offset) / maxDistance;

                    if (emit == EmitType.PointsIn3D)
                    {
                        connector.SubmitPoint(gameObject, preview, priority, pressure, finalPosition, finalRotation, this);
                    }
                    else if (emit == EmitType.PointsOnUV)
                    {
                        connector.HitCache.InvokeCoord(gameObject, preview, priority, pressure, new P3dHit(hit3D), finalRotation);
                    }
                    else if (emit == EmitType.TrianglesIn3D)
                    {
                        connector.HitCache.InvokeTriangle(gameObject, preview, priority, pressure, hit3D, finalRotation);
                    }
                }
                // Hit 2D?
                else if (hit2D.collider != null)
                {
                    CalcHitData(hit2D.point, hit2D.normal, ray, out finalPosition, out finalRotation);

                    fraction = (hit3D.distance + offset) / maxDistance;

                    if (emit == EmitType.PointsIn3D)
                    {
                        connector.SubmitPoint(gameObject, preview, priority, pressure, finalPosition, finalRotation, this);
                    }
                }
                else
                {
                    connector.BreakHits(this);

                    fraction = 1.0f;
                }
            }
        }
예제 #2
0
        protected void PaintAt(P3dPointConnector connector, P3dHitCache hitCache, Vector2 screenPosition, Vector2 screenPositionOld, bool preview, float pressure, object owner)
        {
            var camera = P3dHelper.GetCamera(_camera);

            if (camera != null)
            {
                if (touchOffset != 0.0f && P3dInputManager.TouchCount > 0)
                {
                    screenPosition.y += touchOffset / P3dInputManager.ScaleFactor;
                }

                var ray           = camera.ScreenPointToRay(screenPosition);
                var hit2D         = Physics2D.GetRayIntersection(ray, float.PositiveInfinity, layers);
                var hit3D         = default(RaycastHit);
                var finalPosition = default(Vector3);
                var finalRotation = default(Quaternion);

                // Hit 3D?
                if (Physics.Raycast(ray, out hit3D, float.PositiveInfinity, layers) == true && (hit2D.collider == null || hit3D.distance < hit2D.distance))
                {
                    CalcHitData(hit3D.point, hit3D.normal, ray, camera, screenPositionOld, out finalPosition, out finalRotation);

                    if (emit == EmitType.PointsIn3D)
                    {
                        if (connector != null)
                        {
                            connector.SubmitPoint(gameObject, preview, priority, pressure, finalPosition, finalRotation, owner);
                        }
                        else
                        {
                            hitCache.InvokePoint(gameObject, preview, priority, pressure, finalPosition, finalRotation);
                        }

                        return;
                    }
                    else if (emit == EmitType.PointsOnUV)
                    {
                        hitCache.InvokeCoord(gameObject, preview, priority, pressure, new P3dHit(hit3D), finalRotation);

                        return;
                    }
                    else if (emit == EmitType.TrianglesIn3D)
                    {
                        hitCache.InvokeTriangle(gameObject, preview, priority, pressure, hit3D, finalRotation);

                        return;
                    }
                }
                // Hit 2D?
                else if (hit2D.collider != null)
                {
                    CalcHitData(hit2D.point, hit2D.normal, ray, camera, screenPositionOld, out finalPosition, out finalRotation);

                    if (emit == EmitType.PointsIn3D)
                    {
                        if (connector != null)
                        {
                            connector.SubmitPoint(gameObject, preview, priority, pressure, finalPosition, finalRotation, owner);
                        }
                        else
                        {
                            hitCache.InvokePoint(gameObject, preview, priority, pressure, finalPosition, finalRotation);
                        }

                        return;
                    }
                }
            }

            if (connector != null)
            {
                connector.BreakHits(owner);
            }
        }
예제 #3
0
 private void SubmitHit(bool preview)
 {
     connector.SubmitPoint(gameObject, preview, priority, pressure, transform.position, transform.rotation, this);
 }