初始化
This commit is contained in:
62
UnityGame/Assets/Scripts/ThirdParty/YIUIFramework/Plugins/YIUILoad/LoadHandle/LoadHandle.cs
vendored
Normal file
62
UnityGame/Assets/Scripts/ThirdParty/YIUIFramework/Plugins/YIUILoad/LoadHandle/LoadHandle.cs
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace YIUIFramework
|
||||
{
|
||||
internal class LoadHandle : IRefPool
|
||||
{
|
||||
internal string PkgName { get; private set; }
|
||||
internal string ResName { get; private set; }
|
||||
internal int Handle { get; private set; }
|
||||
internal int RefCount { get; private set; }
|
||||
internal Object Object { get; private set; }
|
||||
|
||||
internal void SetGroupHandle(string pkgName, string resName)
|
||||
{
|
||||
PkgName = pkgName;
|
||||
ResName = resName;
|
||||
}
|
||||
|
||||
public void Recycle()
|
||||
{
|
||||
PkgName = string.Empty;
|
||||
ResName = string.Empty;
|
||||
Handle = 0;
|
||||
RefCount = 0;
|
||||
Object = null;
|
||||
}
|
||||
|
||||
internal void ResetHandle(Object obj, int handle)
|
||||
{
|
||||
Object = obj;
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
internal void AddRefCount()
|
||||
{
|
||||
RefCount++;
|
||||
}
|
||||
|
||||
internal void RemoveRefCount()
|
||||
{
|
||||
RefCount--;
|
||||
if (RefCount <= 0)
|
||||
{
|
||||
Release();
|
||||
}
|
||||
}
|
||||
|
||||
private void Release()
|
||||
{
|
||||
if (Handle != 0)
|
||||
YIUILoadDI.ReleaseAction?.Invoke(Handle);
|
||||
LoadHelper.PutLoad(PkgName, ResName);
|
||||
}
|
||||
|
||||
internal bool WaitAsync { get; private set; }
|
||||
|
||||
internal void SetWaitAsync(bool value)
|
||||
{
|
||||
WaitAsync = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 023914783fab4f48953b0b61c8dd9457
|
||||
timeCreated: 1688365598
|
||||
76
UnityGame/Assets/Scripts/ThirdParty/YIUIFramework/Plugins/YIUILoad/LoadHandle/LoadHelper.cs
vendored
Normal file
76
UnityGame/Assets/Scripts/ThirdParty/YIUIFramework/Plugins/YIUILoad/LoadHandle/LoadHelper.cs
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YIUIFramework
|
||||
{
|
||||
internal static partial class LoadHelper
|
||||
{
|
||||
private static string s_NullPkgName = "Default";
|
||||
|
||||
private static Dictionary<string, Dictionary<string, LoadHandle>> m_AllLoadDic =
|
||||
new Dictionary<string, Dictionary<string, LoadHandle>>();
|
||||
|
||||
internal static LoadHandle GetLoad(string pkgName, string resName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pkgName))
|
||||
{
|
||||
pkgName = s_NullPkgName;
|
||||
}
|
||||
|
||||
if (!m_AllLoadDic.ContainsKey(pkgName))
|
||||
{
|
||||
m_AllLoadDic.Add(pkgName, new Dictionary<string, LoadHandle>());
|
||||
}
|
||||
|
||||
var pkgDic = m_AllLoadDic[pkgName];
|
||||
|
||||
if (!pkgDic.ContainsKey(resName))
|
||||
{
|
||||
var group = RefPool.Get<LoadHandle>();
|
||||
group.SetGroupHandle(pkgName, resName);
|
||||
pkgDic.Add(resName, group);
|
||||
}
|
||||
|
||||
return pkgDic[resName];
|
||||
}
|
||||
|
||||
internal static bool PutLoad(string pkgName, string resName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pkgName))
|
||||
{
|
||||
pkgName = s_NullPkgName;
|
||||
}
|
||||
|
||||
if (!m_AllLoadDic.ContainsKey(pkgName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var pkgDic = m_AllLoadDic[pkgName];
|
||||
|
||||
if (!pkgDic.ContainsKey(resName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var load = pkgDic[resName];
|
||||
pkgDic.Remove(resName);
|
||||
RemoveLoadHandle(load);
|
||||
RefPool.Put(load);
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void PutAll()
|
||||
{
|
||||
foreach (var pkgDic in m_AllLoadDic.Values)
|
||||
{
|
||||
foreach (var load in pkgDic.Values)
|
||||
{
|
||||
RefPool.Put(load);
|
||||
}
|
||||
}
|
||||
|
||||
m_AllLoadDic.Clear();
|
||||
m_ObjLoadHandle.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7351aab0776482f9b21092caefbaa09
|
||||
timeCreated: 1688366062
|
||||
59
UnityGame/Assets/Scripts/ThirdParty/YIUIFramework/Plugins/YIUILoad/LoadHandle/LoadHelper_obj.cs
vendored
Normal file
59
UnityGame/Assets/Scripts/ThirdParty/YIUIFramework/Plugins/YIUILoad/LoadHandle/LoadHelper_obj.cs
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YIUIFramework
|
||||
{
|
||||
internal static partial class LoadHelper
|
||||
{
|
||||
private static Dictionary<Object, LoadHandle> m_ObjLoadHandle = new Dictionary<Object, LoadHandle>();
|
||||
|
||||
internal static bool AddLoadHandle(Object obj, LoadHandle handle)
|
||||
{
|
||||
if (m_ObjLoadHandle.ContainsKey(obj))
|
||||
{
|
||||
if (m_ObjLoadHandle[obj] != handle)
|
||||
{
|
||||
Debug.LogError($"此obj {obj.name} Handle 已存在 且前后不一致 请检查 请勿创建多个");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
m_ObjLoadHandle.Add(obj, handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool RemoveLoadHandle(LoadHandle handle)
|
||||
{
|
||||
var obj = handle.Object;
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return RemoveLoadHandle(obj);
|
||||
}
|
||||
|
||||
private static bool RemoveLoadHandle(Object obj)
|
||||
{
|
||||
if (!m_ObjLoadHandle.ContainsKey(obj))
|
||||
{
|
||||
Debug.LogError($"此obj {obj.name} Handle 不存在 请检查 请先创建设置");
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_ObjLoadHandle.Remove(obj);
|
||||
}
|
||||
|
||||
internal static LoadHandle GetLoadHandle(Object obj)
|
||||
{
|
||||
if (!m_ObjLoadHandle.ContainsKey(obj))
|
||||
{
|
||||
Debug.LogError($"此obj {obj.name} Handle 不存在 请检查 请先创建设置");
|
||||
return null;
|
||||
}
|
||||
|
||||
return m_ObjLoadHandle[obj];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c93e02ca9d19437483150cabad564dde
|
||||
timeCreated: 1688366653
|
||||
Reference in New Issue
Block a user