浏览代码

Merge is best practice code

/main
Mike Geig 5 年前
当前提交
57cf2e08
共有 7 个文件被更改,包括 44 次插入127 次删除
  1. 113
      DOTS_Pong/Assets/Scenes/Pong.unity
  2. 10
      DOTS_Pong/Assets/Scripts/GameManager.cs
  3. 24
      DOTS_Pong/Assets/Scripts/Systems/BallGoalCheckSystem.cs
  4. 6
      DOTS_Pong/Assets/Scripts/Systems/IncreaseVelocityOverTimeSystem.cs
  5. 9
      DOTS_Pong/Assets/Scripts/Systems/PaddleMovementSystem.cs
  6. 6
      DOTS_Pong/Assets/Scripts/Systems/PlayerInputSystem.cs
  7. 3
      DOTS_Pong/Packages/manifest.json

113
DOTS_Pong/Assets/Scenes/Pong.unity


m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

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

respawnDelay: 2
playerScores:
mainText: {fileID: 182749420}
player0Text: {fileID: 291883916}
player1Text: {fileID: 1467894795}
playerTexts:
- {fileID: 291883916}
- {fileID: 1467894795}
--- !u!1001 &137466713
PrefabInstance:
m_ObjectHideFlags: 0

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

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

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

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 8
--- !u!1 &705507993
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 705507995}
- component: {fileID: 705507994}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &705507994
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705507993}
m_Enabled: 1
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 1
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &705507995
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705507993}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &963194225
GameObject:
m_ObjectHideFlags: 0

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

10
DOTS_Pong/Assets/Scripts/GameManager.cs


using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;

public int[] playerScores;
public Text mainText;
public Text player0Text;
public Text player1Text;
public Text[] playerTexts;
Entity ballEntityPrefab;
EntityManager manager;

GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);
manager = World.DefaultGameObjectInjectionWorld.EntityManager;
oneSecond = new WaitForSeconds(1f);

public void PlayerScored(int playerID)
{
playerScores[playerID]++;
player0Text.text = playerScores[0].ToString();
player1Text.text = playerScores[1].ToString();
for(int i = 0; i < playerScores.Length && i < playerTexts.Length; i++)
playerTexts[i].text = playerScores[i].ToString();
StartCoroutine(CountdownAndSpawnBall());
}

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


using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Entities;
using UnityEngine;
using Unity.Collections;
using Unity.Mathematics;
using Unity.Jobs;

protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Entities
inputDeps.Complete();
EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.TempJob);
Entities
.WithStructuralChanges()
.ForEach((Entity entity, ref Translation trans) =>
.WithoutBurst()
.ForEach((Entity entity, in Translation trans) =>
{
float3 pos = trans.Value;
float bound = GameManager.main.xBound;

GameManager.main.PlayerScored(0);
EntityManager.DestroyEntity(entity);
ecb.DestroyEntity(entity);
EntityManager.DestroyEntity(entity);
ecb.DestroyEntity(entity);
return inputDeps;
ecb.Playback(EntityManager);
ecb.Dispose();
return new JobHandle();
}
}

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


{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
inputDeps.Complete();
.ForEach((ref SpeedIncreaseOverTimeData data, ref PhysicsVelocity vel) =>
.ForEach((ref PhysicsVelocity vel, in SpeedIncreaseOverTimeData data) =>
{
var modifier = new float2(data.increasePerSecond * deltaTime);

vel.Linear.xy = newVel;
}).Run();
return inputDeps;
return new JobHandle();
}
}

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


using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;

protected override JobHandle OnUpdate(JobHandle inputDeps)
{
inputDeps.Complete();
float deltaTime = Time.DeltaTime;
float yBound = GameManager.main.yBound;

trans.Value.y = math.clamp(trans.Value.y + (data.speed * data.direction * deltaTime), -yBound, yBound);
}).Run();
return inputDeps;
return new JobHandle();
}
}

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


{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Entities.ForEach((ref PaddleInputData inputData, ref PaddleMovementData moveData) =>
inputDeps.Complete();
Entities.ForEach((ref PaddleMovementData moveData, in PaddleInputData inputData) =>
{
moveData.direction = 0;

return inputDeps;
return new JobHandle();
}
}

3
DOTS_Pong/Packages/manifest.json


{
"dependencies": {
"com.unity.burst": "1.2.0-preview.11",
"com.unity.collab-proxy": "1.2.16",
"com.unity.entities": "0.3.0-preview.4",
"com.unity.ide.rider": "1.1.0",

"com.unity.rendering.hybrid": "0.2.0-preview.18",
"com.unity.rendering.hybrid": "0.3.0-preview.4",
"com.unity.test-framework": "1.1.3",
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.2.6",

正在加载...
取消
保存