浏览代码

Merge pull request #1 from UnityTechnologies/cleanup

Minor simplifications/cleanup
/main
GitHub 4 年前
当前提交
88169043
共有 3 个文件被更改,包括 38 次插入57 次删除
  1. 44
      DOTS_Pong/Assets/Scripts/Systems/BallGoalCheckSystem.cs
  2. 30
      DOTS_Pong/Assets/Scripts/Systems/IncreaseVelocityOverTimeSystem.cs
  3. 21
      DOTS_Pong/Assets/Scripts/Systems/PaddleMovementSystem.cs

44
DOTS_Pong/Assets/Scripts/Systems/BallGoalCheckSystem.cs


public class BallGoalCheckSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Entities
.WithAll<BallTag>()
.WithStructuralChanges()
.ForEach((Entity entity, ref Translation trans) =>
{
float3 pos = trans.Value;
float bound = GameManager.main.xBound;
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Entities
.WithAll<BallTag>()
.WithStructuralChanges()
.ForEach((Entity entity, ref Translation trans) =>
{
float3 pos = trans.Value;
float bound = GameManager.main.xBound;
if (pos.x >= bound)
{
GameManager.main.PlayerScored(0);
EntityManager.DestroyEntity(entity);
}
else if (pos.x <= -bound)
{
GameManager.main.PlayerScored(1);
EntityManager.DestroyEntity(entity);
}
}).Run();
if (pos.x >= bound)
{
GameManager.main.PlayerScored(0);
EntityManager.DestroyEntity(entity);
}
else if (pos.x <= -bound)
{
GameManager.main.PlayerScored(1);
EntityManager.DestroyEntity(entity);
}
}).Run();
return inputDeps;
}
return inputDeps;
}
}

30
DOTS_Pong/Assets/Scripts/Systems/IncreaseVelocityOverTimeSystem.cs


protected override JobHandle OnUpdate(JobHandle inputDeps)
{
float deltaTime = Time.DeltaTime;
JobHandle handle = Entities
.WithReadOnly(deltaTime)
.ForEach((ref SpeedIncreaseOverTimeData data, ref PhysicsVelocity vel) =>
{
float modifier = data.increasePerSecond * deltaTime;
float3 newVel = vel.Linear;
if (newVel.x > 0)
newVel.x += modifier;
else
newVel.x -= modifier;
if (newVel.y > 0)
newVel.y += modifier;
else
newVel.y -= modifier;
Entities
.ForEach((ref SpeedIncreaseOverTimeData data, ref PhysicsVelocity vel) =>
{
var modifier = new float2(data.increasePerSecond * deltaTime);
float2 newVel = vel.Linear.xy;
newVel += math.lerp(-modifier, modifier, math.sign(newVel));
vel.Linear = newVel;
vel.Linear.xy = newVel;
}).Run();
}).Schedule(inputDeps);
return handle;
return inputDeps;
}
}

21
DOTS_Pong/Assets/Scripts/Systems/PaddleMovementSystem.cs


float deltaTime = Time.DeltaTime;
float yBound = GameManager.main.yBound;
JobHandle handle = Entities
.WithBurst()
.WithReadOnly(deltaTime)
.WithReadOnly(yBound)
.ForEach((ref Translation trans, in PaddleMovementData data) =>
{
float3 pos = trans.Value;
pos.y += data.speed * data.direction * deltaTime;
if (pos.y > yBound) pos.y = yBound;
if (pos.y < -yBound) pos.y = -yBound;
Entities
.ForEach((ref Translation trans, in PaddleMovementData data) =>
{
trans.Value.y = math.clamp(trans.Value.y + (data.speed * data.direction * deltaTime), -yBound, yBound);
}).Run();
trans.Value = pos;
}).Schedule(inputDeps);
return handle;
return inputDeps;
}
}
正在加载...
取消
保存