Skip to content

Commit

Permalink
fixed retry counter reference bug issue
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Sep 12, 2023
1 parent 3f24ede commit bd7a1d5
Show file tree
Hide file tree
Showing 11 changed files with 1,427 additions and 1,301 deletions.
4 changes: 2 additions & 2 deletions Assets/AssetBundleBuilderSetting.asset
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ MonoBehaviour:
BuildPackage: DefaultPackage
CompressOption: 2
OutputNameStyle: 1
CopyBuildinFileOption: 1
CopyBuildinFileOption: 0
CopyBuildinFileTags:
EncyptionClassName: HT2XorEncryption
EncyptionClassName: EncryptionNone
3 changes: 2 additions & 1 deletion Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetLoaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,8 @@ internal static bool RefineResourcesPath(ref string assetName)
{
if (assetName.Substring(0, prefix.Length).Equals(prefix))
{
assetName = assetName.Replace(prefix, string.Empty);
var count = assetName.Length - prefix.Length;
assetName = assetName.Substring(prefix.Length, count);
return true;
}
}
Expand Down
165 changes: 85 additions & 80 deletions Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/Base/AssetCache.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,85 @@
using System.Collections.Generic;

namespace OxGFrame.AssetLoader.Cacher
{
public abstract class AssetCache<T> : ICache<T>
{
public struct RetryCounter
{
public byte retryCount;
public byte maxRetryCount;

public RetryCounter(byte maxRetryCount)
{
this.retryCount = 0;
this.maxRetryCount = maxRetryCount;
}

public bool IsRetryValid()
{
// 嘗試次數先++, 後判斷, 所以需使用 <= 進行判斷
return this.retryCount <= maxRetryCount;
}

public void AddRetryCount()
{
this.retryCount++;
}
}

protected Dictionary<string, T> _cacher;

protected Dictionary<string, RetryCounter> _loadingFlags;

public float currentCount { get; protected set; }

public float totalCount { get; protected set; }

public int Count { get { return this._cacher.Count; } }

public abstract bool HasInCache(string assetName);

public abstract T GetFromCache(string assetName);

public AssetCache()
{
this._cacher = new Dictionary<string, T>();
this._loadingFlags = new Dictionary<string, RetryCounter>();
}

protected bool HasInLoadingFlags(string assetName)
{
if (string.IsNullOrEmpty(assetName)) return false;
return this._loadingFlags.ContainsKey(assetName);
}

protected void AddLoadingFlags(string assetName, byte maxRetryCount)
{
if (!this.HasInLoadingFlags(assetName)) this._loadingFlags.Add(assetName, new RetryCounter(maxRetryCount));
}

protected void RemoveLoadingFlags(string assetName)
{
if (this.HasInLoadingFlags(assetName)) this._loadingFlags.Remove(assetName);
}

protected RetryCounter GetRetryCounter(string assetName)
{
this._loadingFlags.TryGetValue(assetName, out RetryCounter retryCounter);
return retryCounter;
}

~AssetCache()
{
this._cacher.Clear();
this._cacher = null;
this._loadingFlags.Clear();
this._loadingFlags = null;
}
}
}
using System.Collections.Generic;

namespace OxGFrame.AssetLoader.Cacher
{
public abstract class AssetCache<T> : ICache<T>
{
public class RetryCounter
{
public byte retryCount;
public byte maxRetryCount;

public RetryCounter(byte maxRetryCount)
{
this.retryCount = 0;
this.maxRetryCount = maxRetryCount;
}

public bool IsRetryActive()
{
return this.retryCount > 0;
}

public bool IsRetryValid()
{
// 嘗試次數先++, 後判斷, 所以需使用 <= 進行判斷
return this.retryCount <= maxRetryCount;
}

public void AddRetryCount()
{
this.retryCount++;
}
}

protected Dictionary<string, T> _cacher;

protected Dictionary<string, RetryCounter> _loadingFlags;

public float currentCount { get; protected set; }

public float totalCount { get; protected set; }

public int Count { get { return this._cacher.Count; } }

public abstract bool HasInCache(string assetName);

public abstract T GetFromCache(string assetName);

public AssetCache()
{
this._cacher = new Dictionary<string, T>();
this._loadingFlags = new Dictionary<string, RetryCounter>();
}

protected bool HasInLoadingFlags(string assetName)
{
if (string.IsNullOrEmpty(assetName)) return false;
return this._loadingFlags.ContainsKey(assetName);
}

protected void AddLoadingFlags(string assetName, byte maxRetryCount)
{
if (!this.HasInLoadingFlags(assetName)) this._loadingFlags.Add(assetName, new RetryCounter(maxRetryCount));
}

protected void RemoveLoadingFlags(string assetName)
{
if (this.HasInLoadingFlags(assetName)) this._loadingFlags.Remove(assetName);
}

protected RetryCounter GetRetryCounter(string assetName)
{
this._loadingFlags.TryGetValue(assetName, out RetryCounter retryCounter);
return retryCounter;
}

~AssetCache()
{
this._cacher.Clear();
this._cacher = null;
this._loadingFlags.Clear();
this._loadingFlags = null;
}
}
}
Loading

0 comments on commit bd7a1d5

Please sign in to comment.