Ejemplo n.º 1
0
    public static void SingleRayCast(Unity.Physics.CollisionWorld world, Unity.Physics.RaycastInput input,
                                     ref Unity.Physics.RaycastHit result)
    {
        var rayCommands = new NativeArray <Unity.Physics.RaycastInput>(1, Allocator.TempJob);
        var rayResults  = new NativeArray <Unity.Physics.RaycastHit>(1, Allocator.TempJob);

        rayCommands[0] = input;
        var handle = ScheduleBatchRayCast(world, rayCommands, rayResults);

        handle.Complete();
        result = rayResults[0];
        rayCommands.Dispose();
        rayResults.Dispose();
    }
Ejemplo n.º 2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var physicsWorldSystem = Unity.Entities.World.Active.GetExistingSystem <Unity.Physics.Systems.BuildPhysicsWorld>();
        var collisionWorld     = physicsWorldSystem.PhysicsWorld.CollisionWorld;

        var mousePostion = Input.mousePosition;
        var unityRay     = Camera.main.ScreenPointToRay(mousePostion);
        var ray          = new Unity.Physics.Ray(unityRay.origin, unityRay.direction * 10000);

        Unity.Physics.RaycastInput input = new Unity.Physics.RaycastInput()
        {
            Ray    = ray,
            Filter = new CollisionFilter()
            {
                CategoryBits = ~0u,
                MaskBits     = ~0u,
                GroupIndex   = 0
            }
        };

        Unity.Physics.RaycastHit hit = new Unity.Physics.RaycastHit();

        SingleRayCast(collisionWorld, input, ref hit);
        bool haveHit = collisionWorld.CastRay(input, out hit);

        if (haveHit)
        {
            mousePostion = new float3(hit.Position.x, hit.Position.y, hit.Position.z);
        }

        //Debug.Log("Mouse Positon: " + mousePostion);

        var job = new MouseInputJob
        {
            leftClick     = Input.GetMouseButtonDown(0),
            rightClick    = Input.GetMouseButtonDown(1),
            mousePosition = mousePostion
        };


        return(job.Schedule(this, inputDeps));
    }
Ejemplo n.º 3
0
        public static Entity Raycast(Vector3 _rayOrigin, Vector3 _to)
        {
            var physicWorldSystem    = World.DefaultGameObjectInjectionWorld.GetExistingSystem <BuildPhysicsWorld>();
            var collisionWorldSystem = physicWorldSystem.PhysicsWorld.CollisionWorld;

            var raycastInput = new Unity.Physics.RaycastInput {
                Start  = _rayOrigin,
                End    = _to,
                Filter = new CollisionFilter {
                    BelongsTo    = ~0u, // Everything
                    CollidesWith = ~0u,
                    GroupIndex   = 0
                }
            };

            var raycatsHit = new Unity.Physics.RaycastHit();

            RaycastHelpers.SingleRaycast(collisionWorldSystem, raycastInput, ref raycatsHit);

            return(raycatsHit.Entity);
        }