Skip to content

Commit

Permalink
Added property to disable debug logging. Warnings and errors still al…
Browse files Browse the repository at this point in the history
…ways show.
  • Loading branch information
FodderMK committed Feb 17, 2020
1 parent 0dc2b51 commit 081e95c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Scripts/AssetBundleDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions Scripts/AssetBundleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssetBundleDownloadCommand> handler;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -165,6 +166,12 @@ public AssetBundleManager UseLowerCasePlatformName(bool useLowerCase)
return this;
}

public AssetBundleManager DisableDebugLogging(bool disable = true)
{
debugLoggingEnabled = !disable;
return this;
}

/// <summary>
/// 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
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Scripts/StreamingAssetsBundleDownloadDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 081e95c

Please sign in to comment.