Mike Geig
5 年前
当前提交
e5796b1b
共有 20 个文件被更改,包括 1454 次插入 和 903 次删除
-
6Assets/Scripts/Boat/AIcontroller.cs
-
2Assets/Scripts/Boat/BoatController.cs
-
10Assets/Scripts/Boat/Engine.cs
-
7Assets/Scripts/GameSystem/RaceManager.cs
-
3Assets/Scripts/GameSystem/WaypointGroup.cs
-
16Assets/Unity Physics Items/BuoyantObject_DOTS.cs
-
8Assets/Unity Physics Items/Components/BoatDataComponents.cs
-
886Assets/Unity Physics Items/Physics Scene.unity
-
999Assets/Unity Physics Items/Prefabs/BoatEntity.prefab
-
2Assets/Unity Physics Items/Systems/ApplyBuoyancyForceSystem.cs
-
43Assets/Unity Physics Items/Systems/DriveSystem.cs
-
115Assets/Unity Physics Items/AIController_DOTS.cs
-
11Assets/Unity Physics Items/AIController_DOTS.cs.meta
-
15Assets/Unity Physics Items/BoatBodyComponent.cs
-
146Assets/Unity Physics Items/Prefabs/AIBoatEntity Variant.prefab
-
7Assets/Unity Physics Items/Prefabs/AIBoatEntity Variant.prefab.meta
-
54Assets/Unity Physics Items/Systems/InputSystem.cs
-
11Assets/Unity Physics Items/Systems/InputSystem.cs.meta
-
16Assets/Unity Physics Items/Components/BoatBodyComponent.cs
-
0/Assets/Unity Physics Items/BoatBodyComponent.cs.meta
886
Assets/Unity Physics Items/Physics Scene.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
999
Assets/Unity Physics Items/Prefabs/BoatEntity.prefab
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using BoatAttack; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using Unity.Entities; |
|||
using Unity.Mathematics; |
|||
using UnityEngine; |
|||
using UnityEngine.AI; |
|||
|
|||
class PathData |
|||
{ |
|||
public Vector3[] pathPoint; |
|||
public int curPoint; |
|||
public int curWP; |
|||
public bool foundPath; |
|||
}; |
|||
|
|||
public class AIController_DOTS : MonoBehaviour |
|||
{ |
|||
static AIController_DOTS main; |
|||
|
|||
Dictionary<Entity, PathData> paths; |
|||
|
|||
|
|||
private void Awake() |
|||
{ |
|||
if (main != null && main != this) |
|||
{ |
|||
Destroy(this); |
|||
return; |
|||
} |
|||
|
|||
main = this; |
|||
paths = new Dictionary<Entity, PathData>(); |
|||
} |
|||
|
|||
public static void Register(Entity entity) |
|||
{ |
|||
if (main.paths.ContainsKey(entity)) |
|||
return; |
|||
|
|||
PathData data = new PathData(); |
|||
|
|||
main.paths.Add(entity, data); |
|||
} |
|||
|
|||
public static void GetInputs(Entity entity, float3 pos, quaternion rot, out float throttle, out float steering) |
|||
{ |
|||
main.GetInputsInternal(entity, pos, rot, out throttle, out steering); |
|||
} |
|||
|
|||
void GetInputsInternal(Entity entity, float3 pos, quaternion rot, out float throttle, out float steering) |
|||
{ |
|||
throttle = steering = 0; |
|||
|
|||
//Do we have data?
|
|||
PathData data; |
|||
if (!paths.TryGetValue(entity, out data)) |
|||
return; |
|||
|
|||
if (data.pathPoint == null) |
|||
{ |
|||
WaypointGroup.Waypoint wp = WaypointGroup.Instance.GetClosestWaypoint(pos); |
|||
CalculatePath(WaypointGroup.Instance.GetNextWaypoint(wp), data, pos); |
|||
} |
|||
else if (data.pathPoint.Length > data.curPoint && data.foundPath) |
|||
{ |
|||
if ((Vector3.Distance(pos, data.pathPoint[data.curPoint])) < 8) // If we are close to the current point on the path get the next
|
|||
{ |
|||
data.curPoint++; // Move on to next point
|
|||
if (data.curPoint >= data.pathPoint.Length) |
|||
CalculatePath(WaypointGroup.Instance.GetWaypoint(data.curWP), data, pos); |
|||
} |
|||
} |
|||
|
|||
if (data.pathPoint != null && data.pathPoint.Length > data.curPoint) |
|||
{ |
|||
//Get angle to the destination and the side
|
|||
Vector3 normDir = data.pathPoint[data.curPoint] - (Vector3)pos; |
|||
normDir = normDir.normalized; |
|||
|
|||
var forward = math.forward(rot); |
|||
float dot = Vector3.Dot(normDir, forward); |
|||
|
|||
//float angle = Mathf.Acos (dot) * Mathf.Rad2Deg;
|
|||
float targetSide = Vector3.Cross(forward, normDir).y;//positive on right side, negative on left side
|
|||
|
|||
steering = Mathf.Clamp(targetSide, -1.0f, 1.0f); |
|||
throttle = dot > 0 ? 1f : 0.25f; |
|||
} |
|||
} |
|||
|
|||
void CalculatePath(WaypointGroup.Waypoint wp, PathData data, float3 pos) |
|||
{ |
|||
var offset = (UnityEngine.Random.value * 2f - 1f) * wp.WPwidth * Vector3.left; |
|||
var curWPPos = wp.point + wp.rotation * offset; |
|||
|
|||
data.curWP++; |
|||
if (data.curWP >= WaypointGroup.Instance.WPs.Count) |
|||
data.curWP = 0; |
|||
|
|||
var navPath = new NavMeshPath(); // New nav path
|
|||
NavMesh.CalculatePath(pos, curWPPos, 255, navPath); |
|||
|
|||
if (navPath.status == NavMeshPathStatus.PathComplete) // if the path is good(complete) use it
|
|||
{ |
|||
data.pathPoint = navPath.corners; |
|||
data.curPoint = 1; |
|||
data.foundPath = true; |
|||
} |
|||
else if (navPath == null || navPath.status == NavMeshPathStatus.PathInvalid) // if the path is bad, we havent found a path
|
|||
{ |
|||
data.foundPath = false; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d535e331fdb3f734cb363f09fa881545 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using Unity.Entities; |
|||
using Unity.Transforms; |
|||
using UnityEngine; |
|||
|
|||
|
|||
public class BoatBodyComponent : MonoBehaviour//, IConvertGameObjectToEntity
|
|||
{ |
|||
//Called by parent BuoyantObject_DOTS
|
|||
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) |
|||
{ |
|||
dstManager.AddComponent(entity, typeof(CopyTransformToGameObject)); |
|||
} |
|||
} |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!1001 &2478739796189504339 |
|||
PrefabInstance: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 2 |
|||
m_Modification: |
|||
m_TransformParent: {fileID: 0} |
|||
m_Modifications: |
|||
- target: {fileID: 3457973740146875416, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_Name |
|||
value: BoatEntity |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875416, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_IsActive |
|||
value: 1 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalPosition.x |
|||
value: -78.9 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalPosition.y |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalPosition.z |
|||
value: -20 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.x |
|||
value: -0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.y |
|||
value: 0.95782626 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.z |
|||
value: -0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.w |
|||
value: 0.28734788 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_RootOrder |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalEulerAnglesHint.x |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalEulerAnglesHint.y |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalEulerAnglesHint.z |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 6727757724182940452, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: PrimaryColor.r |
|||
value: 0.7434182 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 6727757724182940452, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: PrimaryColor.g |
|||
value: 0.7434182 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 6727757724182940452, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: PrimaryColor.b |
|||
value: 0.7434182 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 6727757724182940452, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: TrimColor.r |
|||
value: 0.025658185 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 6727757724182940452, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: TrimColor.g |
|||
value: 0.15348418 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 6727757724182940452, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: TrimColor.b |
|||
value: 0.25658178 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 6727757724182940452, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: Human |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 320792261470743900, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_IsActive |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 558137786967539335, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.x |
|||
value: 0.09853761 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 558137786967539335, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.y |
|||
value: -0.0000002682209 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 558137786967539335, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.z |
|||
value: -0.00000011175871 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 558137786967539335, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalPosition.z |
|||
value: -5 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 558137786967539335, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalPosition.x |
|||
value: 0.0000026226044 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 558137786967539335, guid: 0a308b87c1579fb4c9ea256406209ca5, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.w |
|||
value: 0.99513334 |
|||
objectReference: {fileID: 0} |
|||
m_RemovedComponents: [] |
|||
m_SourcePrefab: {fileID: 100100000, guid: 0a308b87c1579fb4c9ea256406209ca5, type: 3} |
|
|||
fileFormatVersion: 2 |
|||
guid: c48ad8112d3b604478deaa848d47c861 |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using BoatAttack; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using Unity.Entities; |
|||
using Unity.Transforms; |
|||
using UnityEngine; |
|||
|
|||
[UpdateBefore(typeof(DriveSystem))] |
|||
public class InputSystem : ComponentSystem |
|||
{ |
|||
InputControls controls; |
|||
|
|||
float throttle; |
|||
float steering; |
|||
|
|||
float startTime; |
|||
|
|||
protected override void OnCreate() |
|||
{ |
|||
startTime = Time.time + WaypointGroup.raceDelay; |
|||
|
|||
controls = new InputControls(); |
|||
|
|||
controls.BoatControls.Trottle.performed += context => throttle = context.ReadValue<float>(); |
|||
controls.BoatControls.Trottle.canceled += context => throttle = 0f; |
|||
|
|||
controls.BoatControls.Steering.performed += context => steering = context.ReadValue<float>(); |
|||
controls.BoatControls.Steering.canceled += context => steering = 0f; |
|||
|
|||
controls.BoatControls.Enable(); |
|||
|
|||
base.OnCreate(); |
|||
} |
|||
|
|||
protected override void OnUpdate() |
|||
{ |
|||
//not time to start
|
|||
if (Time.time < startTime) |
|||
return; |
|||
|
|||
Entities.ForEach((Entity entity, ref Translation pos, ref Rotation rot, ref DrivingData data ) => |
|||
{ |
|||
if (data.isHuman) |
|||
{ |
|||
data.throttle = throttle; |
|||
data.steering = steering; |
|||
} |
|||
else |
|||
{ |
|||
AIController_DOTS.GetInputs(entity, pos.Value, rot.Value, out data.throttle, out data.steering); |
|||
} |
|||
}); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b8a5f3eb75380dc4b8e643111843c4e9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using Unity.Entities; |
|||
using Unity.Transforms; |
|||
using UnityEngine; |
|||
|
|||
|
|||
|
|||
|
|||
public class BoatBodyComponent : MonoBehaviour, IConvertGameObjectToEntity |
|||
{ |
|||
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) |
|||
{ |
|||
dstManager.AddComponent(entity, typeof(CopyTransformToGameObject)); |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue