@@ -60,6 +60,7 @@ struct CategoryUI
6060 readonly List < SceneEntry > m_Scenes = new List < SceneEntry > ( ) ;
6161 readonly Dictionary < string , CategoryUI > m_Categories = new Dictionary < string , CategoryUI > ( ) ;
6262 readonly Dictionary < int , GameObject > m_Buttons = new Dictionary < int , GameObject > ( ) ;
63+ readonly HashSet < GameObject > m_ButtonSet = new HashSet < GameObject > ( ) ;
6364 Canvas m_Canvas ;
6465 Sprite m_RoundSprite ;
6566 TextMeshProUGUI m_Badge ;
@@ -86,12 +87,22 @@ void Awake()
8687 EventSystem . current . SetSelectedGameObject ( m_FirstButton ) ;
8788 }
8889
90+ void OnDestroy ( )
91+ {
92+ if ( m_RoundSprite != null )
93+ {
94+ if ( m_RoundSprite . texture != null )
95+ Destroy ( m_RoundSprite . texture ) ;
96+ Destroy ( m_RoundSprite ) ;
97+ }
98+ }
99+
89100 void LateUpdate ( )
90101 {
91102 if ( m_ScrollRect == null || EventSystem . current == null ) return ;
92103
93104 var selected = EventSystem . current . currentSelectedGameObject ;
94- if ( selected == null || ! m_Buttons . ContainsValue ( selected ) ) return ;
105+ if ( selected == null || ! m_ButtonSet . Contains ( selected ) ) return ;
95106
96107 var selectedRT = selected . GetComponent < RectTransform > ( ) ;
97108 var contentRT = m_ScrollRect . content ;
@@ -109,12 +120,12 @@ void LateUpdate()
109120 if ( selWorldBottom < vpWorldBottom )
110121 {
111122 float delta = vpWorldBottom - selWorldBottom + 10f ;
112- contentRT . anchoredPosition += new Vector2 ( 0 , - delta / m_ScrollRect . transform . lossyScale . y ) ;
123+ contentRT . anchoredPosition += new Vector2 ( 0 , delta / m_ScrollRect . transform . lossyScale . y ) ;
113124 }
114125 else if ( selWorldTop > vpWorldTop )
115126 {
116127 float delta = selWorldTop - vpWorldTop + 10f ;
117- contentRT . anchoredPosition += new Vector2 ( 0 , delta / m_ScrollRect . transform . lossyScale . y ) ;
128+ contentRT . anchoredPosition += new Vector2 ( 0 , - delta / m_ScrollRect . transform . lossyScale . y ) ;
118129 }
119130 }
120131
@@ -146,8 +157,11 @@ static void SetupEventSystem()
146157 {
147158 hasSceneES = true ;
148159 }
149- else
160+ else if ( es . gameObject . name == "[OverlayEventSystem]" )
150161 {
162+ // Clean up the ReturnToMenuOverlay's DDOL EventSystem that may
163+ // linger after returning to the menu. Other persistent
164+ // EventSystems (e.g. from a global manager) are left alone.
151165 es . gameObject . SetActive ( false ) ;
152166 Destroy ( es . gameObject ) ;
153167 }
@@ -618,6 +632,7 @@ void BuildSceneButton(Transform parent, SceneEntry entry)
618632 }
619633
620634 m_Buttons [ entry . buildIndex ] = go ;
635+ m_ButtonSet . Add ( go ) ;
621636 }
622637
623638 #endregion
0 commit comments