浏览代码

Updated to Entities 0.3.0 and updated to latest syntaxes

/main
mikegeig 5 年前
当前提交
a9378fb9
共有 28 个文件被更改,包括 170 次插入137 次删除
  1. 13
      DOTS_Pong/Assets/Ball.prefab
  2. 29
      DOTS_Pong/Assets/Paddle.prefab
  3. 44
      DOTS_Pong/Assets/Scenes/Pong.unity
  4. 5
      DOTS_Pong/Assets/Scripts/GameManager.cs
  5. 3
      DOTS_Pong/Packages/manifest.json
  6. 2
      DOTS_Pong/Assets/Scripts/Data Components/PaddleDataComponents.cs.meta
  7. 8
      DOTS_Pong/Assets/Scripts/Data Components.meta
  8. 8
      DOTS_Pong/Assets/Scripts/Systems.meta
  9. 5
      DOTS_Pong/Assets/Scripts/Data Components/BallTag.cs
  10. 9
      DOTS_Pong/Assets/Scripts/Data Components/PaddleDataComponents.cs
  11. 8
      DOTS_Pong/Assets/Scripts/Data Components/PaddleMovementData.cs
  12. 11
      DOTS_Pong/Assets/Scripts/Data Components/PaddleMovementData.cs.meta
  13. 35
      DOTS_Pong/Assets/Scripts/Systems/PaddleMovementSystem.cs
  14. 19
      DOTS_Pong/Assets/Scripts/Systems/PlayerInputSystem.cs
  15. 24
      DOTS_Pong/Assets/Scripts/DataComponents.cs
  16. 26
      DOTS_Pong/Assets/Scripts/PaddleConversion.cs
  17. 40
      DOTS_Pong/Assets/Scripts/PaddleMovementSystem.cs
  18. 18
      DOTS_Pong/Assets/Scripts/PlayerInputSystem.cs
  19. 0
      /DOTS_Pong/Assets/Scenes/Pong.unity.meta
  20. 0
      /DOTS_Pong/Assets/Scenes/Pong.unity
  21. 0
      /DOTS_Pong/Assets/Scripts/Systems/BallGoalCheckSystem.cs
  22. 0
      /DOTS_Pong/Assets/Scripts/Systems/BallGoalCheckSystem.cs.meta
  23. 0
      /DOTS_Pong/Assets/Scripts/Data Components/BallTag.cs.meta
  24. 0
      /DOTS_Pong/Assets/Scripts/Data Components/PaddleDataComponents.cs.meta
  25. 0
      /DOTS_Pong/Assets/Scripts/Systems/PaddleMovementSystem.cs.meta
  26. 0
      /DOTS_Pong/Assets/Scripts/Systems/PlayerInputSystem.cs.meta

13
DOTS_Pong/Assets/Ball.prefab


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

m_Name:
m_EditorClassIdentifier:
ConversionMode: 0
--- !u!114 &-8228592243626107727
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: 8c7a07eafff724c4fbd9eaa76c212dd8, type: 3}
m_Name:
m_EditorClassIdentifier:

29
DOTS_Pong/Assets/Paddle.prefab


- component: {fileID: 8502827632645724346}
- component: {fileID: 6644258564744900212}
- component: {fileID: 1898650166706972447}
- component: {fileID: 6505968936035989361}
- component: {fileID: 5998213871152161582}
- component: {fileID: 3090207904209200674}
m_Layer: 0
m_Name: Paddle
m_TagString: Untagged

m_Interpolate: 0
m_Constraints: 126
m_CollisionDetection: 0
--- !u!114 &6505968936035989361
--- !u!114 &7727572489642212705
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a52f690e10769f348a4b5c234e49c6a9, type: 3}
m_Script: {fileID: 11500000, guid: ea7d7495833204790ba1d3a8755397f8, type: 3}
playerID: 0
speed: 3
ConversionMode: 0
--- !u!114 &5998213871152161582
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1314940309337419778}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ccccff6b24fc6ec4884cc374f823d3d7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &7727572489642212705
--- !u!114 &3090207904209200674
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ea7d7495833204790ba1d3a8755397f8, type: 3}
m_Script: {fileID: 11500000, guid: 145ec430f5c0db0488b9fa9b3b20e74c, type: 3}
ConversionMode: 0
direction: 0
speed: 3

44
DOTS_Pong/Assets/Scenes/Pong.unity


m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &108099016
MonoBehaviour:

- target: {fileID: 5479178889855886559, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}
propertyPath: m_Name
value: Wall (1)
value: Wall lower
objectReference: {fileID: 0}
- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}

- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
value: -0
value: 0
value: -0
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}

- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}
propertyPath: m_RootOrder
value: 6
value: 5
objectReference: {fileID: 0}
- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}

- target: {fileID: 1314940309337419778, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}
propertyPath: m_Name
value: Paddle (1)
value: Paddle 1
objectReference: {fileID: 0}
- target: {fileID: 5706543593829935943, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}

- target: {fileID: 5706543593829935943, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}
propertyPath: m_RootOrder
value: 4
value: 8
objectReference: {fileID: 0}
- target: {fileID: 5706543593829935943, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5998213871152161582, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}
propertyPath: upKey
value: 273
objectReference: {fileID: 0}
- target: {fileID: 5998213871152161582, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}
propertyPath: downKey
value: 274
objectReference: {fileID: 0}
- target: {fileID: 6505968936035989361, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}
propertyPath: playerID

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &291883914
GameObject:

- {fileID: 291883915}
- {fileID: 1467894794}
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}

- target: {fileID: 1314940309337419778, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}
propertyPath: m_Name
value: Paddle
value: Paddle 0
objectReference: {fileID: 0}
- target: {fileID: 5706543593829935943, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}

- target: {fileID: 5706543593829935943, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}
propertyPath: m_RootOrder
value: 3
value: 7
objectReference: {fileID: 0}
- target: {fileID: 5706543593829935943, guid: 12afeaf2bb15d604ab614517d7cfa828,
type: 3}

- target: {fileID: 5479178889855886559, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}
propertyPath: m_Name
value: Wall
value: Wall upper
objectReference: {fileID: 0}
- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}

- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
value: -0
value: 0
value: -0
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}

- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}
propertyPath: m_RootOrder
value: 5
value: 4
objectReference: {fileID: 0}
- target: {fileID: 5568865997738305383, guid: 6fb40a4c3651fe64cacb4f9131c73801,
type: 3}

5
DOTS_Pong/Assets/Scripts/GameManager.cs


main = this;
playerScores = new int[2];
GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);
ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, World.Active);
oneSecond = new WaitForSeconds(1f);
delay = new WaitForSeconds(respawnDelay);

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;//UnityEngine.Random.insideUnitCircle * ballSpeed;
Vector3 speed = dir * ballSpeed;
PhysicsVelocity velocity = new PhysicsVelocity()
{

3
DOTS_Pong/Packages/manifest.json


{
"dependencies": {
"com.unity.collab-proxy": "1.2.16",
"com.unity.entities": "0.2.0-preview.18",
"com.unity.entities": "0.3.0-preview.4",
"com.unity.quicksearch": "1.4.1",
"com.unity.rendering.hybrid": "0.2.0-preview.18",
"com.unity.test-framework": "1.1.3",
"com.unity.textmeshpro": "2.0.1",

2
DOTS_Pong/Assets/Scripts/Data Components/PaddleDataComponents.cs.meta


fileFormatVersion: 2
guid: a52f690e10769f348a4b5c234e49c6a9
guid: ccccff6b24fc6ec4884cc374f823d3d7
MonoImporter:
externalObjects: {}
serializedVersion: 2

8
DOTS_Pong/Assets/Scripts/Data Components.meta


fileFormatVersion: 2
guid: f87a7167ff15fd84dac4011f8c443487
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
DOTS_Pong/Assets/Scripts/Systems.meta


fileFormatVersion: 2
guid: 530d0e867556ff14ab18a45ce53c8a9c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

5
DOTS_Pong/Assets/Scripts/Data Components/BallTag.cs


using Unity.Entities;
[GenerateAuthoringComponent]
public struct BallTag : IComponentData
{ }

9
DOTS_Pong/Assets/Scripts/Data Components/PaddleDataComponents.cs


using Unity.Entities;
using UnityEngine;
[GenerateAuthoringComponent]
public struct PaddleInputData : IComponentData
{
public KeyCode upKey;
public KeyCode downKey;
}

8
DOTS_Pong/Assets/Scripts/Data Components/PaddleMovementData.cs


using Unity.Entities;
[GenerateAuthoringComponent]
public struct PaddleMovementData : IComponentData
{
public int direction;
public float speed;
}

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


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

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


using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class PaddleMovementSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
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;
trans.Value = pos;
}).Schedule(inputDeps);
return handle;
}
}

19
DOTS_Pong/Assets/Scripts/Systems/PlayerInputSystem.cs


using Unity.Entities;
using Unity.Jobs;
using UnityEngine;
public class PlayerInputSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Entities.ForEach((ref PaddleInputData inputData, ref PaddleMovementData moveData) =>
{
moveData.direction = 0;
moveData.direction += Input.GetKey(inputData.upKey) ? 1 : 0;
moveData.direction -= Input.GetKey(inputData.downKey) ? 1 : 0;
}).Run();
return inputDeps;
}
}

24
DOTS_Pong/Assets/Scripts/DataComponents.cs


using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using UnityEngine;
public struct PlayerInputData : IComponentData
{
public KeyCode upKey;
public KeyCode downKey;
}
public struct PlayerData : IComponentData
{
public int playerID;
}
public struct PaddleMovementData : IComponentData
{
public int direction;
public float speed;
}
public struct BallTag : IComponentData
{ }

26
DOTS_Pong/Assets/Scripts/PaddleConversion.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
public class PaddleConversion : MonoBehaviour, IConvertGameObjectToEntity
{
public int playerID;
public float speed = 3f;
public KeyCode upKey;
public KeyCode downKey;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponentData(entity, new PlayerData { playerID = playerID });
dstManager.AddComponentData(entity, new PaddleMovementData { direction = 0, speed = speed });
PlayerInputData data = new PlayerInputData
{
upKey = upKey,
downKey = downKey
};
dstManager.AddComponentData(entity, data);
}
}

40
DOTS_Pong/Assets/Scripts/PaddleMovementSystem.cs


using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class PaddleMovementSystem : JobComponentSystem
{
public struct MoveJob : IJobForEach<PaddleMovementData, Translation>
{
public float deltaTime;
public float yBound;
public void Execute([ReadOnly] ref PaddleMovementData data, ref Translation trans)
{
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;
trans.Value = pos;
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
MoveJob job = new MoveJob
{
deltaTime = Time.DeltaTime,
yBound = GameManager.main.yBound
};
return job.Schedule(this, inputDeps);
}
}

18
DOTS_Pong/Assets/Scripts/PlayerInputSystem.cs


using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using UnityEngine;
public class PlayerInputSystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach((ref PlayerInputData inputData, ref PaddleMovementData moveData) =>
{
moveData.direction = 0;
moveData.direction += Input.GetKey(inputData.upKey) ? 1 : 0;
moveData.direction -= Input.GetKey(inputData.downKey) ? 1 : 0;
});
}
}

/DOTS_Pong/Assets/Scenes/SampleScene.unity.meta → /DOTS_Pong/Assets/Scenes/Pong.unity.meta

/DOTS_Pong/Assets/Scenes/SampleScene.unity → /DOTS_Pong/Assets/Scenes/Pong.unity

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

/DOTS_Pong/Assets/Scripts/BallGoalCheckSystem.cs.meta → /DOTS_Pong/Assets/Scripts/Systems/BallGoalCheckSystem.cs.meta

/DOTS_Pong/Assets/Scripts/DataComponents.cs.meta → /DOTS_Pong/Assets/Scripts/Data Components/BallTag.cs.meta

/DOTS_Pong/Assets/Scripts/PaddleConversion.cs.meta → /DOTS_Pong/Assets/Scripts/Data Components/PaddleDataComponents.cs.meta

/DOTS_Pong/Assets/Scripts/PaddleMovementSystem.cs.meta → /DOTS_Pong/Assets/Scripts/Systems/PaddleMovementSystem.cs.meta

/DOTS_Pong/Assets/Scripts/PlayerInputSystem.cs.meta → /DOTS_Pong/Assets/Scripts/Systems/PlayerInputSystem.cs.meta

正在加载...
取消
保存