//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 loyalsoft. All rights reserved.
// Homepage: http://www.game7000.com/
// Feedback: http://www.game7000.com/
//------------------------------------------------------------
using GameFramework.UI;
using System;
using UnityEngine;
namespace UnityGameFramework.Runtime
{
///
/// 界面。
///
public sealed class UIForm : MonoBehaviour, IUIForm
{
private int m_SerialId;
private string m_UIFormAssetName;
private IUIGroup m_UIGroup;
private int m_DepthInUIGroup;
private bool m_PauseCoveredUIForm;
private UIFormLogic m_UIFormLogic;
///
/// 获取界面序列编号。
///
public int SerialId
{
get
{
return m_SerialId;
}
}
///
/// 获取界面资源名称。
///
public string UIFormAssetName
{
get
{
return m_UIFormAssetName;
}
}
///
/// 获取界面实例。
///
public object Handle
{
get
{
return gameObject;
}
}
///
/// 获取界面所属的界面组。
///
public IUIGroup UIGroup
{
get
{
return m_UIGroup;
}
}
///
/// 获取界面深度。
///
public int DepthInUIGroup
{
get
{
return m_DepthInUIGroup;
}
}
///
/// 获取是否暂停被覆盖的界面。
///
public bool PauseCoveredUIForm
{
get
{
return m_PauseCoveredUIForm;
}
}
///
/// 获取界面逻辑。
///
public UIFormLogic Logic
{
get
{
return m_UIFormLogic;
}
}
///
/// 初始化界面。
///
/// 界面序列编号。
/// 界面资源名称。
/// 界面所处的界面组。
/// 是否暂停被覆盖的界面。
/// 是否是新实例。
/// 用户自定义数据。
public void OnInit(int serialId, string uiFormAssetName, IUIGroup uiGroup, bool pauseCoveredUIForm, bool isNewInstance, object userData)
{
m_SerialId = serialId;
m_UIFormAssetName = uiFormAssetName;
m_UIGroup = uiGroup;
m_DepthInUIGroup = 0;
m_PauseCoveredUIForm = pauseCoveredUIForm;
if (!isNewInstance)
{
return;
}
m_UIFormLogic = GetComponent();
if (m_UIFormLogic == null)
{
Log.Error("UI form '{0}' can not get UI form logic.", uiFormAssetName);
return;
}
try
{
m_UIFormLogic.OnInit(userData);
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnInit with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面回收。
///
public void OnRecycle()
{
try
{
m_UIFormLogic.OnRecycle();
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnRecycle with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
m_SerialId = 0;
m_DepthInUIGroup = 0;
m_PauseCoveredUIForm = true;
}
///
/// 界面打开。
///
/// 用户自定义数据。
public void OnOpen(object userData)
{
try
{
m_UIFormLogic.OnOpen(userData);
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnOpen with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面关闭。
///
/// 是否是关闭界面管理器时触发。
/// 用户自定义数据。
public void OnClose(bool isShutdown, object userData)
{
try
{
m_UIFormLogic.OnClose(isShutdown, userData);
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnClose with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面暂停。
///
public void OnPause()
{
try
{
m_UIFormLogic.OnPause();
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnPause with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面暂停恢复。
///
public void OnResume()
{
try
{
m_UIFormLogic.OnResume();
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnResume with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面遮挡。
///
public void OnCover()
{
try
{
m_UIFormLogic.OnCover();
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnCover with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面遮挡恢复。
///
public void OnReveal()
{
try
{
m_UIFormLogic.OnReveal();
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnReveal with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面激活。
///
/// 用户自定义数据。
public void OnRefocus(object userData)
{
try
{
m_UIFormLogic.OnRefocus(userData);
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnRefocus with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面轮询。
///
/// 逻辑流逝时间,以秒为单位。
/// 真实流逝时间,以秒为单位。
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
try
{
m_UIFormLogic.OnUpdate(elapseSeconds, realElapseSeconds);
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnUpdate with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
///
/// 界面深度改变。
///
/// 界面组深度。
/// 界面在界面组中的深度。
public void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
{
m_DepthInUIGroup = depthInUIGroup;
try
{
m_UIFormLogic.OnDepthChanged(uiGroupDepth, depthInUIGroup);
}
catch (Exception exception)
{
Log.Error("UI form '[{0}]{1}' OnDepthChanged with exception '{2}'.", m_SerialId.ToString(), m_UIFormAssetName, exception.ToString());
}
}
}
}