DOTS/ECS ISystem — ссылочные данные DynamicBufferC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 DOTS/ECS ISystem — ссылочные данные DynamicBuffer

Сообщение Anonymous »

Создал эталонный сценарий ECS с использованием DynamicBuffers (имеет более одного типа значения). Мне нужно инициализировать данные для работы CreateDropPile.
Код:
DropPileSystem

Код: Выделить всё

using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Random = Unity.Mathematics.Random;
public partial struct DropPileSystem : ISystem
{
public EntityManager entityManager;
public EntityCommandBuffer entityCommandBuffer;

public DynamicBuffer dropPileDynamicBuffer;
public Entity dropPileReference;
public Entity holdablePileReference;
public DynamicBuffer holdableItemDynamicBuffer;
public void OnStartRunning(ref SystemState state)
{
entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityCommandBuffer = SystemAPI.GetSingleton().CreateCommandBuffer(state.WorldUnmanaged);

dropPileReference = SystemAPI.GetSingletonEntity();
holdablePileReference = SystemAPI.GetSingletonEntity();
holdableItemDynamicBuffer = SystemAPI.GetBuffer(holdablePileReference);
dropPileDynamicBuffer = SystemAPI.GetBuffer(dropPileReference);

UnityEngine.Debug.Log(dropPileDynamicBuffer.Length);

}
public void CreateDropPile(Entity holdableItemType)
{
UnityEngine.Debug.Log(dropPileDynamicBuffer.Length);

DropPileDynamicBuffer dropPileTemplate = GetDropPileTemplate(holdableItemType);
UnityEngine.Debug.Log(dropPileTemplate);

Entity newDropPile = entityManager.Instantiate(dropPileTemplate.dropPile);

entityCommandBuffer.SetComponent(newDropPile, new DropPile
{
dropPileItemEntity = holdableItemType,
dropPileItemQuantity = 1,
});
}
HoldableItemReference:

Код: Выделить всё

using UnityEngine;
using Unity.Entities;
using Unity.Mathematics;
using System.Collections.Generic;
using static HoldableItemCategorySO;
using Random = Unity.Mathematics.Random;

public class HoldableItemReferencesAuthoring : MonoBehaviour
{
[SerializeField] private List holdableItemSOList;

public class Baker : Baker
{

public override void Bake(HoldableItemReferencesAuthoring authoring)
{
Entity entity = GetEntity(TransformUsageFlags.Dynamic);
DynamicBuffer holdableItemDataBuffer = AddBuffer(entity);

for (int i = 0; i < authoring.holdableItemSOList.Count; i++)
{
holdableItemDataBuffer.Add(new HoldableItemDynamicBuffer
{
itemEntity = GetEntity(authoring.holdableItemSOList[i].gameWorldPrefab, TransformUsageFlags.Dynamic),
itemID = i,
inventoryQuantityMax = authoring.holdableItemSOList[i].holdingAmountMax,
inventorySpacePointsCost = authoring.holdableItemSOList[i].inventorySpacePointsCost,
stackCategory = authoring.holdableItemSOList[i].stackCategory,
itemCategory = authoring.holdableItemSOList[i].itemCategory,
handheldOffset = authoring.holdableItemSOList[i].handheldOffset,
});
}
AddComponent(entity, new HoldableItemReferences());
}
}
}
public struct HoldableItemReferences : IComponentData
{
}
public struct HoldableItemDynamicBuffer: IBufferElementData
{
public Entity itemEntity;
public int itemID;
public int inventoryQuantityMax;
public float inventorySpacePointsCost;
public StackCategory stackCategory;
public ItemCategory itemCategory;
public float3 handheldOffset;
public Random randomSeed;
}
Система команд ввода:

Код: Выделить всё

if (inputData.ValueRO.isInteracting) // if "F"  is pressed
{
DropPileSystem dropPileSystem = state.WorldUnmanaged.GetUnsafeSystemRef(state.SystemHandle);
dropPileSystem.CreateDropPile(holdableItemDynamicBuffer[1].itemEntity);
}
Я пытался запустить «OnStartRunning» внутри функции, ссылающейся на SystemState «World», создавая статический экземпляр ссылочных данных и некоторые другие вещи.Код должен инициализировать список данных DynamicBuffer, чтобы на каждый объект внутри можно было ссылаться (желательно через все сценарии ECS/DOTS).
Во многом похоже на ссылку или ресурс. сценарий. Разница лишь в том, что при авторинге он создается из списка, а не GameObject по GameObject.
Есть идеи?


Подробнее здесь: https://stackoverflow.com/questions/793 ... eable-data
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»