예제 #1
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);
            }
        }