CTT/Unity/Assets/HotfixView/Model/FGUI/GObjectHelper.cs

39 lines
942 B
C#

using FairyGUI;
using System.Collections.Generic;
namespace ET
{
public static class GObjectHelper
{
private static Dictionary<GObject, FUI> _keyValuePairs = new Dictionary<GObject, FUI>();
public static T Get<T>(this GObject self) where T : FUI
{
if (self != null && _keyValuePairs.TryGetValue(self,out FUI ui))
{
return ui as T;
}
return default;
}
public static void Add(this GObject self, FUI fui)
{
if (self != null && fui != null)
{
_keyValuePairs[self] = fui;
}
}
public static FUI Remove(this GObject self)
{
if (self != null && _keyValuePairs.TryGetValue(self, out FUI ui))
{
_keyValuePairs.Remove(self);
return ui;
}
return null;
}
}
}