//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 loyalsoft. All rights reserved.
// Homepage: http://www.game7000.com/
// Feedback: http://www.game7000.com/
//------------------------------------------------------------
using GameFramework.ObjectPool;
using GameFramework.Resource;
using System;
using System.Collections.Generic;
namespace GameFramework.UI
{
///
/// 界面管理器。
///
internal sealed partial class UIManager : GameFrameworkModule, IUIManager
{
private readonly Dictionary m_UIGroups;
private readonly Dictionary m_UIFormsBeingLoaded;
private readonly HashSet m_UIFormsToReleaseOnLoad;
private readonly Queue m_RecycleQueue;
private readonly LoadAssetCallbacks m_LoadAssetCallbacks;
private IObjectPoolManager m_ObjectPoolManager;
private IResourceManager m_ResourceManager;
private IObjectPool m_InstancePool;
private IUIFormHelper m_UIFormHelper;
private int m_Serial;
private bool m_IsShutdown;
private EventHandler m_OpenUIFormSuccessEventHandler;
private EventHandler m_OpenUIFormFailureEventHandler;
private EventHandler m_OpenUIFormUpdateEventHandler;
private EventHandler m_OpenUIFormDependencyAssetEventHandler;
private EventHandler m_CloseUIFormCompleteEventHandler;
///
/// 初始化界面管理器的新实例。
///
public UIManager()
{
m_UIGroups = new Dictionary(StringComparer.Ordinal);
m_UIFormsBeingLoaded = new Dictionary();
m_UIFormsToReleaseOnLoad = new HashSet();
m_RecycleQueue = new Queue();
m_LoadAssetCallbacks = new LoadAssetCallbacks(LoadAssetSuccessCallback, LoadAssetFailureCallback, LoadAssetUpdateCallback, LoadAssetDependencyAssetCallback);
m_ObjectPoolManager = null;
m_ResourceManager = null;
m_InstancePool = null;
m_UIFormHelper = null;
m_Serial = 0;
m_IsShutdown = false;
m_OpenUIFormSuccessEventHandler = null;
m_OpenUIFormFailureEventHandler = null;
m_OpenUIFormUpdateEventHandler = null;
m_OpenUIFormDependencyAssetEventHandler = null;
m_CloseUIFormCompleteEventHandler = null;
}
///
/// 获取界面组数量。
///
public int UIGroupCount
{
get
{
return m_UIGroups.Count;
}
}
///
/// 获取或设置界面实例对象池自动释放可释放对象的间隔秒数。
///
public float InstanceAutoReleaseInterval
{
get
{
return m_InstancePool.AutoReleaseInterval;
}
set
{
m_InstancePool.AutoReleaseInterval = value;
}
}
///
/// 获取或设置界面实例对象池的容量。
///
public int InstanceCapacity
{
get
{
return m_InstancePool.Capacity;
}
set
{
m_InstancePool.Capacity = value;
}
}
///
/// 获取或设置界面实例对象池对象过期秒数。
///
public float InstanceExpireTime
{
get
{
return m_InstancePool.ExpireTime;
}
set
{
m_InstancePool.ExpireTime = value;
}
}
///
/// 获取或设置界面实例对象池的优先级。
///
public int InstancePriority
{
get
{
return m_InstancePool.Priority;
}
set
{
m_InstancePool.Priority = value;
}
}
///
/// 打开界面成功事件。
///
public event EventHandler OpenUIFormSuccess
{
add
{
m_OpenUIFormSuccessEventHandler += value;
}
remove
{
m_OpenUIFormSuccessEventHandler -= value;
}
}
///
/// 打开界面失败事件。
///
public event EventHandler OpenUIFormFailure
{
add
{
m_OpenUIFormFailureEventHandler += value;
}
remove
{
m_OpenUIFormFailureEventHandler -= value;
}
}
///
/// 打开界面更新事件。
///
public event EventHandler OpenUIFormUpdate
{
add
{
m_OpenUIFormUpdateEventHandler += value;
}
remove
{
m_OpenUIFormUpdateEventHandler -= value;
}
}
///
/// 打开界面时加载依赖资源事件。
///
public event EventHandler OpenUIFormDependencyAsset
{
add
{
m_OpenUIFormDependencyAssetEventHandler += value;
}
remove
{
m_OpenUIFormDependencyAssetEventHandler -= value;
}
}
///
/// 关闭界面完成事件。
///
public event EventHandler CloseUIFormComplete
{
add
{
m_CloseUIFormCompleteEventHandler += value;
}
remove
{
m_CloseUIFormCompleteEventHandler -= value;
}
}
///
/// 界面管理器轮询。
///
/// 逻辑流逝时间,以秒为单位。
/// 真实流逝时间,以秒为单位。
internal override void Update(float elapseSeconds, float realElapseSeconds)
{
while (m_RecycleQueue.Count > 0)
{
IUIForm uiForm = m_RecycleQueue.Dequeue();
uiForm.OnRecycle();
m_InstancePool.Unspawn(uiForm.Handle);
}
foreach (KeyValuePair uiGroup in m_UIGroups)
{
uiGroup.Value.Update(elapseSeconds, realElapseSeconds);
}
}
///
/// 关闭并清理界面管理器。
///
internal override void Shutdown()
{
m_IsShutdown = true;
CloseAllLoadedUIForms();
m_UIGroups.Clear();
m_UIFormsBeingLoaded.Clear();
m_UIFormsToReleaseOnLoad.Clear();
m_RecycleQueue.Clear();
}
///
/// 设置对象池管理器。
///
/// 对象池管理器。
public void SetObjectPoolManager(IObjectPoolManager objectPoolManager)
{
if (objectPoolManager == null)
{
throw new GameFrameworkException("Object pool manager is invalid.");
}
m_ObjectPoolManager = objectPoolManager;
m_InstancePool = m_ObjectPoolManager.CreateSingleSpawnObjectPool("UI Instance Pool");
}
///
/// 设置资源管理器。
///
/// 资源管理器。
public void SetResourceManager(IResourceManager resourceManager)
{
if (resourceManager == null)
{
throw new GameFrameworkException("Resource manager is invalid.");
}
m_ResourceManager = resourceManager;
}
///
/// 设置界面辅助器。
///
/// 界面辅助器。
public void SetUIFormHelper(IUIFormHelper uiFormHelper)
{
if (uiFormHelper == null)
{
throw new GameFrameworkException("UI form helper is invalid.");
}
m_UIFormHelper = uiFormHelper;
}
///
/// 是否存在界面组。
///
/// 界面组名称。
/// 是否存在界面组。
public bool HasUIGroup(string uiGroupName)
{
if (string.IsNullOrEmpty(uiGroupName))
{
throw new GameFrameworkException("UI group name is invalid.");
}
return m_UIGroups.ContainsKey(uiGroupName);
}
///
/// 获取界面组。
///
/// 界面组名称。
/// 要获取的界面组。
public IUIGroup GetUIGroup(string uiGroupName)
{
if (string.IsNullOrEmpty(uiGroupName))
{
throw new GameFrameworkException("UI group name is invalid.");
}
UIGroup uiGroup = null;
if (m_UIGroups.TryGetValue(uiGroupName, out uiGroup))
{
return uiGroup;
}
return null;
}
///
/// 获取所有界面组。
///
/// 所有界面组。
public IUIGroup[] GetAllUIGroups()
{
int index = 0;
IUIGroup[] results = new IUIGroup[m_UIGroups.Count];
foreach (KeyValuePair uiGroup in m_UIGroups)
{
results[index++] = uiGroup.Value;
}
return results;
}
///
/// 获取所有界面组。
///
/// 所有界面组。
public void GetAllUIGroups(List results)
{
if (results == null)
{
throw new GameFrameworkException("Results is invalid.");
}
results.Clear();
foreach (KeyValuePair uiGroup in m_UIGroups)
{
results.Add(uiGroup.Value);
}
}
///
/// 增加界面组。
///
/// 界面组名称。
/// 界面组辅助器。
/// 是否增加界面组成功。
public bool AddUIGroup(string uiGroupName, IUIGroupHelper uiGroupHelper)
{
return AddUIGroup(uiGroupName, 0, uiGroupHelper);
}
///
/// 增加界面组。
///
/// 界面组名称。
/// 界面组深度。
/// 界面组辅助器。
/// 是否增加界面组成功。
public bool AddUIGroup(string uiGroupName, int uiGroupDepth, IUIGroupHelper uiGroupHelper)
{
if (string.IsNullOrEmpty(uiGroupName))
{
throw new GameFrameworkException("UI group name is invalid.");
}
if (uiGroupHelper == null)
{
throw new GameFrameworkException("UI group helper is invalid.");
}
if (HasUIGroup(uiGroupName))
{
return false;
}
m_UIGroups.Add(uiGroupName, new UIGroup(uiGroupName, uiGroupDepth, uiGroupHelper));
return true;
}
///
/// 是否存在界面。
///
/// 界面序列编号。
/// 是否存在界面。
public bool HasUIForm(int serialId)
{
foreach (KeyValuePair uiGroup in m_UIGroups)
{
if (uiGroup.Value.HasUIForm(serialId))
{
return true;
}
}
return false;
}
///
/// 是否存在界面。
///
/// 界面资源名称。
/// 是否存在界面。
public bool HasUIForm(string uiFormAssetName)
{
if (string.IsNullOrEmpty(uiFormAssetName))
{
throw new GameFrameworkException("UI form asset name is invalid.");
}
foreach (KeyValuePair uiGroup in m_UIGroups)
{
if (uiGroup.Value.HasUIForm(uiFormAssetName))
{
return true;
}
}
return false;
}
///
/// 获取界面。
///
/// 界面序列编号。
/// 要获取的界面。
public IUIForm GetUIForm(int serialId)
{
foreach (KeyValuePair uiGroup in m_UIGroups)
{
IUIForm uiForm = uiGroup.Value.GetUIForm(serialId);
if (uiForm != null)
{
return uiForm;
}
}
return null;
}
///
/// 获取界面。
///
/// 界面资源名称。
/// 要获取的界面。
public IUIForm GetUIForm(string uiFormAssetName)
{
if (string.IsNullOrEmpty(uiFormAssetName))
{
throw new GameFrameworkException("UI form asset name is invalid.");
}
foreach (KeyValuePair uiGroup in m_UIGroups)
{
IUIForm uiForm = uiGroup.Value.GetUIForm(uiFormAssetName);
if (uiForm != null)
{
return uiForm;
}
}
return null;
}
///
/// 获取界面。
///
/// 界面资源名称。
/// 要获取的界面。
public IUIForm[] GetUIForms(string uiFormAssetName)
{
if (string.IsNullOrEmpty(uiFormAssetName))
{
throw new GameFrameworkException("UI form asset name is invalid.");
}
List results = new List();
foreach (KeyValuePair uiGroup in m_UIGroups)
{
results.AddRange(uiGroup.Value.GetUIForms(uiFormAssetName));
}
return results.ToArray();
}
///
/// 获取界面。
///
/// 界面资源名称。
/// 要获取的界面。
public void GetUIForms(string uiFormAssetName, List results)
{
if (string.IsNullOrEmpty(uiFormAssetName))
{
throw new GameFrameworkException("UI form asset name is invalid.");
}
if (results == null)
{
throw new GameFrameworkException("Results is invalid.");
}
results.Clear();
foreach (KeyValuePair uiGroup in m_UIGroups)
{
uiGroup.Value.InternalGetUIForms(uiFormAssetName, results);
}
}
///
/// 获取所有已加载的界面。
///
/// 所有已加载的界面。
public IUIForm[] GetAllLoadedUIForms()
{
List results = new List();
foreach (KeyValuePair uiGroup in m_UIGroups)
{
results.AddRange(uiGroup.Value.GetAllUIForms());
}
return results.ToArray();
}
///
/// 获取所有已加载的界面。
///
/// 所有已加载的界面。
public void GetAllLoadedUIForms(List results)
{
if (results == null)
{
throw new GameFrameworkException("Results is invalid.");
}
results.Clear();
foreach (KeyValuePair uiGroup in m_UIGroups)
{
uiGroup.Value.InternalGetAllUIForms(results);
}
}
///
/// 获取所有正在加载界面的序列编号。
///
/// 所有正在加载界面的序列编号。
public int[] GetAllLoadingUIFormSerialIds()
{
int index = 0;
int[] results = new int[m_UIFormsBeingLoaded.Count];
foreach (KeyValuePair uiFormBeingLoaded in m_UIFormsBeingLoaded)
{
results[index++] = uiFormBeingLoaded.Key;
}
return results;
}
///
/// 获取所有正在加载界面的序列编号。
///
/// 所有正在加载界面的序列编号。
public void GetAllLoadingUIFormSerialIds(List results)
{
if (results == null)
{
throw new GameFrameworkException("Results is invalid.");
}
results.Clear();
foreach (KeyValuePair uiFormBeingLoaded in m_UIFormsBeingLoaded)
{
results.Add(uiFormBeingLoaded.Key);
}
}
///
/// 是否正在加载界面。
///
/// 界面序列编号。
/// 是否正在加载界面。
public bool IsLoadingUIForm(int serialId)
{
return m_UIFormsBeingLoaded.ContainsKey(serialId);
}
///
/// 是否正在加载界面。
///
/// 界面资源名称。
/// 是否正在加载界面。
public bool IsLoadingUIForm(string uiFormAssetName)
{
if (string.IsNullOrEmpty(uiFormAssetName))
{
throw new GameFrameworkException("UI form asset name is invalid.");
}
return m_UIFormsBeingLoaded.ContainsValue(uiFormAssetName);
}
///
/// 是否是合法的界面。
///
/// 界面。
/// 界面是否合法。
public bool IsValidUIForm(IUIForm uiForm)
{
if (uiForm == null)
{
return false;
}
return HasUIForm(uiForm.SerialId);
}
///
/// 打开界面。
///
/// 界面资源名称。
/// 界面组名称。
/// 界面的序列编号。
public int OpenUIForm(string uiFormAssetName, string uiGroupName)
{
return OpenUIForm(uiFormAssetName, uiGroupName, Constant.DefaultPriority, false, null);
}
///
/// 打开界面。
///
/// 界面资源名称。
/// 界面组名称。
/// 加载界面资源的优先级。
/// 界面的序列编号。
public int OpenUIForm(string uiFormAssetName, string uiGroupName, int priority)
{
return OpenUIForm(uiFormAssetName, uiGroupName, priority, false, null);
}
///
/// 打开界面。
///
/// 界面资源名称。
/// 界面组名称。
/// 是否暂停被覆盖的界面。
/// 界面的序列编号。
public int OpenUIForm(string uiFormAssetName, string uiGroupName, bool pauseCoveredUIForm)
{
return OpenUIForm(uiFormAssetName, uiGroupName, Constant.DefaultPriority, pauseCoveredUIForm, null);
}
///
/// 打开界面。
///
/// 界面资源名称。
/// 界面组名称。
/// 用户自定义数据。
/// 界面的序列编号。
public int OpenUIForm(string uiFormAssetName, string uiGroupName, object userData)
{
return OpenUIForm(uiFormAssetName, uiGroupName, Constant.DefaultPriority, false, userData);
}
///
/// 打开界面。
///
/// 界面资源名称。
/// 界面组名称。
/// 加载界面资源的优先级。
/// 是否暂停被覆盖的界面。
/// 界面的序列编号。
public int OpenUIForm(string uiFormAssetName, string uiGroupName, int priority, bool pauseCoveredUIForm)
{
return OpenUIForm(uiFormAssetName, uiGroupName, priority, pauseCoveredUIForm, null);
}
///
/// 打开界面。
///
/// 界面资源名称。
/// 界面组名称。
/// 加载界面资源的优先级。
/// 用户自定义数据。
/// 界面的序列编号。
public int OpenUIForm(string uiFormAssetName, string uiGroupName, int priority, object userData)
{
return OpenUIForm(uiFormAssetName, uiGroupName, priority, false, userData);
}
///
/// 打开界面。
///
/// 界面资源名称。
/// 界面组名称。
/// 是否暂停被覆盖的界面。
/// 用户自定义数据。
/// 界面的序列编号。
public int OpenUIForm(string uiFormAssetName, string uiGroupName, bool pauseCoveredUIForm, object userData)
{
return OpenUIForm(uiFormAssetName, uiGroupName, Constant.DefaultPriority, pauseCoveredUIForm, userData);
}
///
/// 打开界面。
///
/// 界面资源名称。
/// 界面组名称。
/// 加载界面资源的优先级。
/// 是否暂停被覆盖的界面。
/// 用户自定义数据。
/// 界面的序列编号。
public int OpenUIForm(string uiFormAssetName, string uiGroupName, int priority, bool pauseCoveredUIForm, object userData)
{
if (m_ResourceManager == null)
{
throw new GameFrameworkException("You must set resource manager first.");
}
if (m_UIFormHelper == null)
{
throw new GameFrameworkException("You must set UI form helper first.");
}
if (string.IsNullOrEmpty(uiFormAssetName))
{
throw new GameFrameworkException("UI form asset name is invalid.");
}
if (string.IsNullOrEmpty(uiGroupName))
{
throw new GameFrameworkException("UI group name is invalid.");
}
UIGroup uiGroup = (UIGroup)GetUIGroup(uiGroupName);
if (uiGroup == null)
{
throw new GameFrameworkException(Utility.Text.Format("UI group '{0}' is not exist.", uiGroupName));
}
int serialId = ++m_Serial;
UIFormInstanceObject uiFormInstanceObject = m_InstancePool.Spawn(uiFormAssetName);
if (uiFormInstanceObject == null)
{
m_UIFormsBeingLoaded.Add(serialId, uiFormAssetName);
m_ResourceManager.LoadAsset(uiFormAssetName, priority, m_LoadAssetCallbacks, OpenUIFormInfo.Create(serialId, uiGroup, pauseCoveredUIForm, userData));
}
else
{
InternalOpenUIForm(serialId, uiFormAssetName, uiGroup, uiFormInstanceObject.Target, pauseCoveredUIForm, false, 0f, userData);
}
return serialId;
}
///
/// 关闭界面。
///
/// 要关闭界面的序列编号。
public void CloseUIForm(int serialId)
{
CloseUIForm(serialId, null);
}
///
/// 关闭界面。
///
/// 要关闭界面的序列编号。
/// 用户自定义数据。
public void CloseUIForm(int serialId, object userData)
{
if (IsLoadingUIForm(serialId))
{
m_UIFormsToReleaseOnLoad.Add(serialId);
m_UIFormsBeingLoaded.Remove(serialId);
return;
}
IUIForm uiForm = GetUIForm(serialId);
if (uiForm == null)
{
throw new GameFrameworkException(Utility.Text.Format("Can not find UI form '{0}'.", serialId));
}
CloseUIForm(uiForm, userData);
}
///
/// 关闭界面。
///
/// 要关闭的界面。
public void CloseUIForm(IUIForm uiForm)
{
CloseUIForm(uiForm, null);
}
///
/// 关闭界面。
///
/// 要关闭的界面。
/// 用户自定义数据。
public void CloseUIForm(IUIForm uiForm, object userData)
{
if (uiForm == null)
{
throw new GameFrameworkException("UI form is invalid.");
}
UIGroup uiGroup = (UIGroup)uiForm.UIGroup;
if (uiGroup == null)
{
throw new GameFrameworkException("UI group is invalid.");
}
uiGroup.RemoveUIForm(uiForm);
uiForm.OnClose(m_IsShutdown, userData);
uiGroup.Refresh();
if (m_CloseUIFormCompleteEventHandler != null)
{
CloseUIFormCompleteEventArgs closeUIFormCompleteEventArgs = CloseUIFormCompleteEventArgs.Create(uiForm.SerialId, uiForm.UIFormAssetName, uiGroup, userData);
m_CloseUIFormCompleteEventHandler(this, closeUIFormCompleteEventArgs);
ReferencePool.Release(closeUIFormCompleteEventArgs);
}
m_RecycleQueue.Enqueue(uiForm);
}
///
/// 关闭所有已加载的界面。
///
public void CloseAllLoadedUIForms()
{
CloseAllLoadedUIForms(null);
}
///
/// 关闭所有已加载的界面。
///
/// 用户自定义数据。
public void CloseAllLoadedUIForms(object userData)
{
IUIForm[] uiForms = GetAllLoadedUIForms();
foreach (IUIForm uiForm in uiForms)
{
if (!HasUIForm(uiForm.SerialId))
{
continue;
}
CloseUIForm(uiForm, userData);
}
}
///
/// 关闭所有正在加载的界面。
///
public void CloseAllLoadingUIForms()
{
foreach (KeyValuePair uiFormBeingLoaded in m_UIFormsBeingLoaded)
{
m_UIFormsToReleaseOnLoad.Add(uiFormBeingLoaded.Key);
}
m_UIFormsBeingLoaded.Clear();
}
///
/// 激活界面。
///
/// 要激活的界面。
public void RefocusUIForm(IUIForm uiForm)
{
RefocusUIForm(uiForm, null);
}
///
/// 激活界面。
///
/// 要激活的界面。
/// 用户自定义数据。
public void RefocusUIForm(IUIForm uiForm, object userData)
{
if (uiForm == null)
{
throw new GameFrameworkException("UI form is invalid.");
}
UIGroup uiGroup = (UIGroup)uiForm.UIGroup;
if (uiGroup == null)
{
throw new GameFrameworkException("UI group is invalid.");
}
uiGroup.RefocusUIForm(uiForm, userData);
uiGroup.Refresh();
uiForm.OnRefocus(userData);
}
///
/// 设置界面实例是否被加锁。
///
/// 要设置是否被加锁的界面实例。
/// 界面实例是否被加锁。
public void SetUIFormInstanceLocked(object uiFormInstance, bool locked)
{
if (uiFormInstance == null)
{
throw new GameFrameworkException("UI form instance is invalid.");
}
m_InstancePool.SetLocked(uiFormInstance, locked);
}
///
/// 设置界面实例的优先级。
///
/// 要设置优先级的界面实例。
/// 界面实例优先级。
public void SetUIFormInstancePriority(object uiFormInstance, int priority)
{
if (uiFormInstance == null)
{
throw new GameFrameworkException("UI form instance is invalid.");
}
m_InstancePool.SetPriority(uiFormInstance, priority);
}
private void InternalOpenUIForm(int serialId, string uiFormAssetName, UIGroup uiGroup, object uiFormInstance, bool pauseCoveredUIForm, bool isNewInstance, float duration, object userData)
{
try
{
IUIForm uiForm = m_UIFormHelper.CreateUIForm(uiFormInstance, uiGroup, userData);
if (uiForm == null)
{
throw new GameFrameworkException("Can not create UI form in UI form helper.");
}
uiForm.OnInit(serialId, uiFormAssetName, uiGroup, pauseCoveredUIForm, isNewInstance, userData);
uiGroup.AddUIForm(uiForm);
uiForm.OnOpen(userData);
uiGroup.Refresh();
if (m_OpenUIFormSuccessEventHandler != null)
{
OpenUIFormSuccessEventArgs openUIFormSuccessEventArgs = OpenUIFormSuccessEventArgs.Create(uiForm, duration, userData);
m_OpenUIFormSuccessEventHandler(this, openUIFormSuccessEventArgs);
ReferencePool.Release(openUIFormSuccessEventArgs);
}
}
catch (Exception exception)
{
if (m_OpenUIFormFailureEventHandler != null)
{
OpenUIFormFailureEventArgs openUIFormFailureEventArgs = OpenUIFormFailureEventArgs.Create(serialId, uiFormAssetName, uiGroup.Name, pauseCoveredUIForm, exception.ToString(), userData);
m_OpenUIFormFailureEventHandler(this, openUIFormFailureEventArgs);
ReferencePool.Release(openUIFormFailureEventArgs);
return;
}
throw;
}
}
private void LoadAssetSuccessCallback(string uiFormAssetName, object uiFormAsset, float duration, object userData)
{
OpenUIFormInfo openUIFormInfo = (OpenUIFormInfo)userData;
if (openUIFormInfo == null)
{
throw new GameFrameworkException("Open UI form info is invalid.");
}
if (m_UIFormsToReleaseOnLoad.Contains(openUIFormInfo.SerialId))
{
m_UIFormsToReleaseOnLoad.Remove(openUIFormInfo.SerialId);
ReferencePool.Release(openUIFormInfo);
m_UIFormHelper.ReleaseUIForm(uiFormAsset, null);
return;
}
m_UIFormsBeingLoaded.Remove(openUIFormInfo.SerialId);
UIFormInstanceObject uiFormInstanceObject = UIFormInstanceObject.Create(uiFormAssetName, uiFormAsset, m_UIFormHelper.InstantiateUIForm(uiFormAsset), m_UIFormHelper);
m_InstancePool.Register(uiFormInstanceObject, true);
InternalOpenUIForm(openUIFormInfo.SerialId, uiFormAssetName, openUIFormInfo.UIGroup, uiFormInstanceObject.Target, openUIFormInfo.PauseCoveredUIForm, true, duration, openUIFormInfo.UserData);
ReferencePool.Release(openUIFormInfo);
}
private void LoadAssetFailureCallback(string uiFormAssetName, LoadResourceStatus status, string errorMessage, object userData)
{
OpenUIFormInfo openUIFormInfo = (OpenUIFormInfo)userData;
if (openUIFormInfo == null)
{
throw new GameFrameworkException("Open UI form info is invalid.");
}
if (m_UIFormsToReleaseOnLoad.Contains(openUIFormInfo.SerialId))
{
m_UIFormsToReleaseOnLoad.Remove(openUIFormInfo.SerialId);
return;
}
m_UIFormsBeingLoaded.Remove(openUIFormInfo.SerialId);
string appendErrorMessage = Utility.Text.Format("Load UI form failure, asset name '{0}', status '{1}', error message '{2}'.", uiFormAssetName, status, errorMessage);
if (m_OpenUIFormFailureEventHandler != null)
{
OpenUIFormFailureEventArgs openUIFormFailureEventArgs = OpenUIFormFailureEventArgs.Create(openUIFormInfo.SerialId, uiFormAssetName, openUIFormInfo.UIGroup.Name, openUIFormInfo.PauseCoveredUIForm, appendErrorMessage, openUIFormInfo.UserData);
m_OpenUIFormFailureEventHandler(this, openUIFormFailureEventArgs);
ReferencePool.Release(openUIFormFailureEventArgs);
return;
}
throw new GameFrameworkException(appendErrorMessage);
}
private void LoadAssetUpdateCallback(string uiFormAssetName, float progress, object userData)
{
OpenUIFormInfo openUIFormInfo = (OpenUIFormInfo)userData;
if (openUIFormInfo == null)
{
throw new GameFrameworkException("Open UI form info is invalid.");
}
if (m_OpenUIFormUpdateEventHandler != null)
{
OpenUIFormUpdateEventArgs openUIFormUpdateEventArgs = OpenUIFormUpdateEventArgs.Create(openUIFormInfo.SerialId, uiFormAssetName, openUIFormInfo.UIGroup.Name, openUIFormInfo.PauseCoveredUIForm, progress, openUIFormInfo.UserData);
m_OpenUIFormUpdateEventHandler(this, openUIFormUpdateEventArgs);
ReferencePool.Release(openUIFormUpdateEventArgs);
}
}
private void LoadAssetDependencyAssetCallback(string uiFormAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData)
{
OpenUIFormInfo openUIFormInfo = (OpenUIFormInfo)userData;
if (openUIFormInfo == null)
{
throw new GameFrameworkException("Open UI form info is invalid.");
}
if (m_OpenUIFormDependencyAssetEventHandler != null)
{
OpenUIFormDependencyAssetEventArgs openUIFormDependencyAssetEventArgs = OpenUIFormDependencyAssetEventArgs.Create(openUIFormInfo.SerialId, uiFormAssetName, openUIFormInfo.UIGroup.Name, openUIFormInfo.PauseCoveredUIForm, dependencyAssetName, loadedCount, totalCount, openUIFormInfo.UserData);
m_OpenUIFormDependencyAssetEventHandler(this, openUIFormDependencyAssetEventArgs);
ReferencePool.Release(openUIFormDependencyAssetEventArgs);
}
}
}
}