https://www.youtube. com/watch?v=IO6_6Y_YUdE
Однако я, похоже, уже застрял в самых основах.
У меня есть объект HexGrid внутри подсцены с моно-компонентом HexGridAuthoringComponent.Эти компоненты содержат ссылку на префаб.
Я сохраняю ссылку на префаб с помощью Baker в объект.
Я пытаюсь создать объект с помощью системы.
Это работает. Сущность появляется в Иерахии и, кажется, имеет соответствующие компоненты в инспекторе.
Однако я не вижу ни одной из Сущностей в игре или сцене.
< strong>Код:
HexGridProperties (компонент данных для объекта HexGrid)
Код: Выделить всё
using Unity.Entities;
using UnityEngine;
namespace HexGrid
{
public struct HexGridProperties : IComponentData
{
public Entity HexCellPrefab;
}
}
Код: Выделить всё
using Unity.Entities;
using UnityEngine;
namespace HexGrid
{
public class HexGridAuthoring : MonoBehaviour
{
public GameObject HexGrid;
}
public class HexGridBaker : Baker
{
public override void Bake(HexGridAuthoring authoring)
{
AddComponent(new HexGridProperties
{
HexCellPrefab = GetEntity(authoring.HexGrid)
});
}
}
}
Код: Выделить всё
using Unity.Entities;
namespace HexGrid
{
public readonly partial struct HexGridAspect : IAspect
{
public readonly Entity Entity;
private readonly RefRO _hexGridProperties;
public Entity HexCellPrefab => _hexGridProperties.ValueRO.HexCellPrefab;
}
}
Код: Выделить всё
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
namespace HexGrid
{
[BurstCompile]
[UpdateInGroup(typeof(InitializationSystemGroup))]
public partial struct HexCellSpawnSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate();
}
[BurstCompile]
public void OnDestroy(ref SystemState state)
{
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
state.Enabled = false;
var hexGridEntity = SystemAPI.GetSingletonEntity();
var hexGrid = SystemAPI.GetAspectRO(hexGridEntity);
var ecb = new EntityCommandBuffer(Allocator.Temp);
for (int i = 0; i < 100; i++)
{
ecb.Instantiate(hexGrid.HexCellPrefab);
}
ecb.Playback(state.EntityManager);
}
}
}
Редактор: 2022.2.3f1
Сущности: 1.0.0-pre.15
Entities-Graphics: 1.0.0-pre.15
Подробнее здесь: https://stackoverflow.com/questions/753 ... er-show-up
Мобильная версия