forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomIInitialHeadingSystem.cs
More file actions
34 lines (30 loc) · 1.01 KB
/
Copy pathRandomIInitialHeadingSystem.cs
File metadata and controls
34 lines (30 loc) · 1.01 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
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
namespace Samples.Common
{
public class RandomInitialHeadingSystem : ComponentSystem
{
struct RandomInitialHeadingGroup
{
[ReadOnly] public ComponentDataArray<RandomInitialHeading> RandomInitialHeadiings;
[ReadOnly] public EntityArray Entities;
public ComponentDataArray<Heading> Headings;
public int Length;
}
[Inject] RandomInitialHeadingGroup m_Group;
protected override void OnUpdate()
{
for (int i = 0; i < m_Group.Length; i++)
{
m_Group.Headings[i] = new Heading
{
Value = math.normalize(new float3(Random.Range(-1, 1), Random.Range(-1,1), Random.Range(-1, 1)))
};
PostUpdateCommands.RemoveComponent<RandomInitialHeading>(m_Group.Entities[i]);
}
}
}
}