////////////////////////////////////////////////
Use ECS and data-oriented design!
Difficulty Rating Outline: * 1: Easier, no concurrent data dependencies * 2: Moderate, concurrent reads and writes * 3: Difficult, lots of concurrency, data design problems to solve
//////////////////////////////////////////////////////
Installing the Unity Editor
To install the Editor:
Click the Installs tab. The default install locations are:
Windows:
C:\Program Files\Unity\Hub\Editor
Mac:
/Applications/Unity/Hub/Editor
Note: If you want to change the default installation location, follow these steps:
From the top right corner of the Hub window, click the Gear icon.
In the Editor Folder Location dialog box, enter the new installation location and click Done.
//////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////
ConvertAndDestroy 会让转化后消失
///////////////////////////////////////
[GenerateAuthoringComponent]
public struct RotationSpeed_ForEach : IComponentData
{
public float RadiansPerSecond;
}
[RequiresEntityConversion]
[AddComponentMenu("DOTS Samples/IJobChunk/Rotation Speed")]
[ConverterVersion("joe", 1)]
public class RotationSpeedAuthoring_IJobChunk : MonoBehaviour, IConvertGameObjectToEntity
{
public float DegreesPerSecond = 360.0F;
// The MonoBehaviour data is converted to ComponentData on the entity.
// We are specifically transforming from a good editor representation of the data (Represented in degrees)
// To a good runtime representation (Represented in radians)
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var data = new RotationSpeed_IJobChunk { RadiansPerSecond = math.radians(DegreesPerSecond) };
dstManager.AddComponentData(entity, data);
}
}
//////////////////////////////////////////////////////////////////////
DebugStream.DrawComponent
/////////////////////
运行EntityComponentSystemSamples\UnityPhysicsSamples 把[email protected]下边报错的Test文件夹删除
/////////////////////////////////////////
///////////////////////////////////////////////////////
using System;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
[Serializable]
public struct ActorComponent : IComponentData
{
public float3 position;
public float3 target_positon;
}
[DisallowMultipleComponent]
[RequiresEntityConversion]
public class Actor : MonoBehaviour, IConvertGameObjectToEntity
{
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
float3 grid_pos = new float3(
math.floor(transform.position.x),
0,
math.floor(transform.position.z)
);
dstManager.AddComponentData(entity, new ActorComponent()
{
position = grid_pos,
target_positon = grid_pos,
});
}
}
在这个Cube (2)上加上Actor脚本,需要加上ConvertToEntity脚本
/////////////////////////////////////////////////////////////////
EntityQuery _query
[ReadOnly] public CollisionWorld MCollisionWorld;
var chunkTranslations = chunk.GetNativeArray(TranslationType);
Random random_
public float3 Direction;
CustomCopyTransformToGameObjectSystem m_CustomCopyTransformToGameObjectSystem