forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetLocalPlayerGraphicsColorsSystem.cs
More file actions
47 lines (40 loc) · 1.39 KB
/
Copy pathSetLocalPlayerGraphicsColorsSystem.cs
File metadata and controls
47 lines (40 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
37
38
39
40
41
42
43
44
45
46
47
using System;
using Unity.Entities;
using UnityEngine;
namespace Unity.NetCode.Samples.Common
{
[WorldSystemFilter(WorldSystemFilterFlags.Presentation)]
[UpdateInGroup(typeof(PresentationSystemGroup))]
public partial class SetLocalPlayerGraphicsColorsSystem : SystemBase
{
int m_LastNetworkId;
int m_LastAppliedListVersion;
public Color TargetColor { get; private set; }
protected override void OnCreate()
{
TargetColor = Color.grey;
}
protected override void OnUpdate()
{
if (SetOutlineToLocalPlayerColor.All.Count <= 0)
return;
SystemAPI.TryGetSingleton(out NetworkId networkId);
if (networkId.Value != m_LastNetworkId)
{
m_LastNetworkId = networkId.Value;
TargetColor = networkId.Value > 0 ? NetworkIdDebugColorUtility.GetColor(networkId.Value) : Color.grey;
RefreshWidgets();
}
else if (SetOutlineToLocalPlayerColor.ListVersion != m_LastAppliedListVersion)
{
RefreshWidgets();
}
}
void RefreshWidgets()
{
m_LastAppliedListVersion = SetOutlineToLocalPlayerColor.ListVersion;
foreach (var target in SetOutlineToLocalPlayerColor.All)
target.Refresh(TargetColor);
}
}
}