Пример #1
0
        private void Start()
        {
            if (SceneButtonPrefab == null)
            {
                return;
            }

            SceneLauncherBuildIndex = SceneManager.GetActiveScene().buildIndex;

            // Determine the size of the buttons. Instantiate one of them so that we can check its bounds.
            SceneLauncherButton sceneButtonForSize = Instantiate(SceneButtonPrefab);
            var sceneButtonForSizeCollider         = sceneButtonForSize.GetComponent <Collider>();

            if (sceneButtonForSizeCollider != null)
            {
                sceneButtonSize = sceneButtonForSizeCollider.bounds.size;
            }

            for (int sceneIndex = 0; sceneIndex < sceneMapping.Length; ++sceneIndex)
            {
                if (sceneMapping[sceneIndex].IsButtonEnabled)
                {
                    CreateSceneButton(ButtonSpawnLocation, sceneIndex);
                }
            }

            Destroy(sceneButtonForSize.gameObject);
        }
Пример #2
0
        private void CreateSceneButton(GameObject buttonParent, int sceneIndex, List <string> sceneNames)
        {
            string sceneName = sceneNames[sceneIndex];
            Scene  scene     = SceneManager.GetSceneByBuildIndex(sceneIndex);

            Debug.Assert(SceneManager.GetSceneByName(sceneName) == scene);

            SceneLauncherButton sceneButton = Instantiate(SceneButtonPrefab, GetButtonPosition(sceneIndex, sceneNames.Count), Quaternion.identity, buttonParent.transform);

            sceneButton.SceneIndex = sceneIndex;
            sceneButton.SceneName  = sceneName;
        }
Пример #3
0
        private void Start()
        {
            if (SceneButtonPrefab == null)
            {
                return;
            }

            if (ReturnToSceneLauncherPrefab != null)
            {
                GameObject exsistReturnToSceneLauncher = GameObject.Find("ReturnToSceneLauncher(Clone)");
                if (exsistReturnToSceneLauncher == null)
                {
                    returnToSceneLauncher = Instantiate(ReturnToSceneLauncherPrefab);
                    DontDestroyOnLoad(returnToSceneLauncher);
                }

                if (returnToSceneLauncher.KeywordsAndResponses.Length > 0)
                {
                    // Set the response action of the first keyword to reload this scene.
                    int         sceneLauncherBuildIndex = SceneManager.GetActiveScene().buildIndex;
                    UnityAction keywordAction           = delegate
                    {
                        Debug.LogFormat("SceneLauncher: Returning to SceneLauncher scene {0}.", sceneLauncherBuildIndex);
                        SceneManager.LoadScene(sceneLauncherBuildIndex, LoadSceneMode.Single);
                        //Application.LoadLevelAdditive("SceneLauncher");
                        GameObject.Destroy(returnToSceneLauncher.gameObject);
                    };
                    returnToSceneLauncher.KeywordsAndResponses[0].Response.AddListener(keywordAction);
                }
            }

            // Determine the size of the buttons. Instantiate one of them so that we can check its bounds.
            SceneLauncherButton sceneButtonForSize         = Instantiate(SceneButtonPrefab);
            Collider            sceneButtonForSizeCollider = sceneButtonForSize.GetComponent <Collider>();

            if (sceneButtonForSizeCollider != null)
            {
                sceneButtonSize = sceneButtonForSizeCollider.bounds.size;
            }
            Destroy(sceneButtonForSize.gameObject);

            // Create an empty game object to serve as a parent for all the buttons we're about to create.
            GameObject buttonParent = new GameObject("Buttons");

            List <string> sceneNames = SceneList.Instance.GetSceneNames();

            for (int sceneIndex = 0; sceneIndex < sceneNames.Count; ++sceneIndex)
            {
                CreateSceneButton(buttonParent, sceneIndex, sceneNames);
            }
        }
Пример #4
0
        private void CreateSceneButton(GameObject buttonParent, int sceneIndex)
        {
            string sceneName = sceneMapping[sceneIndex].ScenePath;

            sceneName = sceneName.Substring(sceneName.LastIndexOf("/", StringComparison.Ordinal) + 1);
            sceneName = sceneName.Replace(".unity", "");
            var scene = SceneManager.GetSceneByBuildIndex(sceneIndex);

            Debug.Assert(SceneManager.GetSceneByName(sceneName) == scene);

            SceneLauncherButton sceneButton = Instantiate(SceneButtonPrefab, GetButtonPosition(sceneIndex, sceneMapping.Length), Quaternion.identity, buttonParent.transform);

            sceneButton.SceneIndex    = sceneIndex;
            sceneButton.SceneName     = sceneName;
            sceneButton.MenuReference = ButtonSpawnLocation;
        }
Пример #5
0
        private void Start()
        {
            if (SceneButtonPrefab == null)
            {
                return;
            }

            SceneLauncherBuildIndex = SceneManager.GetActiveScene().buildIndex;

            // Determine the size of the buttons. Instantiate one of them so that we can check its bounds.
            SceneLauncherButton sceneButtonForSize = Instantiate(SceneButtonPrefab);
            var sceneButtonForSizeCollider         = sceneButtonForSize.GetComponent <Collider>();

            if (sceneButtonForSizeCollider != null)
            {
                sceneButtonSize = sceneButtonForSizeCollider.bounds.size;
            }

            for (int sceneIndex = 0; sceneIndex < sceneMapping.Length; ++sceneIndex)
            {
                //UnityEngine.Debug.Log("sceneIndex: " + sceneIndex + " " + sceneMapping[sceneIndex].ScenePath + " is enabled: " + sceneMapping[sceneIndex].IsButtonEnabled);

                // Check scene name and enable
                if (sceneMapping[sceneIndex].ScenePath == "Assets/scenes/cube middle plane.unity")
                {
                    sceneMapping[sceneIndex].IsButtonEnabled = true;
                }
                else if (sceneMapping[sceneIndex].ScenePath == "Assets/scenes/pointing middle plane.unity")
                {
                    sceneMapping[sceneIndex].IsButtonEnabled = true;
                }

                if (sceneMapping[sceneIndex].IsButtonEnabled)
                {
                    CreateSceneButton(ButtonSpawnLocation, sceneIndex);
                }
            }

            Destroy(sceneButtonForSize.gameObject);
        }