Skip to content

Commit 893c66c

Browse files
committed
Implement feedback from pull request #689.
1 parent 2a460d9 commit 893c66c

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

Assets/HoloToolkit/Utilities/Scripts/SceneLauncher.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using UnityEngine;
88
using UnityEngine.Events;
99
using UnityEngine.SceneManagement;
10-
using System;
1110

1211
namespace 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.

Assets/HoloToolkit/Utilities/Scripts/SceneList.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ private void LogSceneNames()
4242
{
4343
string sceneName = sceneNames[iScene];
4444
if (iScene > 0)
45+
{
4546
stringBuilder.Append(", ");
47+
}
4648
stringBuilder.Append(sceneName);
4749
}
4850
Debug.Log(stringBuilder.ToString());
@@ -74,7 +76,9 @@ private static List<string> GetSceneNamesFromEditor()
7476
foreach (UnityEditor.EditorBuildSettingsScene buildScene in UnityEditor.EditorBuildSettings.scenes)
7577
{
7678
if (!buildScene.enabled)
79+
{
7780
continue;
81+
}
7882
string name = Path.GetFileNameWithoutExtension(buildScene.path);
7983
result.Add(name);
8084
}
@@ -89,11 +93,15 @@ private static List<string> GetSceneNamesFromEditor()
8993
public static void OnPostProcessScene()
9094
{
9195
if (Application.isPlaying)
96+
{
9297
return;
98+
}
9399

94100
SceneList sceneList = FindObjectOfType<SceneList>();
95101
if (sceneList == null)
102+
{
96103
return;
104+
}
97105
sceneList.sceneNamesUpdatedByBuild = new List<string>(GetSceneNamesFromEditor());
98106
sceneList.LogSceneNames();
99107
}

0 commit comments

Comments
 (0)