diff --git a/Scripts/AssetBundleDownloader.cs b/Scripts/AssetBundleDownloader.cs index 3d3e3dc..70e1b7e 100644 --- a/Scripts/AssetBundleDownloader.cs +++ b/Scripts/AssetBundleDownloader.cs @@ -77,21 +77,21 @@ private IEnumerator Download(AssetBundleDownloadCommand cmd, int retryCount) var uri = baseUri + cmd.BundleName; UnityWebRequest req; if (cachingDisabled || (cmd.Version <= 0 && cmd.Hash == DEFAULT_HASH)) { - Debug.Log(string.Format("GetAssetBundle [{0}].", uri)); + if (AssetBundleManager.debugLoggingEnabled) Debug.Log(string.Format("GetAssetBundle [{0}].", uri)); #if UNITY_2018_1_OR_NEWER req = UnityWebRequestAssetBundle.GetAssetBundle(uri); #else req = UnityWebRequest.GetAssetBundle(uri); #endif } else if (cmd.Hash == DEFAULT_HASH) { - Debug.Log(string.Format("GetAssetBundle [{0}] v[{1}] [{2}].", Caching.IsVersionCached(uri, new Hash128(0, 0, 0, cmd.Version)) ? "cached" : "uncached", cmd.Version, uri)); + if (AssetBundleManager.debugLoggingEnabled) Debug.Log(string.Format("GetAssetBundle [{0}] v[{1}] [{2}].", Caching.IsVersionCached(uri, new Hash128(0, 0, 0, cmd.Version)) ? "cached" : "uncached", cmd.Version, uri)); #if UNITY_2018_1_OR_NEWER req = UnityWebRequestAssetBundle.GetAssetBundle(uri, cmd.Version, 0); #else req = UnityWebRequest.GetAssetBundle(uri, cmd.Version, 0); #endif } else { - Debug.Log(string.Format("GetAssetBundle [{0}] [{1}] [{2}].", Caching.IsVersionCached(uri, cmd.Hash) ? "cached" : "uncached", uri, cmd.Hash)); + if (AssetBundleManager.debugLoggingEnabled) Debug.Log(string.Format("GetAssetBundle [{0}] [{1}] [{2}].", Caching.IsVersionCached(uri, cmd.Hash) ? "cached" : "uncached", uri, cmd.Hash)); #if UNITY_2018_1_OR_NEWER req = UnityWebRequestAssetBundle.GetAssetBundle(uri, cmd.Hash, 0); #else diff --git a/Scripts/AssetBundleManager.cs b/Scripts/AssetBundleManager.cs index 59a6828..34ae58a 100644 --- a/Scripts/AssetBundleManager.cs +++ b/Scripts/AssetBundleManager.cs @@ -48,6 +48,7 @@ public enum PrimaryManifestType private string[] baseUri; private bool useHash; + internal static bool debugLoggingEnabled = true; private string platformName; private PrioritizationStrategy defaultPrioritizationStrategy; private ICommandHandler handler; @@ -80,7 +81,7 @@ public AssetBundleManager SetBaseUri(string uri) public AssetBundleManager SetBaseUri(string[] uris) { if (baseUri == null || baseUri.Length == 0) { - Debug.LogFormat("Setting base uri to [{0}].", string.Join(",", uris)); + if (debugLoggingEnabled) Debug.LogFormat("Setting base uri to [{0}].", string.Join(",", uris)); } else { Debug.LogWarningFormat("Overriding base uri from [{0}] to [{1}].", string.Join(",", baseUri), string.Join(",", uris)); } @@ -165,6 +166,12 @@ public AssetBundleManager UseLowerCasePlatformName(bool useLowerCase) return this; } + public AssetBundleManager DisableDebugLogging(bool disable = true) + { + debugLoggingEnabled = !disable; + return this; + } + /// /// Downloads the AssetBundle manifest and prepares the system for bundle management. /// Uses the platform name as the manifest name. This is the default behaviour when @@ -265,11 +272,11 @@ private void GetManifestInternal(string manifestName, uint version, int uriIndex OnComplete = manifest => { var maxIndex = baseUri.Length - 1; if (manifest == null && uriIndex < maxIndex && version > 1) { - Debug.LogFormat("Unable to download manifest from [{0}], attempting [{1}]", baseUri[uriIndex], baseUri[uriIndex + 1]); + if (debugLoggingEnabled) Debug.LogFormat("Unable to download manifest from [{0}], attempting [{1}]", baseUri[uriIndex], baseUri[uriIndex + 1]); GetManifestInternal(manifestName, version, uriIndex + 1); } else if (manifest == null && uriIndex >= maxIndex && version > 1 && PrimaryManifest != PrimaryManifestType.RemoteCached) { PrimaryManifest = PrimaryManifestType.RemoteCached; - Debug.LogFormat("Unable to download manifest, attempting to use one previously downloaded (version [{0}]).", version); + if (debugLoggingEnabled) Debug.LogFormat("Unable to download manifest, attempting to use one previously downloaded (version [{0}]).", version); GetManifestInternal(manifestName, version - 1, uriIndex); } else { OnInitializationComplete(manifest, manifestName, version); diff --git a/Scripts/StreamingAssetsBundleDownloadDecorator.cs b/Scripts/StreamingAssetsBundleDownloadDecorator.cs index 7cd86ae..b05631f 100644 --- a/Scripts/StreamingAssetsBundleDownloadDecorator.cs +++ b/Scripts/StreamingAssetsBundleDownloadDecorator.cs @@ -74,7 +74,7 @@ private IEnumerator InternalHandle(AssetBundleDownloadCommand cmd) { // Never use StreamingAssets for the manifest bundle, always try to use it for bundles with a matching hash (Unless the strategy says otherwise) if (BundleAvailableInStreamingAssets(cmd.BundleName, cmd.Hash)) { - Debug.LogFormat("Using StreamingAssets for bundle [{0}]", cmd.BundleName); + if (AssetBundleManager.debugLoggingEnabled) Debug.LogFormat("Using StreamingAssets for bundle [{0}]", cmd.BundleName); var request = AssetBundle.LoadFromFileAsync(fullBundlePath + "/" + cmd.BundleName); while (request.isDone == false) @@ -103,17 +103,17 @@ private bool BundleAvailableInStreamingAssets(string bundleName, Hash128 hash) // - The hash for the bundle in StreamingAssets matches the requested hash if (manifest == null) { - Debug.Log("StreamingAssets manifest is null, using standard download."); + if (AssetBundleManager.debugLoggingEnabled) Debug.Log("StreamingAssets manifest is null, using standard download."); return false; } if (bundleName == remoteManifestName) { - Debug.Log("Attempting to download manifest file, using standard download."); + if (AssetBundleManager.debugLoggingEnabled) Debug.Log("Attempting to download manifest file, using standard download."); return false; } if (manifest.GetAssetBundleHash(bundleName) != hash && currentStrategy != AssetBundleManager.PrioritizationStrategy.PrioritizeStreamingAssets) { - Debug.LogFormat("Hash for [{0}] does not match the one in StreamingAssets, using standard download.", bundleName); + if (AssetBundleManager.debugLoggingEnabled) Debug.LogFormat("Hash for [{0}] does not match the one in StreamingAssets, using standard download.", bundleName); return false; }