forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpawnSystem.cs
More file actions
36 lines (33 loc) · 1.39 KB
/
Copy pathSpawnSystem.cs
File metadata and controls
36 lines (33 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#if !UNITY_DISABLE_MANAGED_COMPONENTS
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
namespace Graphical.AnimationWithGameObjects
{
[WorldSystemFilter(WorldSystemFilterFlags.Default | WorldSystemFilterFlags.Editor)]
public partial struct SpawnSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<ExecuteAnimationWithGameObjects>();
}
public void OnUpdate(ref SystemState state)
{
var query = SystemAPI.QueryBuilder().WithAll<WarriorGOPrefab>().Build();
var entities = query.ToEntityArray(Allocator.Temp);
foreach (var entity in entities)
{
var warriorGOPrefab = state.EntityManager.GetComponentData<WarriorGOPrefab>(entity);
var instance = GameObject.Instantiate(warriorGOPrefab.Prefab);
instance.hideFlags |= HideFlags.HideAndDontSave;
state.EntityManager.AddComponentObject(entity, instance.GetComponent<Transform>());
state.EntityManager.AddComponentObject(entity, instance.GetComponent<Animator>());
state.EntityManager.AddComponentData(entity, new WarriorGOInstance { Instance = instance });
state.EntityManager.RemoveComponent<WarriorGOPrefab>(entity);
}
}
}
}
#endif