浏览代码

Merge branch 'testing-Sync' into dots-physics

/dots-physics
mikegeig 5 年前
当前提交
be54606d
共有 24 个文件被更改,包括 2626 次插入419 次删除
  1. 7
      Assets/Scripts/Boat/Engine.cs
  2. 2
      Assets/Unity Physics Items/AIController_DOTS.cs.meta
  3. 2
      Assets/Unity Physics Items/BoatBodyComponent.cs
  4. 30
      Assets/Unity Physics Items/BuoyancyVisualizer.cs
  5. 22
      Assets/Unity Physics Items/BuoyantObject_DOTS.cs
  6. 4
      Assets/Unity Physics Items/Components/BoatDataComponents.cs
  7. 940
      Assets/Unity Physics Items/Physics Scene.unity
  8. 14
      Assets/Unity Physics Items/Prefabs/BoatEntity.prefab
  9. 209
      Assets/Unity Physics Items/Prefabs/DOTS Buoy.prefab
  10. 101
      Assets/Unity Physics Items/Systems/ApplyBuoyancyForceSystem.cs
  11. 31
      Assets/Unity Physics Items/Systems/DriveSystem.cs
  12. 75
      Assets/Unity Physics Items/Systems/GertsnerSystem.cs
  13. 7
      Assets/Unity Physics Items/Systems/InputSystem.cs
  14. 4
      Packages/manifest.json
  15. 52
      Assets/Unity Physics Items/DOTSTransformManager.cs
  16. 11
      Assets/Unity Physics Items/DOTSTransformManager.cs.meta
  17. 27
      Assets/Unity Physics Items/GridSpawner.cs
  18. 11
      Assets/Unity Physics Items/GridSpawner.cs.meta
  19. 386
      Assets/Unity Physics Items/Prefabs/BoatEntityNew.prefab
  20. 7
      Assets/Unity Physics Items/Prefabs/BoatEntityNew.prefab.meta
  21. 1001
      Assets/Unity Physics Items/Prefabs/DOTS Buoys.prefab
  22. 7
      Assets/Unity Physics Items/Prefabs/DOTS Buoys.prefab.meta
  23. 84
      Assets/Unity Physics Items/Systems/UpdateObjectTransformSystem.cs
  24. 11
      Assets/Unity Physics Items/Systems/UpdateObjectTransformSystem.cs.meta

7
Assets/Scripts/Boat/Engine.cs


void Awake()
{
engineSound.time = UnityEngine.Random.Range(0f, engineSound.clip.length); // randomly start the engine sound
waterSound.time = UnityEngine.Random.Range(0f, waterSound.clip.length); // randomly start the water sound
if(engineSound)
engineSound.time = UnityEngine.Random.Range(0f, engineSound.clip.length); // randomly start the engine sound
if(waterSound)
waterSound.time = UnityEngine.Random.Range(0f, waterSound.clip.length); // randomly start the water sound
_guid = GetInstanceID(); // Get the engines GUID for the buoyancy system
}

2
Assets/Unity Physics Items/AIController_DOTS.cs.meta


externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
executionOrder: -17000
icon: {instanceID: 0}
userData:
assetBundleName:

2
Assets/Unity Physics Items/BoatBodyComponent.cs


public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponent(entity, typeof(CopyTransformToGameObject));
//dstManager.AddComponent(entity, typeof(SyncTransformTag));
//DOTSTransformManager.Register(entity, transform);
}
}

30
Assets/Unity Physics Items/BuoyancyVisualizer.cs


private void OnDrawGizmos()
{
if (!Application.isPlaying)
if (!Application.isPlaying || (boat == Entity.Null))
Gizmos.color = Color.red;
// engine at first position
{
Gizmos.color = Color.green;
var enginePos = transform.TransformPoint(offsets[0].Value);
var waterPos = transform.TransformPoint(offsets[0].Value.x, heights[0].Value.y, offsets[0].Value.z);
Gizmos.DrawSphere(waterPos, .15f);
Gizmos.DrawLine(waterPos, enginePos);
}
for (int i = 0; i < heights.Length; i++)
Gizmos.DrawSphere(new Vector3(transform.position.x + offsets[i].Value.x, heights[i].Value.y, offsets[i].Value.z + transform.position.z), .1f);
}
{
Gizmos.color = Color.red;
for (int i = 1; i < heights.Length; i++)
{
var waterPos = transform.TransformPoint(offsets[0].Value.x, heights[0].Value.y, offsets[0].Value.z);
Gizmos.DrawSphere(transform.TransformPoint(offsets[i].Value.x, heights[i].Value.y, offsets[i].Value.z), .1f);
}
}
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
if (boat == Entity.Null)
{
boat = conversionSystem.GetPrimaryEntity(transform.parent);

22
Assets/Unity Physics Items/BuoyantObject_DOTS.cs


private DebugDrawing[] debugInfo; // For drawing force gizmos
public float percentSubmerged = 0f;
public GameObject childObject;
[ContextMenu("Initialize")]
void Init()
{

if (body)
body.Convert(conversionSystem.GetPrimaryEntity(body), dstManager, conversionSystem);
}
if (childObject != null)
{
dstManager.AddComponent(entity, typeof(SyncTransformTag));
GameObject go = Instantiate(childObject, transform.position, transform.rotation) as GameObject;
if(go.GetComponent<BuoyantObject>()) Destroy(go.GetComponent<BuoyantObject>());
if(go.GetComponent<Engine>()) Destroy(go.GetComponent<Engine>());
if(go.GetComponent<BoatController>()) Destroy(go.GetComponent<BoatController>());
if (go.GetComponent<Rigidbody>()) Destroy(go.GetComponent<Rigidbody>());
if (go.GetComponent<Collider>()) Destroy(go.GetComponent<Collider>());
go.transform.parent = transform.parent;
DOTSTransformManager.Register(entity, go.transform);
}
}
struct DebugDrawing
{

4
Assets/Unity Physics Items/Components/BoatDataComponents.cs


public float3 Value;
}
public struct SimpleBuoyantTag : IComponentData { }
public struct SimpleBuoyantTag : IComponentData { }
public struct SyncTransformTag : IComponentData { }

940
Assets/Unity Physics Items/Physics Scene.unity
文件差异内容过多而无法显示
查看文件

14
Assets/Unity Physics Items/Prefabs/BoatEntity.prefab


- component: {fileID: 3453465595108755947}
- component: {fileID: 2092507921}
- component: {fileID: 2092507922}
- component: {fileID: 1507960575}
m_Layer: 11
m_Name: _Boat
m_TagString: boat

m_Name:
m_EditorClassIdentifier:
ConversionMode: 1
--- !u!114 &1507960575
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3456711171255019043}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d7931266a1a8224ea5dfc21625ffde1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &3456818236728735511
GameObject:
m_ObjectHideFlags: 0

colliders:
- {fileID: 1031304347490252193}
percentSubmerged: 0
childObject: {fileID: 0}
--- !u!114 &1531988078
MonoBehaviour:
m_ObjectHideFlags: 0

209
Assets/Unity Physics Items/Prefabs/DOTS Buoy.prefab


m_Component:
- component: {fileID: 2708360549199760384}
- component: {fileID: 2710428803363308577}
- component: {fileID: 2710428803363308590}
- component: {fileID: 2710428803363308591}
- component: {fileID: 2710428803363308576}
- component: {fileID: 63710510}
m_Layer: 0
m_Name: DOTS Buoy
m_TagString: Untagged

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2710428803363308588}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -99.4, y: 0.686, z: 1.6}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 3824473869457911851}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

- {x: 0, y: 0, z: 0}
colliders: []
percentSubmerged: 0
--- !u!114 &2710428803363308590
childObject: {fileID: 1619300153551722, guid: 0585231fa8a324f28ad94a6ea1420862,
type: 3}
--- !u!114 &63710510
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Name:
m_EditorClassIdentifier:
ConversionMode: 0
--- !u!114 &2710428803363308591
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2710428803363308588}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b275e5f92732148048d7b77e264ac30e, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ShapeType: 1
m_PrimitiveCenter:
x: -0.000000059604645
y: -0.525918
z: 0.030020773
m_PrimitiveSize:
x: 1.2003503
y: 1.2003503
z: 1.7400162
m_PrimitiveOrientation:
Value:
x: 270
y: 270
z: 0
RotationOrder: 4
m_Capsule:
Height: 1.7400162
Radius: 0.60017514
Axis: 2
m_Cylinder:
Height: 1.7400162
Radius: 0.60017514
Axis: 2
m_SphereRadius: 0.8700081
m_ConvexRadius: 0.05
m_CustomMesh: {fileID: 0}
m_Material:
m_SupportsTemplate: 1
m_Template: {fileID: 0}
m_IsTrigger:
m_Override: 0
m_Value: 0
m_Friction:
m_Override: 0
m_Value:
Value: 0
CombineMode: 0
m_Restitution:
m_Override: 0
m_Value:
Value: 0
CombineMode: 2
m_BelongsTo:
m_Override: 0
m_Value: 0101010101010101010101010101010101010101010101010101010101010101
m_CollidesWith:
m_Override: 0
m_Value: 0101010101010101010101010101010101010101010101010101010101010101
m_RaisesCollisionEvents:
m_Override: 0
m_Value: 0
m_CustomTags:
m_Override: 0
m_Value: 0000000000000000
--- !u!114 &2710428803363308576
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2710428803363308588}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ccea9ea98e38942e0b0938c27ed1903e, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MotionType: 1
m_Mass: 1
m_LinearDamping: 0.01
m_AngularDamping: 0.05
m_InitialLinearVelocity:
x: 0
y: 0
z: 0
m_InitialAngularVelocity:
x: 0
y: 0
z: 0
m_GravityFactor: 1
m_OverrideDefaultMassDistribution: 0
m_CenterOfMass:
x: 0
y: 0
z: 0
m_Orientation:
Value:
x: 0
y: 0
z: 0
RotationOrder: 4
m_InertiaTensor:
x: 0.4
y: 0.4
z: 0.4
m_CustomTags:
Tag00: 0
Tag01: 0
Tag02: 0
Tag03: 0
Tag04: 0
Tag05: 0
Tag06: 0
Tag07: 0
--- !u!1 &3824473869457911848
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3824473869457911851}
- component: {fileID: 3824473869457911853}
- component: {fileID: 3824473869457911850}
m_Layer: 0
m_Name: BuoyMesh
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3824473869457911851
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3824473869457911848}
m_LocalRotation: {x: 1, y: 0, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2708360549199760384}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 180, y: 0, z: 0}
--- !u!33 &3824473869457911853
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3824473869457911848}
m_Mesh: {fileID: 4300016, guid: 92a669df93f0d4f99bd8fa27767e8c9e, type: 3}
--- !u!23 &3824473869457911850
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3824473869457911848}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: b1aaf92c06be94931a4e515a4812f42e, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0

101
Assets/Unity Physics Items/Systems/ApplyBuoyancyForceSystem.cs


using Unity.Physics.Extensions;
using Unity.Physics.Systems;
using Unity.Physics;
using Unity.Collections.LowLevel.Unsafe;
float lastTime = 0;
var simpleQuery = GetEntityQuery(typeof(Translation), typeof(Rotation), typeof(BuoyancyNormal), typeof(SimpleBuoyantTag));
var simpleEntities = simpleQuery.ToEntityArray(Allocator.TempJob);
var forceJob = new ForceJob()
var simpleJob = new SimpleForceJob()
offsetBuffer = offsets,
entities = simpleEntities,
translations = GetComponentDataFromEntity<Translation>(false),
rotations = GetComponentDataFromEntity<Rotation>(false),
normals = GetComponentDataFromEntity<BuoyancyNormal>(true),
var simpleHandle = simpleJob.Schedule(simpleEntities.Length, 32, inputDeps);
var forceJobHandle = forceJob.Schedule(this, inputDeps);
var physicsQuery = GetEntityQuery(typeof(Translation), typeof(Rotation), typeof(PhysicsVelocity), typeof(PhysicsMass), typeof(PhysicsDamping), typeof(BuoyantData));
var physicalEntities = physicsQuery.ToEntityArray(Allocator.TempJob);
var simpleJob = new SimpleForceJob()
var forceJob = new ForceJob()
entities = physicalEntities,
translations = GetComponentDataFromEntity<Translation>(true),
rotations = GetComponentDataFromEntity<Rotation>(true),
velocities = GetComponentDataFromEntity<PhysicsVelocity>(false),
masses = GetComponentDataFromEntity<PhysicsMass>(true),
dampings = GetComponentDataFromEntity<PhysicsDamping>(true),
datas = GetComponentDataFromEntity<BuoyantData>(true),
offsetBuffer = offsets,
var forceJobHandle = forceJob.Schedule(physicalEntities.Length, 1, simpleHandle);
return simpleJob.Schedule(this, forceJobHandle);
return forceJobHandle;
//return JobHandle.CombineDependencies(forceJobHandle, simpleHandle);
//[BurstCompile]
public struct ForceJob : IJobForEachWithEntity<Translation, Rotation, PhysicsVelocity, PhysicsMass, PhysicsDamping, BuoyantData>
[BurstCompile]
public struct ForceJob : IJobParallelFor
public float dt;
[ReadOnly] public float dt;
[DeallocateOnJobCompletion]
[ReadOnly] public NativeArray<Entity> entities;
[NativeDisableParallelForRestriction]
[ReadOnly] public ComponentDataFromEntity<Translation> translations;
[NativeDisableParallelForRestriction]
[ReadOnly] public ComponentDataFromEntity<Rotation> rotations;
[ReadOnly] public ComponentDataFromEntity<PhysicsMass> masses;
[ReadOnly] public ComponentDataFromEntity<PhysicsDamping> dampings;
[ReadOnly] public ComponentDataFromEntity<BuoyantData> datas;
[ReadOnly] public BufferFromEntity<VoxelOffset> offsetBuffer;
[ReadOnly] public BufferFromEntity<VoxelHeight> heightBuffer;
[ReadOnly]
public BufferFromEntity<VoxelOffset> offsetBuffer;
[NativeDisableParallelForRestriction]
public ComponentDataFromEntity<PhysicsVelocity> velocities;
[ReadOnly]
public BufferFromEntity<VoxelHeight> heightBuffer;
public void Execute(Entity entity, int index, [ReadOnly] ref Translation pos, [ReadOnly] ref Rotation rot, ref PhysicsVelocity vel, ref PhysicsMass mass, ref PhysicsDamping damping, [ReadOnly] ref BuoyantData data)
public void Execute(int index)
var entity = entities[index];
var pos = translations[entity];
var rot = rotations[entity];
var vel = velocities[entity];
var mass = masses[entity];
var damping = dampings[entity];
var data = datas[entity];
DynamicBuffer<VoxelOffset> offsets = offsetBuffer[entity];
DynamicBuffer<VoxelHeight> heights = heightBuffer[entity];

}
}
velocities[entity] = vel;
//Apply drag
//data.percentSubmerged = Mathf.Lerp(data.percentSubmerged, submergedAmount, 0.25f);
//damping.Linear = data.baseDrag + (data.baseDrag * (data.percentSubmerged * 10f));

[BurstCompile]
[RequireComponentTag(typeof(SimpleBuoyantTag))]
public struct SimpleForceJob : IJobForEachWithEntity<Translation, Rotation, BuoyancyNormal>
public struct SimpleForceJob : IJobParallelFor
[ReadOnly]
public BufferFromEntity<VoxelHeight> heightBuffer;
[DeallocateOnJobCompletion]
[ReadOnly] public NativeArray<Entity> entities;
[ReadOnly] public ComponentDataFromEntity<BuoyancyNormal> normals;
[ReadOnly] public BufferFromEntity<VoxelHeight> heightBuffer;
[NativeDisableParallelForRestriction]
public ComponentDataFromEntity<Translation> translations;
public void Execute(Entity entity, int index, [ReadOnly] ref Translation pos, [ReadOnly] ref Rotation rot, [ReadOnly] ref BuoyancyNormal normal)
[NativeDisableParallelForRestriction]
public ComponentDataFromEntity<Rotation> rotations;
public void Execute(int index)
var entity = entities[index];
var pos = translations[entity];
var rot = rotations[entity];
var normal = normals[entity];
//var position = pos.Value;
//position.y = heights[0].Value.y;
//pos.Value = position;
//transform.up = Vector3.Slerp(transform.up, normals[0], Time.deltaTime);
translations[entity] = pos;
rotations[entity] = rot;
}
}
}

31
Assets/Unity Physics Items/Systems/DriveSystem.cs


{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var job = new DriveWithInputJob()
{
dt = Time.deltaTime,
var heights = GetBufferFromEntity<VoxelHeight>(false);
var job = new DriveWithInputJob()
{
dt = Time.deltaTime,
HeightBuffers = heights,
};
return job.Schedule(this, inputDeps);

{
public float dt;
[ReadOnly]
public BufferFromEntity<VoxelHeight> HeightBuffers;
public void Execute(Entity entity, int index, [ReadOnly] ref Translation pos, [ReadOnly] ref Rotation rot, ref PhysicsVelocity vel, [ReadOnly] ref PhysicsMass mass, ref DrivingData driveData, ref InputData inputData)
public void Execute(Entity entity, int index, [ReadOnly] ref Translation pos, [ReadOnly] ref Rotation rot, ref PhysicsVelocity vel, [ReadOnly] ref PhysicsMass mass, ref DrivingData driveData, ref InputData inputData)
float velMag = math.dot(vel.Linear, vel.Linear);
DynamicBuffer<VoxelHeight> heights = HeightBuffers[entity];
float velMag = math.dot(vel.Linear, vel.Linear);
var wp = math.transform(entityTransform, driveData.engineOffset);// + mass.CenterOfMass);
//if (wp.y <= -0.1f) // if the engine is deeper than 0.1
//{
inputData.throttle = Mathf.Clamp(inputData.throttle, 0f, 1f); // clamp for reasonable values
var engineWP = math.transform(entityTransform, driveData.engineOffset);
var waterWP = math.rotate(rot.Value, heights[0].Value) + engineWP;
var yHeight = heights[0].Value.y - engineWP.y;
//Debug.Log($"yHeight:{yHeight}");
//if (yHeight < -0.1f) // if the engine is deeper than 0.1
{
inputData.throttle = Mathf.Clamp(inputData.throttle, 0f, 1f); // clamp for reasonable values
float3 forward = math.forward(rot.Value);
forward.y = 0f;
forward = math.normalize(forward);

inputData.steering = Mathf.Clamp(inputData.steering, -1f, 1f); // clamp for reasonable values
var sTorque = new float3(0f, driveData.steeringTorque, -driveData.steeringTorque * .5f) * inputData.steering / mass.InverseInertia;
vel.ApplyAngularImpulse(mass, sTorque * dt);
//}
}
}
}
}

75
Assets/Unity Physics Items/Systems/GertsnerSystem.cs


protected override void OnCreate()
{
_waveCount = Water.Instance._waves.Length;
base.OnCreate();
_waveCount = Water.Instance._waves.Length;
}
base.OnCreate();
}
protected override void OnDestroy()
{
if(waveData != null)
waveData.Dispose();
protected override JobHandle OnUpdate(JobHandle inputDeps)
base.OnDestroy();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
var job = new HeightJob {
var query = GetEntityQuery(typeof(Translation), typeof(Rotation), typeof(BuoyancyNormal));
var entities = query.ToEntityArray(Allocator.TempJob);
var job = new HeightQueryJob
{
entities = entities,
translations = GetComponentDataFromEntity<Translation>(true),
rotations = GetComponentDataFromEntity<Rotation>(true),
normals = GetComponentDataFromEntity<BuoyancyNormal>(false),
return job.Schedule(this, inputDeps);
return job.Schedule(entities.Length, 1);
public struct HeightJob : IJobForEachWithEntity<Translation, Rotation, BuoyancyNormal>
public struct HeightQueryJob : IJobParallelFor
[ReadOnly]
public NativeArray<Wave> waveData; // wave data stroed in vec4's like the shader version but packed into one
[ReadOnly] public NativeArray<Wave> waveData; // wave data stroed in vec4's like the shader version but packed into one
[ReadOnly] public float time;
[ReadOnly]
public float time;
[DeallocateOnJobCompletion]
[ReadOnly] public NativeArray<Entity> entities;
[ReadOnly] public ComponentDataFromEntity<Translation> translations;
[ReadOnly] public ComponentDataFromEntity<Rotation> rotations;
[ReadOnly] public BufferFromEntity<VoxelOffset> offsetBuffer;
[ReadOnly]
public BufferFromEntity<VoxelOffset> offsetBuffer;
[NativeDisableParallelForRestriction]
public ComponentDataFromEntity<BuoyancyNormal> normals;
// The code actually running on the job
public void Execute(Entity entity, int i, [ReadOnly] ref Translation translation, ref Rotation rot, ref BuoyancyNormal normal)
public void Execute(int index)
var entity = entities[index];
var entityTransform = new RigidTransform(rot.Value, translation.Value);
var entityTransform = new RigidTransform(rotations[entity].Value, translations[entity].Value);
for (int vi = 0; vi < offsets.Length; vi++)
{

for (var wave = 0; wave < waveData.Length; wave++) // for each wave
{
var thisWave = waveData[wave];
var amplitude = waveData[wave].amplitude;
var direction = waveData[wave].direction;
var wavelength = waveData[wave].wavelength;
var omniPos = waveData[wave].origin;
var amplitude = thisWave.amplitude;
var direction = thisWave.direction;
var wavelength = thisWave.wavelength;
var omniPos = thisWave.origin;
////////////////////////////////wave value calculations//////////////////////////
var w = 6.28318f / wavelength; // 2pi over wavelength(hardcoded)
var wSpeed = math.sqrt(9.8f * w); // frequency of the wave based off wavelength

var dir = 0f;
direction = math.radians(direction); // convert the incoming degrees to radians
var windDirInput = new float2(math.sin(direction), math.cos(direction)) * (1 - waveData[wave].onmiDir); // calculate wind direction - TODO - currently radians
var windOmniInput = (pos - omniPos) * waveData[wave].onmiDir;
var windDirInput = new float2(math.sin(direction), math.cos(direction)) * (1 - thisWave.onmiDir); // calculate wind direction - TODO - currently radians
var windOmniInput = (pos - omniPos) * thisWave.onmiDir;
dir = math.dot(windDir, pos - (omniPos * waveData[wave].onmiDir)); // calculate a gradient along the wind direction
dir = math.dot(windDir, pos - (omniPos * thisWave.onmiDir)); // calculate a gradient along the wind direction
////////////////////////////position output calculations/////////////////////////
var calc = dir * w + -time * wSpeed; // the wave calculation

}
}
heights[vi] = new VoxelHeight{Value = wavePos};
heights[vi] = new VoxelHeight { Value = wavePos };
normal.Value = math.normalize(waveNorm.xzy);
normals[entity] = new BuoyancyNormal { Value = math.normalize(waveNorm.xzy) };
}
}
}

7
Assets/Unity Physics Items/Systems/InputSystem.cs


using Unity.Transforms;
using UnityEngine;
[UpdateBefore(typeof(DriveSystem))]
//[UpdateBefore(typeof(DriveSystem))]
[UpdateInGroup(typeof(InitializationSystemGroup))]
public class InputSystem : ComponentSystem
{
InputControls controls;

protected override void OnUpdate()
{
//not time to start
////not time to start
Entities.ForEach((Entity entity, ref Translation pos, ref Rotation rot, ref InputData data ) =>
Entities.ForEach((Entity entity, ref Translation pos, ref Rotation rot, ref InputData data) =>
{
if (data.isHuman)
{

4
Packages/manifest.json


{
"com.unity.properties" : "0.6.4-preview",
"com.unity.collab-proxy": "1.2.16",
"com.unity.entities": "0.1.1-preview",
"com.unity.ide.rider": "1.1.0",

"com.unity.physics": "0.2.0-preview",
"com.unity.properties": "0.6.4-preview",
"com.unity.rendering.hybrid": "0.1.1-preview",
"com.unity.test-framework": "1.0.17",
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.1.0",

52
Assets/Unity Physics Items/DOTSTransformManager.cs


using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;
public class DOTSTransformManager : MonoBehaviour
{
static DOTSTransformManager main;
Dictionary<Entity, Transform> objects = new Dictionary<Entity, Transform>();
private void Awake()
{
if (main != null && main != this)
{
Destroy(this);
return;
}
main = this;
}
public static void Register(Entity entity, Transform objTransform)
{
if (main == null || main.objects.ContainsKey(entity))
return;
main.objects.Add(entity, objTransform);
}
public static Transform GetTransform(Entity entity)
{
Transform t = null;
main.objects.TryGetValue(entity, out t);
return t;
}
//private void Update()
//{
// var manager = World.Active.EntityManager;
// foreach (var item in objects)
// {
// var pos = manager.GetComponentData<Translation>(item.Key);
// var rot = manager.GetComponentData<Rotation>(item.Key);
// item.Value.SetPositionAndRotation(pos.Value, rot.Value);
// }
//}
}

11
Assets/Unity Physics Items/DOTSTransformManager.cs.meta


fileFormatVersion: 2
guid: 4287778bdddd0914f82e916acf501d52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: -17100
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

27
Assets/Unity Physics Items/GridSpawner.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridSpawner : MonoBehaviour
{
public GameObject spawnedObject;
public float xStep = 3f;
public float yStep = 8f;
public int columns = 3;
public int rows = 3;
private void Start()
{
if (spawnedObject == null)
return;
for (int x = 0; x < columns; x++)
{
for (int y = 0; y < rows; y++)
{
Vector3 pos = transform.position + new Vector3(xStep * x, 0f, yStep * -y);
Instantiate(spawnedObject, pos, transform.rotation, transform);
}
}
}
}

11
Assets/Unity Physics Items/GridSpawner.cs.meta


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

386
Assets/Unity Physics Items/Prefabs/BoatEntityNew.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5912457028842276017
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5912457028842276016}
- component: {fileID: 9074881464304324802}
- component: {fileID: 9074881464304324805}
- component: {fileID: 8340553583230086408}
- component: {fileID: 9074881464304324804}
- component: {fileID: 9074881464304324807}
- component: {fileID: 2354741166599181197}
m_Layer: 11
m_Name: BoatEntityNew
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5912457028842276016
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5912457028842276017}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -104.12, y: -0.389, z: -3.78}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &9074881464304324802
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5912457028842276017}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ea7d7495833204790ba1d3a8755397f8, type: 3}
m_Name:
m_EditorClassIdentifier:
ConversionMode: 0
--- !u!54 &9074881464304324805
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5912457028842276017}
serializedVersion: 2
m_Mass: 3200
m_Drag: 0.1
m_AngularDrag: 0.2
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!64 &8340553583230086408
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5912457028842276017}
m_Material: {fileID: 13400000, guid: bd4c82ff9a8164f5c96a49347c431b99, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 3
m_Convex: 1
m_CookingOptions: 14
m_Mesh: {fileID: 2899951614431091848, guid: a362db008c5274e03bf6f3d2387cf617, type: 3}
--- !u!114 &9074881464304324804
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5912457028842276017}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0fe52c158d195e64a99e4eaa38bb3df7, type: 3}
m_Name:
m_EditorClassIdentifier:
_buoyancyType: 3
density: 483.749
volume: 6.6150007
voxelResolution: 0.3
centerOfMass: {x: 0, y: -0.25, z: -0.55}
voxels:
- {x: -0.9000001, y: 0.18077579, z: -2.0381937}
- {x: -0.9000001, y: 0.18077579, z: -1.7381936}
- {x: -0.9000001, y: 0.18077579, z: -1.4381937}
- {x: -0.9000001, y: 0.18077579, z: -1.1381937}
- {x: -0.9000001, y: 0.18077579, z: -0.83819366}
- {x: -0.9000001, y: 0.18077579, z: -0.5381937}
- {x: -0.9000001, y: 0.18077579, z: -0.23819366}
- {x: -0.9000001, y: 0.18077579, z: 0.06180635}
- {x: -0.6, y: -0.11922422, z: -1.4381937}
- {x: -0.6, y: -0.11922422, z: -1.1381937}
- {x: -0.6, y: -0.11922422, z: -0.83819366}
- {x: -0.6, y: -0.11922422, z: -0.5381937}
- {x: -0.6, y: -0.11922422, z: -0.23819366}
- {x: -0.6, y: -0.11922422, z: 0.06180635}
- {x: -0.6, y: 0.18077579, z: -2.9381933}
- {x: -0.6, y: 0.18077579, z: -2.6381934}
- {x: -0.6, y: 0.18077579, z: -2.3381934}
- {x: -0.6, y: 0.18077579, z: -2.0381937}
- {x: -0.6, y: 0.18077579, z: -1.7381936}
- {x: -0.6, y: 0.18077579, z: -1.4381937}
- {x: -0.6, y: 0.18077579, z: -1.1381937}
- {x: -0.6, y: 0.18077579, z: -0.83819366}
- {x: -0.6, y: 0.18077579, z: -0.5381937}
- {x: -0.6, y: 0.18077579, z: -0.23819366}
- {x: -0.6, y: 0.18077579, z: 0.06180635}
- {x: -0.6, y: 0.18077579, z: 0.3618064}
- {x: -0.6, y: 0.18077579, z: 0.66180634}
- {x: -0.6, y: 0.18077579, z: 0.9618064}
- {x: -0.6, y: 0.18077579, z: 1.2618064}
- {x: -0.6, y: 0.4807758, z: -2.6381934}
- {x: -0.6, y: 0.4807758, z: -2.3381934}
- {x: -0.6, y: 0.4807758, z: -2.0381937}
- {x: -0.6, y: 0.4807758, z: -1.7381936}
- {x: -0.6, y: 0.4807758, z: -1.4381937}
- {x: -0.6, y: 0.4807758, z: -1.1381937}
- {x: -0.6, y: 0.4807758, z: -0.83819366}
- {x: -0.6, y: 0.4807758, z: -0.5381937}
- {x: -0.6, y: 0.4807758, z: -0.23819366}
- {x: -0.6, y: 0.4807758, z: 0.06180635}
- {x: -0.6, y: 0.4807758, z: 0.3618064}
- {x: -0.6, y: 0.4807758, z: 0.66180634}
- {x: -0.30000004, y: -0.11922422, z: -2.6381934}
- {x: -0.30000004, y: -0.11922422, z: -2.3381934}
- {x: -0.30000004, y: -0.11922422, z: -2.0381937}
- {x: -0.30000004, y: -0.11922422, z: -1.7381936}
- {x: -0.30000004, y: -0.11922422, z: -1.4381937}
- {x: -0.30000004, y: -0.11922422, z: -1.1381937}
- {x: -0.30000004, y: -0.11922422, z: -0.83819366}
- {x: -0.30000004, y: -0.11922422, z: -0.5381937}
- {x: -0.30000004, y: -0.11922422, z: -0.23819366}
- {x: -0.30000004, y: -0.11922422, z: 0.06180635}
- {x: -0.30000004, y: -0.11922422, z: 0.3618064}
- {x: -0.30000004, y: -0.11922422, z: 0.66180634}
- {x: -0.30000004, y: -0.11922422, z: 0.9618064}
- {x: -0.30000004, y: 0.18077579, z: -2.9381933}
- {x: -0.30000004, y: 0.18077579, z: -2.6381934}
- {x: -0.30000004, y: 0.18077579, z: -2.3381934}
- {x: -0.30000004, y: 0.18077579, z: -2.0381937}
- {x: -0.30000004, y: 0.18077579, z: -1.7381936}
- {x: -0.30000004, y: 0.18077579, z: -1.4381937}
- {x: -0.30000004, y: 0.18077579, z: -1.1381937}
- {x: -0.30000004, y: 0.18077579, z: -0.83819366}
- {x: -0.30000004, y: 0.18077579, z: -0.5381937}
- {x: -0.30000004, y: 0.18077579, z: -0.23819366}
- {x: -0.30000004, y: 0.18077579, z: 0.06180635}
- {x: -0.30000004, y: 0.18077579, z: 0.3618064}
- {x: -0.30000004, y: 0.18077579, z: 0.66180634}
- {x: -0.30000004, y: 0.18077579, z: 0.9618064}
- {x: -0.30000004, y: 0.18077579, z: 1.2618064}
- {x: -0.30000004, y: 0.18077579, z: 1.5618063}
- {x: -0.30000004, y: 0.18077579, z: 1.8618064}
- {x: -0.30000004, y: 0.4807758, z: -2.9381933}
- {x: -0.30000004, y: 0.4807758, z: -2.6381934}
- {x: -0.30000004, y: 0.4807758, z: -2.3381934}
- {x: -0.30000004, y: 0.4807758, z: -2.0381937}
- {x: -0.30000004, y: 0.4807758, z: -1.7381936}
- {x: -0.30000004, y: 0.4807758, z: -1.4381937}
- {x: -0.30000004, y: 0.4807758, z: -1.1381937}
- {x: -0.30000004, y: 0.4807758, z: -0.83819366}
- {x: -0.30000004, y: 0.4807758, z: -0.5381937}
- {x: -0.30000004, y: 0.4807758, z: -0.23819366}
- {x: -0.30000004, y: 0.4807758, z: 0.06180635}
- {x: -0.30000004, y: 0.4807758, z: 0.3618064}
- {x: -0.30000004, y: 0.4807758, z: 0.66180634}
- {x: -0.30000004, y: 0.4807758, z: 0.9618064}
- {x: -0.30000004, y: 0.4807758, z: 1.2618064}
- {x: -0.30000004, y: 0.4807758, z: 1.5618063}
- {x: -0.30000004, y: 0.7807758, z: -2.3381934}
- {x: -0.30000004, y: 0.7807758, z: -2.0381937}
- {x: -0.30000004, y: 0.7807758, z: -1.7381936}
- {x: -0.30000004, y: 0.7807758, z: -1.4381937}
- {x: -0.30000004, y: 0.7807758, z: -1.1381937}
- {x: -0.30000004, y: 0.7807758, z: -0.83819366}
- {x: -0.000000029802322, y: -0.11922422, z: -2.9381933}
- {x: -0.000000029802322, y: -0.11922422, z: -2.6381934}
- {x: -0.000000029802322, y: -0.11922422, z: -2.3381934}
- {x: -0.000000029802322, y: -0.11922422, z: -2.0381937}
- {x: -0.000000029802322, y: -0.11922422, z: -1.7381936}
- {x: -0.000000029802322, y: -0.11922422, z: -1.4381937}
- {x: -0.000000029802322, y: -0.11922422, z: -1.1381937}
- {x: -0.000000029802322, y: -0.11922422, z: -0.83819366}
- {x: -0.000000029802322, y: -0.11922422, z: -0.5381937}
- {x: -0.000000029802322, y: -0.11922422, z: -0.23819366}
- {x: -0.000000029802322, y: -0.11922422, z: 0.06180635}
- {x: -0.000000029802322, y: -0.11922422, z: 0.3618064}
- {x: -0.000000029802322, y: -0.11922422, z: 0.66180634}
- {x: -0.000000029802322, y: -0.11922422, z: 0.9618064}
- {x: -0.000000029802322, y: -0.11922422, z: 1.2618064}
- {x: -0.000000029802322, y: 0.18077579, z: -2.9381933}
- {x: -0.000000029802322, y: 0.18077579, z: -2.6381934}
- {x: -0.000000029802322, y: 0.18077579, z: -2.3381934}
- {x: -0.000000029802322, y: 0.18077579, z: -2.0381937}
- {x: -0.000000029802322, y: 0.18077579, z: -1.7381936}
- {x: -0.000000029802322, y: 0.18077579, z: -1.4381937}
- {x: -0.000000029802322, y: 0.18077579, z: -1.1381937}
- {x: -0.000000029802322, y: 0.18077579, z: -0.83819366}
- {x: -0.000000029802322, y: 0.18077579, z: -0.5381937}
- {x: -0.000000029802322, y: 0.18077579, z: -0.23819366}
- {x: -0.000000029802322, y: 0.18077579, z: 0.06180635}
- {x: -0.000000029802322, y: 0.18077579, z: 0.3618064}
- {x: -0.000000029802322, y: 0.18077579, z: 0.66180634}
- {x: -0.000000029802322, y: 0.18077579, z: 0.9618064}
- {x: -0.000000029802322, y: 0.18077579, z: 1.2618064}
- {x: -0.000000029802322, y: 0.18077579, z: 1.5618063}
- {x: -0.000000029802322, y: 0.18077579, z: 1.8618064}
- {x: -0.000000029802322, y: 0.18077579, z: 2.1618063}
- {x: -0.000000029802322, y: 0.4807758, z: -2.9381933}
- {x: -0.000000029802322, y: 0.4807758, z: -2.6381934}
- {x: -0.000000029802322, y: 0.4807758, z: -2.3381934}
- {x: -0.000000029802322, y: 0.4807758, z: -2.0381937}
- {x: -0.000000029802322, y: 0.4807758, z: -1.7381936}
- {x: -0.000000029802322, y: 0.4807758, z: -1.4381937}
- {x: -0.000000029802322, y: 0.4807758, z: -1.1381937}
- {x: -0.000000029802322, y: 0.4807758, z: -0.83819366}
- {x: -0.000000029802322, y: 0.4807758, z: -0.5381937}
- {x: -0.000000029802322, y: 0.4807758, z: -0.23819366}
- {x: -0.000000029802322, y: 0.4807758, z: 0.06180635}
- {x: -0.000000029802322, y: 0.4807758, z: 0.3618064}
- {x: -0.000000029802322, y: 0.4807758, z: 0.66180634}
- {x: -0.000000029802322, y: 0.4807758, z: 0.9618064}
- {x: -0.000000029802322, y: 0.4807758, z: 1.2618064}
- {x: -0.000000029802322, y: 0.4807758, z: 1.5618063}
- {x: -0.000000029802322, y: 0.4807758, z: 1.8618064}
- {x: -0.000000029802322, y: 0.4807758, z: 2.1618063}
- {x: -0.000000029802322, y: 0.7807758, z: -2.3381934}
- {x: -0.000000029802322, y: 0.7807758, z: -2.0381937}
- {x: -0.000000029802322, y: 0.7807758, z: -1.7381936}
- {x: -0.000000029802322, y: 0.7807758, z: -1.4381937}
- {x: -0.000000029802322, y: 0.7807758, z: -1.1381937}
- {x: -0.000000029802322, y: 0.7807758, z: -0.83819366}
- {x: -0.000000029802322, y: 0.7807758, z: -0.5381937}
- {x: -0.000000029802322, y: 0.7807758, z: -0.23819366}
- {x: 0.29999998, y: -0.11922422, z: -2.6381934}
- {x: 0.29999998, y: -0.11922422, z: -2.3381934}
- {x: 0.29999998, y: -0.11922422, z: -2.0381937}
- {x: 0.29999998, y: -0.11922422, z: -1.7381936}
- {x: 0.29999998, y: -0.11922422, z: -1.4381937}
- {x: 0.29999998, y: -0.11922422, z: -1.1381937}
- {x: 0.29999998, y: -0.11922422, z: -0.83819366}
- {x: 0.29999998, y: -0.11922422, z: -0.5381937}
- {x: 0.29999998, y: -0.11922422, z: -0.23819366}
- {x: 0.29999998, y: -0.11922422, z: 0.06180635}
- {x: 0.29999998, y: -0.11922422, z: 0.3618064}
- {x: 0.29999998, y: -0.11922422, z: 0.66180634}
- {x: 0.29999998, y: -0.11922422, z: 0.9618064}
- {x: 0.29999998, y: 0.18077579, z: -2.9381933}
- {x: 0.29999998, y: 0.18077579, z: -2.6381934}
- {x: 0.29999998, y: 0.18077579, z: -2.3381934}
- {x: 0.29999998, y: 0.18077579, z: -2.0381937}
- {x: 0.29999998, y: 0.18077579, z: -1.7381936}
- {x: 0.29999998, y: 0.18077579, z: -1.4381937}
- {x: 0.29999998, y: 0.18077579, z: -1.1381937}
- {x: 0.29999998, y: 0.18077579, z: -0.83819366}
- {x: 0.29999998, y: 0.18077579, z: -0.5381937}
- {x: 0.29999998, y: 0.18077579, z: -0.23819366}
- {x: 0.29999998, y: 0.18077579, z: 0.06180635}
- {x: 0.29999998, y: 0.18077579, z: 0.3618064}
- {x: 0.29999998, y: 0.18077579, z: 0.66180634}
- {x: 0.29999998, y: 0.18077579, z: 0.9618064}
- {x: 0.29999998, y: 0.18077579, z: 1.2618064}
- {x: 0.29999998, y: 0.18077579, z: 1.5618063}
- {x: 0.29999998, y: 0.18077579, z: 1.8618064}
- {x: 0.29999998, y: 0.4807758, z: -2.9381933}
- {x: 0.29999998, y: 0.4807758, z: -2.6381934}
- {x: 0.29999998, y: 0.4807758, z: -2.3381934}
- {x: 0.29999998, y: 0.4807758, z: -2.0381937}
- {x: 0.29999998, y: 0.4807758, z: -1.7381936}
- {x: 0.29999998, y: 0.4807758, z: -1.4381937}
- {x: 0.29999998, y: 0.4807758, z: -1.1381937}
- {x: 0.29999998, y: 0.4807758, z: -0.83819366}
- {x: 0.29999998, y: 0.4807758, z: -0.5381937}
- {x: 0.29999998, y: 0.4807758, z: -0.23819366}
- {x: 0.29999998, y: 0.4807758, z: 0.06180635}
- {x: 0.29999998, y: 0.4807758, z: 0.3618064}
- {x: 0.29999998, y: 0.4807758, z: 0.66180634}
- {x: 0.29999998, y: 0.4807758, z: 0.9618064}
- {x: 0.29999998, y: 0.4807758, z: 1.2618064}
- {x: 0.29999998, y: 0.4807758, z: 1.5618063}
- {x: 0.29999998, y: 0.7807758, z: -2.3381934}
- {x: 0.29999998, y: 0.7807758, z: -2.0381937}
- {x: 0.29999998, y: 0.7807758, z: -1.7381936}
- {x: 0.29999998, y: 0.7807758, z: -1.4381937}
- {x: 0.29999998, y: 0.7807758, z: -1.1381937}
- {x: 0.29999998, y: 0.7807758, z: -0.83819366}
- {x: 0.6, y: -0.11922422, z: -1.4381937}
- {x: 0.6, y: -0.11922422, z: -1.1381937}
- {x: 0.6, y: -0.11922422, z: -0.83819366}
- {x: 0.6, y: -0.11922422, z: -0.5381937}
- {x: 0.6, y: -0.11922422, z: -0.23819366}
- {x: 0.6, y: -0.11922422, z: 0.06180635}
- {x: 0.6, y: 0.18077579, z: -2.9381933}
- {x: 0.6, y: 0.18077579, z: -2.6381934}
- {x: 0.6, y: 0.18077579, z: -2.3381934}
- {x: 0.6, y: 0.18077579, z: -2.0381937}
- {x: 0.6, y: 0.18077579, z: -1.7381936}
- {x: 0.6, y: 0.18077579, z: -1.4381937}
- {x: 0.6, y: 0.18077579, z: -1.1381937}
- {x: 0.6, y: 0.18077579, z: -0.83819366}
- {x: 0.6, y: 0.18077579, z: -0.5381937}
- {x: 0.6, y: 0.18077579, z: -0.23819366}
- {x: 0.6, y: 0.18077579, z: 0.06180635}
- {x: 0.6, y: 0.18077579, z: 0.3618064}
- {x: 0.6, y: 0.18077579, z: 0.66180634}
- {x: 0.6, y: 0.18077579, z: 0.9618064}
- {x: 0.6, y: 0.18077579, z: 1.2618064}
- {x: 0.6, y: 0.4807758, z: -2.6381934}
- {x: 0.6, y: 0.4807758, z: -2.3381934}
- {x: 0.6, y: 0.4807758, z: -2.0381937}
- {x: 0.6, y: 0.4807758, z: -1.7381936}
- {x: 0.6, y: 0.4807758, z: -1.4381937}
- {x: 0.6, y: 0.4807758, z: -1.1381937}
- {x: 0.6, y: 0.4807758, z: -0.83819366}
- {x: 0.6, y: 0.4807758, z: -0.5381937}
- {x: 0.6, y: 0.4807758, z: -0.23819366}
- {x: 0.6, y: 0.4807758, z: 0.06180635}
- {x: 0.6, y: 0.4807758, z: 0.3618064}
- {x: 0.6, y: 0.4807758, z: 0.66180634}
- {x: 0.9, y: 0.18077579, z: -2.0381937}
- {x: 0.9, y: 0.18077579, z: -1.7381936}
- {x: 0.9, y: 0.18077579, z: -1.4381937}
- {x: 0.9, y: 0.18077579, z: -1.1381937}
- {x: 0.9, y: 0.18077579, z: -0.83819366}
- {x: 0.9, y: 0.18077579, z: -0.5381937}
- {x: 0.9, y: 0.18077579, z: -0.23819366}
- {x: 0.9, y: 0.18077579, z: 0.06180635}
colliders:
- {fileID: 8340553583230086408}
percentSubmerged: 0
childObject: {fileID: 1553288845585282, guid: fc3ffb83d6eafb1489a5b23bc82d25b6,
type: 3}
--- !u!114 &9074881464304324807
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5912457028842276017}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01c46922a8ed04b0081de10e51b3762f, type: 3}
m_Name:
m_EditorClassIdentifier:
RB: {fileID: 9074881464304324805}
vel: {x: 0, y: 0, z: 0}
engineSound: {fileID: 0}
waterSound: {fileID: 0}
steeringTorque: 5
upwardTorque: 3
horsePower: 18
enginePosition: {x: 0, y: 0.05, z: -3.31}
--- !u!114 &2354741166599181197
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5912457028842276017}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8e14db15b85a74d2288a792b27ee0fa6, type: 3}
m_Name:
m_EditorClassIdentifier:
Human: 0
RandomizeColors: 1
boatRenderer: {fileID: 0}
engine: {fileID: 9074881464304324807}
cam: {fileID: 0}

7
Assets/Unity Physics Items/Prefabs/BoatEntityNew.prefab.meta


fileFormatVersion: 2
guid: ef588ca3a301a7c4b9fca4bdf9c1c390
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Unity Physics Items/Prefabs/DOTS Buoys.prefab
文件差异内容过多而无法显示
查看文件

7
Assets/Unity Physics Items/Prefabs/DOTS Buoys.prefab.meta


fileFormatVersion: 2
guid: 151b573bdeb429d45b0de257872d3e54
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

84
Assets/Unity Physics Items/Systems/UpdateObjectTransformSystem.cs


using System.Collections;
using System.Collections.Generic;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using static WaterSystem.BuoyantObject_DOTS;
using Unity.Physics.Extensions;
using Unity.Physics.Systems;
using Unity.Physics;
[UpdateAfter(typeof(InputSystem))]
public class UpdateObjectTransformSystem : JobComponentSystem
{
NativeArray<Entity> entities;
NativeArray<float3> positions;
NativeArray<quaternion> rotations;
int totalCount;
protected override void OnCreate()
{
totalCount = 0;
entities = new NativeArray<Entity>(512, Allocator.Persistent);
positions = new NativeArray<float3>(512, Allocator.Persistent);
rotations = new NativeArray<quaternion>(512, Allocator.Persistent);
base.OnCreate();
}
protected override void OnDestroy()
{
entities.Dispose();
positions.Dispose();
rotations.Dispose();
base.OnDestroy();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
for (int i = 0; i < entities.Length; i++)
{
var t = DOTSTransformManager.GetTransform(entities[i]);
if(t != null)
t.SetPositionAndRotation(positions[i], rotations[i]);
}
SyncJob.count = 0;
var job = new SyncJob
{
entities = entities,
positions = positions,
rotations = rotations
};
return job.Schedule(this, inputDeps);
}
//[BurstCompile]
[RequireComponentTag(typeof(SyncTransformTag))]
public struct SyncJob : IJobForEachWithEntity<Translation, Rotation>
{
public NativeArray<Entity> entities;
public NativeArray<float3> positions;
public NativeArray<quaternion> rotations;
public static int count;
public void Execute(Entity entity, int index, ref Translation pos, ref Rotation rot)
{
count++;
entities[index] = entity;
positions[index] = pos.Value;
rotations[index] = rot.Value;
}
}
}

11
Assets/Unity Physics Items/Systems/UpdateObjectTransformSystem.cs.meta


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