-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRendererId.cs
41 lines (33 loc) · 1.19 KB
/
RendererId.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SubsurfaceStudios.Slightmapper.Global {
[ExecuteAlways]
public class RendererId : MonoBehaviour {
public uint Id;
public MeshRenderer RendererIfAvailable;
public ReflectionProbe ReflectionProbeIfAvailable;
[ContextMenu("Force reregister ID")]
public void ForceReregisterId() => RendererIdAllocator.RegisterId(Id, this);
void Awake() => ForceReregisterId();
#if UNITY_EDITOR
[ContextMenu("Set Renderer")]
void SetRenderer() => RendererIfAvailable = GetComponent<MeshRenderer>();
[ContextMenu("Set Reflection Probe")]
void SetReflectionProbe() => ReflectionProbeIfAvailable = GetComponent<ReflectionProbe>();
[ContextMenu("Force regenerate ID")]
public void ForceNewId() {
Id = RendererIdAllocator.GetId();
SetRenderer();
SetReflectionProbe();
ForceReregisterId();
}
void OnValidate() {
if (RendererIdAllocator.Index[Id] != this)
ForceNewId();
}
public void Reset() => ForceNewId();
#endif // UNITY_EDITOR
}
}