forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryInitSystem.cs
More file actions
51 lines (42 loc) · 1.45 KB
/
Copy pathDirectoryInitSystem.cs
File metadata and controls
51 lines (42 loc) · 1.45 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using Unity.Entities;
using UnityEngine;
using UnityEngine.UI;
using Unity.Burst;
namespace HelloCube.GameObjectSync
{
public partial struct DirectoryInitSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
// We need to wait for the scene to load before Updating, so we must RequireForUpdate at
// least one component type loaded from the scene.
state.RequireForUpdate<Execute.GameObjectSync>();
}
public void OnUpdate(ref SystemState state)
{
state.Enabled = false;
var go = GameObject.Find("Directory");
if (go == null)
{
throw new Exception("GameObject 'Directory' not found.");
}
var directory = go.GetComponent<Directory>();
var directoryManaged = new DirectoryManaged();
directoryManaged.RotatorPrefab = directory.RotatorPrefab;
directoryManaged.RotationToggle = directory.RotationToggle;
var entity = state.EntityManager.CreateEntity();
state.EntityManager.AddComponentData(entity, directoryManaged);
}
}
public class DirectoryManaged : IComponentData
{
public GameObject RotatorPrefab;
public Toggle RotationToggle;
// Every IComponentData class must have a no-arg constructor.
public DirectoryManaged()
{
}
}
}