public static void BuildAndRunPlayer(bool developmentBuild) { //This should ask where people want to build the player // string outputPath = EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebGL ? Utility.AssetBundlesOutputPath : (EditorUserBuildSettings.activeBuildTarget.ToString().IndexOf("Standalone") > -1 ? "Builds-Standalone" : "Builds-Devices"); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } //IMPORTANT Standalone Builds DELETE everything in the folder they are saved in- so building into the AssetBundles Folder DELETES ALL ASSETBUNDLES string[] levels = GetLevelsFromBuildSettings(); if (levels.Length == 0) { Debug.LogWarning("There were no Scenes in you Build Settings. Adding the current active Scene."); levels = new string[1] { UnityEngine.SceneManagement.SceneManager.GetActiveScene().path }; } string targetName = GetBuildTargetName(EditorUserBuildSettings.activeBuildTarget); if (targetName == null) { return; } //For Standalone or WebGL that can run locally make the server write a file with its current setting that it can get when the game runs if the localserver is enabled if (SimpleWebServer.serverStarted && CanRunLocally(EditorUserBuildSettings.activeBuildTarget)) { SimpleWebServer.WriteServerURL(); } else if (SimpleWebServer.serverStarted && !CanRunLocally(EditorUserBuildSettings.activeBuildTarget)) { Debug.LogWarning("Builds for " + EditorUserBuildSettings.activeBuildTarget.ToString() + " cannot access the LocalServer. AssetBundles will be downloaded from the remoteServerUrl's"); } //BuildOptions BuildOptions option = BuildOptions.None; if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebGL) { option = developmentBuild ? BuildOptions.Development : BuildOptions.None; } else { option = developmentBuild ? BuildOptions.Development | BuildOptions.AutoRunPlayer : BuildOptions.AutoRunPlayer; } string buildError = ""; #if UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 buildError = BuildPipeline.BuildPlayer(levels, outputPath + targetName, EditorUserBuildSettings.activeBuildTarget, option); #else BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); buildPlayerOptions.scenes = levels; buildPlayerOptions.locationPathName = outputPath + targetName; buildPlayerOptions.assetBundleManifestPath = GetAssetBundleManifestFilePath(); buildPlayerOptions.target = EditorUserBuildSettings.activeBuildTarget; buildPlayerOptions.options = option; buildError = BuildPipeline.BuildPlayer(buildPlayerOptions); #endif //after the build completes destroy the serverURL file if (SimpleWebServer.serverStarted && CanRunLocally(EditorUserBuildSettings.activeBuildTarget)) { SimpleWebServer.DestroyServerURLFile(); } if (buildError == "" || buildError == null) { string fullPathToBuild = Path.Combine(Directory.GetParent(Application.dataPath).FullName, outputPath); Debug.Log("Built Successful! Build Location: " + fullPathToBuild); if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebGL) { Application.OpenURL(SimpleWebServer.ServerURL + "index.html"); } } }
public override bool Update() { if (decryptedLoadOperation != null) { decryptedLoadOperation.Update(); if (decryptedLoadOperation.IsDone()) { assetBundle = decryptedLoadOperation.assetBundle; downloadProgress = 1f; m_WWW.Dispose(); m_WWW = null; return(false); } else //keep updating { downloadProgress = 0.9f + (decryptedLoadOperation.progress / 100); return(true); } } else { base.Update(); } // TODO: When can check iOS copy this into the iOS functions above // This checks that the download is actually happening and restarts it if it is not //fixes a bug in SimpleWebServer where it would randomly stop working for some reason if (!downloadIsDone) { downloadProgress = m_WWW.progress; if (!string.IsNullOrEmpty(m_WWW.error)) { Debug.Log("[AssetBundleLoadOperation] download error for " + m_WWW.url + " : " + m_WWW.error); } else { if (m_WWW.progress == 0) { zeroDownload++; } #if UNITY_EDITOR //Sometimes SimpleWebServer randomly looses it port connection //Sometimes restarting the download helps, sometimes it needs to be completely restarted if (SimpleWebServer.Instance != null) { if (zeroDownload == 150) { Debug.Log("[AssetBundleLoadOperation] progress was zero for 150 frames restarting dowload"); m_WWW.Dispose(); //sometimes makes a difference when the download fails m_WWW = null; m_WWW = new WWW(m_Url); } if (zeroDownload == 300) //If we are in the editor we can restart the Server and this will make it work { Debug.LogWarning("[AssetBundleLoadOperation] progress was zero for 300 frames restarting the server"); //we wont be able to do the following from a build int port = SimpleWebServer.Instance.Port; SimpleWebServer.Start(port); m_WWW.Dispose(); m_WWW = null; m_WWW = new WWW(m_Url); zeroDownload = 0; } } else #endif if (zeroDownload == 500) { Debug.Log("[AssetBundleLoadOperation] progress was zero for 500 frames restarting dowload"); m_WWW.Dispose(); m_WWW = null; m_WWW = new WWW(m_Url); zeroDownload = 0; } } return(true); } else { downloadProgress = 1f; return(false); } }