Data-OrientedTechnologyStack(DOTS) 记录及遇到的问题

////////////////////////////////////////////////

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

扫描二维码关注公众号,回复: 10546044 查看本文章

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

发布了16 篇原创文章 · 获赞 44 · 访问量 38万+

猜你喜欢

转载自blog.csdn.net/Game_jqd/article/details/103809565
今日推荐