Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Unity.Assertions;
- using Unity.Entities;
- using UnityEngine;
- namespace ScriptsSandbox
- {
- [ExecuteAlways]
- public class PrefabAuthoring : MonoBehaviour
- {
- void OnEnable()
- {
- var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
- var entityPrefab = entityManager.CreateEntity(
- typeof(Prefab),
- typeof(MyFunkyComponent));
- Assert.IsTrue(entityPrefab != Entity.Null);
- var query = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(
- ComponentType.ReadOnly<MyFunkyComponent>(),
- ComponentType.ReadOnly<Prefab>());
- var prefabs = query.ToEntityArray(Unity.Collections.Allocator.Temp);
- Debug.Log($"First Query found {prefabs.Length} prefabs");
- prefabs.Dispose();
- var queryPrefab = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(new EntityQueryDesc
- {
- All = new[]
- {
- ComponentType.ReadOnly<MyFunkyComponent>()
- },
- Options = EntityQueryOptions.Default | EntityQueryOptions.IncludePrefab
- });
- var prefabs2 = queryPrefab.ToEntityArray(Unity.Collections.Allocator.Temp);
- Debug.Log($"Second Query found {prefabs2.Length} prefabs");
- prefabs2.Dispose();
- entityManager.DestroyEntity(entityPrefab);
- }
- }
- public struct MyFunkyComponent : IComponentData
- {
- public float Size;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement