浏览代码

Added system to speed ball up over time

/main
mikegeig 4 年前
当前提交
9031eaff
共有 9 个文件被更改,包括 82 次插入6 次删除
  1. 15
      DOTS_Pong/Assets/Ball.prefab
  2. 2
      DOTS_Pong/Assets/Paddle.prefab
  3. 2
      DOTS_Pong/Assets/Scenes/Pong.unity
  4. 4
      DOTS_Pong/Assets/Scripts/GameManager.cs
  5. 1
      DOTS_Pong/Assets/Scripts/Systems/PaddleMovementSystem.cs
  6. 7
      DOTS_Pong/Assets/Scripts/Data Components/SpeedIncreaseOverTimeData.cs
  7. 11
      DOTS_Pong/Assets/Scripts/Data Components/SpeedIncreaseOverTimeData.cs.meta
  8. 35
      DOTS_Pong/Assets/Scripts/Systems/IncreaseVelocityOverTimeSystem.cs
  9. 11
      DOTS_Pong/Assets/Scripts/Systems/IncreaseVelocityOverTimeSystem.cs.meta

15
DOTS_Pong/Assets/Ball.prefab


- component: {fileID: 3563139634143517313}
- component: {fileID: 710304911809870656}
- component: {fileID: -8228592243626107727}
- component: {fileID: 7136671490792183030}
m_Layer: 0
m_Name: Ball
m_TagString: Untagged

m_Script: {fileID: 11500000, guid: 8c7a07eafff724c4fbd9eaa76c212dd8, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &7136671490792183030
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6887475011426345520}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3a346d13eb3ccd4e91ee975f89ba2b7, type: 3}
m_Name:
m_EditorClassIdentifier:
increasePerSecond: 0.35
totalMultiplier: 0

2
DOTS_Pong/Assets/Paddle.prefab


m_Name:
m_EditorClassIdentifier:
direction: 0
speed: 3
speed: 4

2
DOTS_Pong/Assets/Scenes/Pong.unity


type: 3}
xBound: 8.5
yBound: 3
ballSpeed: 6
ballSpeed: 4
respawnDelay: 2
playerScores:
mainText: {fileID: 182749420}

4
DOTS_Pong/Assets/Scripts/GameManager.cs


void SpawnBall()
{
Entity ball = manager.Instantiate(ballEntityPrefab);
manager.AddComponent(ball, typeof(BallTag));
Vector3 dir = new Vector3(UnityEngine.Random.Range(0, 2) == 0 ? -1 : 1, UnityEngine.Random.Range(-.5f, .5f), 0f).normalized;
Vector3 speed = dir * ballSpeed;

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


using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class PaddleMovementSystem : JobComponentSystem
{

7
DOTS_Pong/Assets/Scripts/Data Components/SpeedIncreaseOverTimeData.cs


using Unity.Entities;
[GenerateAuthoringComponent]
public struct SpeedIncreaseOverTimeData : IComponentData
{
public float increasePerSecond;
}

11
DOTS_Pong/Assets/Scripts/Data Components/SpeedIncreaseOverTimeData.cs.meta


fileFormatVersion: 2
guid: f3a346d13eb3ccd4e91ee975f89ba2b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Physics;
public class IncreaseVelocityOverTimeSystem : JobComponentSystem
{
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;
vel.Linear = newVel;
}).Schedule(inputDeps);
return handle;
}
}

11
DOTS_Pong/Assets/Scripts/Systems/IncreaseVelocityOverTimeSystem.cs.meta


fileFormatVersion: 2
guid: 3c528c64cb3abed48b4f7e8efa84addf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存