Esempio n. 1
0
 private void LoadScene()
 {
     Networking.SetPrimarySocket(socket);
                 #if UNITY_4_6 || UNITY_4_7
     Application.LoadLevel(sceneName);
                 #else
     UnitySceneManager.LoadScene(sceneName);
                 #endif
 }
        private void Build()
        {
            string path = EditorUtility.SaveFolderPanel("Choose Build Location", "", "");

            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("Aborted because the path was not specified");
                return;
            }

            string[] levels = new string[2];
            for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
            {
                #if UNITY_4_6 || UNITY_4_7
                if (EditorBuildSettings.scenes[i].path.Contains(EditorApplication.currentScene))
                #else
                if (EditorBuildSettings.scenes[i].path.Contains(UnitySceneManager.GetCurrentEditorSceneName()))
                                #endif
                { levels[0] = EditorBuildSettings.scenes[i].path; }
                else if (EditorBuildSettings.scenes[i].path.Contains(Target.sceneName))
                {
                    levels[1] = EditorBuildSettings.scenes[i].path;
                }
            }

            if (levels[0] == null || levels[1] == null)
            {
                Debug.LogError("Aborted because the current scene and the target scene were not in the build settings");
                return;
            }

            path += "/Autobuild";

            if (System.IO.Directory.Exists(path))
            {
                System.IO.Directory.Delete(path, true);
            }

            System.IO.Directory.CreateDirectory(path);

            BuildTarget target    = BuildTarget.StandaloneWindows;
            string      extension = ".exe";

            if (platform == Platform.Mac)
            {
                target    = BuildTarget.StandaloneOSXIntel;
                extension = ".app";
            }
            else if (platform == Platform.Linux)
            {
                target    = BuildTarget.StandaloneLinux;
                extension = ".so";
            }

            Target.executePath = path + "/autobuild" + extension;

            ResolutionDialogSetting resolutionDialog = PlayerSettings.displayResolutionDialog;

            PlayerSettings.runInBackground         = true;
            PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;

            BuildPipeline.BuildPlayer(levels, Target.executePath, target, BuildOptions.None);

            PlayerSettings.displayResolutionDialog = resolutionDialog;

            EditorApplication.isPlaying = true;
        }