-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCutGuideVisualFactory.cs
More file actions
68 lines (58 loc) · 2.36 KB
/
Copy pathCutGuideVisualFactory.cs
File metadata and controls
68 lines (58 loc) · 2.36 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using UnityEngine;
namespace ProxyNote
{
internal static class CutGuideVisualFactory
{
internal const string GuideName = "ProxyNoteCutGuide";
internal static GameObject Create(Transform proxyRoot)
{
Transform guideParent = FindNoteCube(proxyRoot) ?? proxyRoot;
MeshRenderer sourceRenderer =
guideParent.GetComponentInChildren<MeshRenderer>(includeInactive: true);
if (sourceRenderer == null && guideParent != proxyRoot)
{
guideParent = proxyRoot;
sourceRenderer =
proxyRoot.GetComponentInChildren<MeshRenderer>(includeInactive: true);
}
if (sourceRenderer == null || sourceRenderer.sharedMaterial == null)
{
return null;
}
GameObject guide = GameObject.CreatePrimitive(PrimitiveType.Cube);
guide.name = GuideName;
guide.SetActive(false);
Collider collider = guide.GetComponent<Collider>();
if (collider != null)
{
collider.enabled = false;
Object.Destroy(collider);
}
MeshRenderer renderer = guide.GetComponent<MeshRenderer>();
renderer.sharedMaterial = sourceRenderer.sharedMaterial;
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
renderer.receiveShadows = false;
renderer.lightProbeUsage = sourceRenderer.lightProbeUsage;
renderer.reflectionProbeUsage = sourceRenderer.reflectionProbeUsage;
MaterialPropertyBlock properties = new MaterialPropertyBlock();
sourceRenderer.GetPropertyBlock(properties);
renderer.SetPropertyBlock(properties);
guide.transform.SetParent(guideParent, false);
guide.transform.localRotation = Quaternion.identity;
return guide;
}
private static Transform FindNoteCube(Transform proxyRoot)
{
Transform[] transforms =
proxyRoot.GetComponentsInChildren<Transform>(includeInactive: true);
foreach (Transform child in transforms)
{
if (child.name == "NoteCube")
{
return child;
}
}
return null;
}
}
}