void ServerStart() { SimpleWebServer.Start(_port); _statusMessage = "Server Running"; UpdateHosts(); if (_activeHost == null) { ActiveHost = _hosts[0]; } SimpleWebServer.ServerURL = ActiveHost; }
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: iOS AppSlicing and OnDemandResources will need something like this too // 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) { //We actually need to know if progress has stalled, not just if there is none //so set the progress after we compare //downloadProgress = m_WWW.progress; if (!string.IsNullOrEmpty(m_WWW.error)) { if (Debug.isDebugBuild) { Debug.Log("[AssetBundleLoadOperation] download error for " + m_WWW.url + " : " + m_WWW.error); } } else { if (m_WWW.downloadProgress == downloadProgress) { zeroDownload++; } else { downloadProgress = m_WWW.downloadProgress; zeroDownload = 0; } #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) { if (Debug.isDebugBuild) { 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; #if UNITY_2018_1_OR_NEWER m_WWW = UnityWebRequestAssetBundle.GetAssetBundle(m_Url); #else m_WWW = UnityWebRequest.GetAssetBundle(m_Url); #endif #if UNITY_2017_2_OR_NEWER m_WWW.SendWebRequest(); #else m_WWW.Send(); #endif } if (zeroDownload == 300) //If we are in the editor we can restart the Server and this will make it work { if (Debug.isDebugBuild) { 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; #if UNITY_2018_1_OR_NEWER m_WWW = UnityWebRequestAssetBundle.GetAssetBundle(m_Url); #else m_WWW = UnityWebRequest.GetAssetBundle(m_Url); #endif #if UNITY_2017_2_OR_NEWER m_WWW.SendWebRequest(); #else m_WWW.Send(); #endif zeroDownload = 0; } } else #endif if ((downloadProgress == 0 && zeroDownload == 500) || zeroDownload >= Mathf.Clamp((2500 * downloadProgress), 500, 2500)) //let this number get larger the more has been downloaded (cos its really annoying to be at 98% and have it fail) { //when we cannot download because WiFi is connected but a hotspot needs authentication //or because the user has run out of mobile data the www class takes a while error out if ((AssetBundleManager.ConnectionChecker != null && !AssetBundleManager.ConnectionChecker.InternetAvailable) || retryAttempts > maxRetryAttempts) { if (retryAttempts > maxRetryAttempts) { //there was some unknown error with the connection //tell the user we could not complete the download error = "Downloading of " + assetBundleName + " failed after 10 attempts. Something is wrong with the internet connection."; m_WWW.Dispose(); m_WWW = null; } else { //if we have a connection checker and no connection, leave the www alone so it times out on its own if (Debug.isDebugBuild) { Debug.Log("[AssetBundleLoadOperation] progress was zero for " + zeroDownload + " frames and the ConnectionChecker said there was no Internet Available."); } } } else { if (Debug.isDebugBuild) { Debug.Log("[AssetBundleLoadOperation] progress was zero for " + zeroDownload + " frames restarting dowload"); } m_WWW.Dispose(); m_WWW = null; //m_WWW = new WWW(m_Url);//make sure this still caches if (AssetBundleManager.AssetBundleIndexObject != null) #if UNITY_2018_1_OR_NEWER { m_WWW = UnityWebRequestAssetBundle.GetAssetBundle(m_Url, AssetBundleManager.AssetBundleIndexObject.GetAssetBundleHash(assetBundleName), 0); } #else { m_WWW = UnityWebRequest.GetAssetBundle(m_Url, AssetBundleManager.AssetBundleIndexObject.GetAssetBundleHash(assetBundleName), 0); } #endif else #if UNITY_2018_1_OR_NEWER { m_WWW = UnityWebRequestAssetBundle.GetAssetBundle(m_Url); } #else { m_WWW = UnityWebRequest.GetAssetBundle(m_Url); } #endif //but increment the retry either way so the failed Ui shows sooner retryAttempts++; } zeroDownload = 0; } }
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); } }