using UnityEngine; using UnityEngine.UI; namespace SpellBoundAR.MusicalInstruments.SheetMusic { public class WrittenNoteBridge : MaskableGraphic { private Transform _bottomLeft; private Transform _topLeft; private Transform _bottomRight; private Transform _topRight; [Header("Colors")] [SerializeField] private Color defaultColor; [SerializeField] private Color customColor; protected override void OnEnable() { base.OnEnable(); MusicalInstrumentsManager.OnColorsChanged += RefreshColors; RefreshColors(); } protected override void OnDisable() { base.OnDisable(); MusicalInstrumentsManager.OnColorsChanged -= RefreshColors; } public void SetBridgeCorners(Transform bottomLeft, Transform topLeft, Transform bottomRight, Transform topRight) { _bottomLeft = bottomLeft; _topLeft = topLeft; _bottomRight = bottomRight; _topRight = topRight; } public void SetCustomColor(Color newColor) { customColor = newColor; RefreshColors(); } private void RefreshColors() { color = MusicalInstrumentsManager.Colors ? customColor : defaultColor; } protected override void OnPopulateMesh(VertexHelper vh) { if (!_bottomLeft || !_topLeft || !_bottomRight || !_topRight) return; vh.Clear(); UIVertex vertex = UIVertex.simpleVert; vertex.color = color; Vector3 myPosition = transform.position; vertex.position = _bottomLeft.position - myPosition; vh.AddVert(vertex); vertex.position = _topLeft.position - myPosition; vh.AddVert(vertex); vertex.position = _bottomRight.position - myPosition; vh.AddVert(vertex); vertex.position = _topRight.position - myPosition; vh.AddVert(vertex); vh.AddTriangle(0, 1, 2); vh.AddTriangle(1, 2, 3); } private void Update() { SetVerticesDirty(); } } }