77using UnityEngine ;
88using UnityEngine . Events ;
99using UnityEngine . SceneManagement ;
10- using System ;
1110
1211namespace HoloToolkit . Unity
1312{
@@ -31,13 +30,17 @@ private void OnValidate()
3130 Debug . Assert ( SceneButtonPrefab != null , "SceneLauncher.SceneButtonPrefab is not set." ) ;
3231 Debug . Assert ( ReturnToSceneLauncherPrefab != null , "SceneLauncher.ReturnToSceneLauncherPrefab is not set." ) ;
3332 if ( ReturnToSceneLauncherPrefab != null )
33+ {
3434 Debug . Assert ( ReturnToSceneLauncherPrefab . KeywordsAndResponses . Length > 0 , "SceneLauncher.ReturnToSceneLauncherPrefab has a KeywordManager with no keywords." ) ;
35+ }
3536 }
3637
3738 private void Start ( )
3839 {
3940 if ( SceneButtonPrefab == null )
41+ {
4042 return ;
43+ }
4144
4245 if ( ReturnToSceneLauncherPrefab != null )
4346 {
@@ -71,27 +74,27 @@ private void Start()
7174 GameObject buttonParent = new GameObject ( "Buttons" ) ;
7275
7376 List < string > sceneNames = SceneList . Instance . GetSceneNames ( ) ;
74- for ( int iScene = 0 ; iScene < sceneNames . Count ; ++ iScene )
77+ for ( int sceneIndex = 0 ; sceneIndex < sceneNames . Count ; ++ sceneIndex )
7578 {
76- CreateSceneButton ( buttonParent , iScene , sceneNames ) ;
79+ CreateSceneButton ( buttonParent , sceneIndex , sceneNames ) ;
7780 }
7881 }
7982
80- private void CreateSceneButton ( GameObject buttonParent , int iScene , List < string > sceneNames )
83+ private void CreateSceneButton ( GameObject buttonParent , int sceneIndex , List < string > sceneNames )
8184 {
82- string sceneName = sceneNames [ iScene ] ;
83- Scene scene = SceneManager . GetSceneByBuildIndex ( iScene ) ;
85+ string sceneName = sceneNames [ sceneIndex ] ;
86+ Scene scene = SceneManager . GetSceneByBuildIndex ( sceneIndex ) ;
8487 Debug . Assert ( SceneManager . GetSceneByName ( sceneName ) == scene ) ;
8588
86- Interactive sceneButton = Instantiate < Interactive > ( SceneButtonPrefab , GetButtonPosition ( iScene , sceneNames . Count ) , Quaternion . identity , buttonParent . transform ) ;
89+ Interactive sceneButton = Instantiate < Interactive > ( SceneButtonPrefab , GetButtonPosition ( sceneIndex , sceneNames . Count ) , Quaternion . identity , buttonParent . transform ) ;
8790 sceneButton . name = sceneName ;
8891 SetSceneButtonWidthScale ( sceneButton ) ;
8992 sceneButton . IsEnabled = scene != SceneManager . GetActiveScene ( ) ; // Disable button to launch our own scene.
90- int buildIndex = iScene ;
93+ int sceneBuildIndex = sceneIndex ;
9194 UnityAction buttonAction = delegate
9295 {
93- Debug . LogFormat ( "SceneLauncher: Loading scene {0}: {1}" , buildIndex , SceneList . Instance . GetSceneNames ( ) [ buildIndex ] ) ;
94- SceneManager . LoadScene ( buildIndex , LoadSceneMode . Single ) ;
96+ Debug . LogFormat ( "SceneLauncher: Loading scene {0}: {1}" , sceneBuildIndex , SceneList . Instance . GetSceneNames ( ) [ sceneBuildIndex ] ) ;
97+ SceneManager . LoadScene ( sceneBuildIndex , LoadSceneMode . Single ) ;
9598 } ;
9699 sceneButton . OnSelectEvents . AddListener ( buttonAction ) ;
97100 LabelTheme labelTheme = sceneButton . GetComponent < LabelTheme > ( ) ;
@@ -105,19 +108,21 @@ private void SetSceneButtonWidthScale(Interactive sceneButton)
105108 {
106109 // Scale the button horizontally by SceneButtonWidthScale to make more space for text.
107110 sceneButton . transform . localScale = Vector3 . Scale ( sceneButton . transform . localScale , new Vector3 ( SceneButtonWidthScale , 1.0f , 1.0f ) ) ;
108- foreach ( TextMesh textMesh in sceneButton . GetComponentsInChildren < TextMesh > ( ) )
111+ // For text, we are going to invert the scale applied to the button so that text isn't stretched by the scale.
112+ Vector3 textScale = new Vector3 ( 1.0f / SceneButtonWidthScale , 1.0f , 1.0f ) ;
113+ TextMesh [ ] childTextMeshes = sceneButton . GetComponentsInChildren < TextMesh > ( ) ;
114+ for ( int i = 0 ; i < childTextMeshes . Length ; i ++ )
109115 {
110- // Reverse the scale applied to the button so that the text isn't stretched by the scale.
111- textMesh . transform . localScale = Vector3 . Scale ( textMesh . transform . localScale , new Vector3 ( 1.0f / SceneButtonWidthScale , 1.0f , 1.0f ) ) ;
116+ childTextMeshes [ i ] . transform . localScale = Vector3 . Scale ( childTextMeshes [ i ] . transform . localScale , textScale ) ;
112117 }
113118 }
114119
115- private Vector3 GetButtonPosition ( int iScene , int numberOfScenes )
120+ private Vector3 GetButtonPosition ( int sceneIndex , int numberOfScenes )
116121 {
117122 int yCount = Mathf . Min ( numberOfScenes , MaxRows ) ;
118123 int xCount = ( numberOfScenes - 1 ) / yCount + 1 ;
119- int x = iScene % xCount ;
120- int y = iScene / xCount ;
124+ int x = sceneIndex % xCount ;
125+ int y = sceneIndex / xCount ;
121126 Debug . Assert ( x < xCount && y < yCount ) ;
122127
123128 // Center a grid of cells in a grid.
0 commit comments