Ejemplo n.º 1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var input = new float3
            {
                x = Input.GetAxis("Horizontal"),
                y = Input.GetAxis("Length"),
                z = Input.GetAxis("Vertical"),
            };
            var job = new PlayerMoveJob
            {
                player_move = playerMove,
                dt          = Time.deltaTime,
                input       = input
            };

            inputDeps = job.Schedule(playerMove.Length, 64, inputDeps);
            var rot_job = new PlayerRotJob
            {
                player_move = playerMove,
                dt          = Time.deltaTime,
                input       = new float2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")),
            };

            inputDeps = rot_job.Schedule(playerMove.Length, 64, inputDeps);
            return(inputDeps);
        }
Ejemplo n.º 2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var job = new PlayerMoveJob
            {
                dt = Time.deltaTime,
            };

            return(job.Schedule(this, inputDeps));
        }
Ejemplo n.º 3
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new PlayerMoveJob
        {
            target    = m_LocalPlayer.ToComponentDataArray <Translation>(Allocator.TempJob),
            deltaTime = Time.deltaTime,
            speed     = 6
        };

        return(job.Schedule(this, inputDeps));
    }
Ejemplo n.º 4
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //return inputDeps;

            var gp    = Gamepad.current;
            var input = gp != null?getPadInput(gp) : getKeyInput(Keyboard.current);

            var tfCamera    = Camera.main.transform;
            var camRotWorld = (quaternion)tfCamera.rotation;//this.TfCamera.rotation;

            inputDeps = new PlayerMoveJob
            {
                CamRotWorld    = camRotWorld,
                DeltaTime      = UnityEngine.Time.fixedDeltaTime,//Time.DeltaTime,
                StickDir       = input.lStickDir,
                JumpForce      = input.jumpForce,
                CollisionWorld = this.buildPhysicsWorldSystem.PhysicsWorld,//.CollisionWorld,
            }
            .Schedule(this, inputDeps);

            var rs = gp != null?gp.rightStick.ReadValue() : Mouse.current.delta.ReadValue() * 0.5f;

            //tfCamera.Rotate( Vector3.left, rs.y * 90.0f * Time.deltaTime );
            tfCamera.Rotate(Vector3.up, rs.x * 90.0f * Time.DeltaTime);

            return(inputDeps);


            (float3 lStickDir, float jumpForce) getPadInput(Gamepad gp_)
            {
                var ls        = gp_.leftStick.ReadValue();
                var lStickDir = new float3(ls.x, 0.0f, ls.y);
                var jumpForce = gp_.leftShoulder.wasPressedThisFrame ? 10.0f : 0.0f;

                return(lStickDir, jumpForce);
            }

            (float3 lStickDir, float jumpForce) getKeyInput(Keyboard kb)
            {
                var l         = kb.dKey.isPressed ? 1.0f : 0.0f;
                var r         = kb.aKey.isPressed ? -1.0f : 0.0f;
                var u         = kb.wKey.isPressed ? 1.0f : 0.0f;
                var d         = kb.sKey.isPressed ? -1.0f : 0.0f;
                var lStickDir = new float3(l + r, 0.0f, u + d);
                var jumpForce = kb.spaceKey.wasPressedThisFrame ? 10.0f : 0.0f;

                return(lStickDir, jumpForce);
            }
        }
Ejemplo n.º 5
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            ArchetypeChunkComponentType <PlayerInputData>       playerInputDataRO = GetArchetypeChunkComponentType <PlayerInputData>(true);
            ArchetypeChunkComponentType <PlayerMoveData>        playerMoveDataRO  = GetArchetypeChunkComponentType <PlayerMoveData>(true);
            ArchetypeChunkComponentType <Position>              positionRW        = GetArchetypeChunkComponentType <Position>(false);
            ArchetypeChunkComponentType <Rotation>              rotationRW        = GetArchetypeChunkComponentType <Rotation>(false);
            ArchetypeChunkComponentType <EntityBoundCenterData> boundCenterDataRW = GetArchetypeChunkComponentType <EntityBoundCenterData>(false);
            ArchetypeChunkComponentType <EntityBoundMinMaxData> boundMinMaxDataRW = GetArchetypeChunkComponentType <EntityBoundMinMaxData>(false);
            ArchetypeChunkComponentType <EntityBoundOffsetData> boundOffsetDataRO = GetArchetypeChunkComponentType <EntityBoundOffsetData>(true);
            ArchetypeChunkComponentType <EntityBoundExtendData> boundExtendDataRO = GetArchetypeChunkComponentType <EntityBoundExtendData>(true);

            //CreateArchetypeChunkArray runs inside a job, we can use a job handle to make dependency on that job
            //A NativeArray<ArchetypeChunk> is allocated with the correct size on the main thread and that's what is returned, we are responsible for de-allocating it (In this case using [DeallocateOnJobCompletion] in the move job)
            //The job scheduled by CreateArchetypeChunkArray fill that array with correct chunk information
            JobHandle createChunckArrayJobHandle;
            NativeArray <ArchetypeChunk> playerMoveDataChunk = playerMoveDataGroup.CreateArchetypeChunkArray(Allocator.TempJob, out createChunckArrayJobHandle);

            //Special case when our query return no chunk at all
            if (playerMoveDataChunk.Length == 0)
            {
                createChunckArrayJobHandle.Complete();
                playerMoveDataChunk.Dispose();
                return(inputDeps);
            }

            //Make sure our movejob is dependent on the job filling the array has completed
            JobHandle moveJobDependency = JobHandle.CombineDependencies(inputDeps, createChunckArrayJobHandle);

            PlayerMoveJob playerMoveJob = new PlayerMoveJob
            {
                chunks            = playerMoveDataChunk,
                playerInputDataRO = playerInputDataRO,
                playerMoveDataRO  = playerMoveDataRO,
                positionRW        = positionRW,
                rotationRW        = rotationRW,
                boundCenterDataRW = boundCenterDataRW,
                boundMinMaxDataRW = boundMinMaxDataRW,
                boundOffsetDataRO = boundOffsetDataRO,
                boundExtendDataRO = boundExtendDataRO,
                deltaTime         = Time.deltaTime,
            };

            return(playerMoveJob.Schedule(playerMoveDataChunk.Length,
                                          MonoBehaviourECSBridge.Instance.GetJobBatchCount(playerMoveDataChunk.Length),
                                          moveJobDependency));
        }
Ejemplo n.º 6
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            PlayerMoveJob playerMoveJob = new PlayerMoveJob
            {
                playerInputDataArray          = playerMoveDataGroup.playerInputDataArray,
                playerMoveDataArray           = playerMoveDataGroup.playerMoveDataArray,
                entityInstanceRenderDataArray = playerMoveDataGroup.entityInstanceRenderDataArray,
                entityBoundCenterDataArray    = playerMoveDataGroup.entityBoundCenterDataArray,
                entityBoundMinMaxDataArray    = playerMoveDataGroup.entityBoundMinMaxDataArray,
                entityBoundOffsetDataArray    = playerMoveDataGroup.entityBoundOffsetDataArray,
                entityBoundExtendDataArray    = playerMoveDataGroup.entityBoundExtendDataArray,
                deltaTime = Time.deltaTime,
            };


            return(playerMoveJob.Schedule(playerMoveDataGroup.Length,
                                          MonoBehaviourECSBridge.Instance.GetJobBatchCount(playerMoveDataGroup.Length),
                                          inputDeps));
        }