Код:
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,
});
}
Код: Выделить всё
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);
}
Во многом похоже на ссылку или ресурс. сценарий. Разница лишь в том, что при авторинге он создается из списка, а не GameObject по GameObject.
Есть идеи?
Подробнее здесь: https://stackoverflow.com/questions/793 ... eable-data