@@ -46,12 +46,17 @@ public bool Interactable
4646 }
4747 }
4848
49+ public Image Background { get ; }
50+
4951 public ReMenuButton ( string text , string tooltip , Action onClick , Transform parent , Sprite sprite = null , bool resizeTextNoSprite = true ) : base ( ButtonPrefab , parent ,
5052 $ "Button_{ text } ")
5153 {
5254 _text = GameObject . GetComponentInChildren < TextMeshProUGUI > ( ) ;
5355 _text . text = text ;
5456 _text . richText = true ;
57+
58+ Background = RectTransform . Find ( "Background" ) . GetComponent < Image > ( ) ;
59+
5560 if ( sprite == null )
5661 {
5762 if ( resizeTextNoSprite )
@@ -63,7 +68,7 @@ public ReMenuButton(string text, string tooltip, Action onClick, Transform paren
6368 _text . m_htmlColor = new Color ( 0.4157f , 0.8902f , 0.9765f , 1f ) ;
6469 _text . transform . localPosition = new Vector3 ( _text . transform . localPosition . x , - 30f ) ;
6570
66- var layoutElement = RectTransform . Find ( " Background" ) . gameObject . AddComponent < LayoutElement > ( ) ;
71+ var layoutElement = Background . gameObject . AddComponent < LayoutElement > ( ) ;
6772 layoutElement . ignoreLayout = true ;
6873
6974 var horizontalLayout = GameObject . AddComponent < HorizontalLayoutGroup > ( ) ;
@@ -96,17 +101,21 @@ public ReMenuButton(string text, string tooltip, Action onClick, Transform paren
96101 var uiTooltip = GameObject . GetComponent < VRC . UI . Elements . Tooltips . UiTooltip > ( ) ;
97102 uiTooltip . field_Public_String_0 = tooltip ;
98103 uiTooltip . field_Public_String_1 = tooltip ;
99-
100- _button = GameObject . GetComponent < Button > ( ) ;
101- _button . onClick = new Button . ButtonClickedEvent ( ) ;
102- _button . onClick . AddListener ( new Action ( onClick ) ) ;
104+
105+ if ( onClick != null )
106+ {
107+ _button = GameObject . GetComponent < Button > ( ) ;
108+ _button . onClick = new Button . ButtonClickedEvent ( ) ;
109+ _button . onClick . AddListener ( new Action ( onClick ) ) ;
110+ }
103111 }
104112
105113 public ReMenuButton ( Transform transform ) : base ( transform )
106114 {
107115 _text = GameObject . GetComponentInChildren < TextMeshProUGUI > ( ) ;
108116 _styleElement = GameObject . GetComponent < StyleElement > ( ) ;
109117 _button = GameObject . GetComponent < Button > ( ) ;
118+ Background = RectTransform . Find ( "Background" ) . GetComponent < Image > ( ) ;
110119 }
111120
112121 public static ReMenuButton Create ( string text , string tooltip , Action onClick , Transform parent , Sprite sprite = null )
0 commit comments