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));
    }
Esempio n. 2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var physicsWorldSystem = Unity.Entities.World.Active.GetExistingManager <Unity.Physics.Systems.BuildPhysicsWorld>();
        var collisionWorld     = physicsWorldSystem.PhysicsWorld.CollisionWorld;

        var mousePostion = Input.mousePosition;
        var ray          = Camera.main.ScreenPointToRay(mousePostion);
        var direction    = ray.direction - mousePostion;

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

        Unity.Physics.RaycastHit hit;
        bool havehit = collisionWorld.CastRay(input, out hit);

        if (havehit)
        {
            mousePostion = new float3(hit.Position.x, 0, hit.Position.z);
            //Debug.Log("Hit postion" + hit.Position.x + " , 0, " + hit.Position.z);
        }

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

        return(job.Schedule(this, inputDeps));
    }