182 lines
4.4 KiB
C#
182 lines
4.4 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using Thousandto.Plugins.Common;
|
|
using Thousandto.Core.Base;
|
|
using Thousandto.Code.Global;
|
|
using System.Collections.Generic;
|
|
using EventManager = UnityEngine.Gonbest.MagicCube.EventManager;
|
|
using EventSystemHandler = UnityEngine.Gonbest.MagicCube.EventSystemHandler;
|
|
|
|
namespace Thousandto.GameUI.Form
|
|
{
|
|
public class UISubPanelBasePanel<TUINormal> : UIBaseFormAnimation
|
|
{
|
|
#region//私有变量
|
|
private TUINormal _parent = default(TUINormal);
|
|
//所有事件的记录
|
|
private Dictionary<int, EventSystemHandler> _allEvents = new Dictionary<int, EventSystemHandler>();
|
|
//是否已经显示
|
|
private bool _isVisible = false;
|
|
#endregion
|
|
|
|
#region//属性
|
|
public TUINormal Parent
|
|
{
|
|
get
|
|
{
|
|
return _parent;
|
|
}
|
|
}
|
|
//是否已经显示
|
|
public bool IsVisible
|
|
{
|
|
get
|
|
{
|
|
return _isVisible;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region//子类继承
|
|
//第一次显示
|
|
public virtual void OnFirstShow(TUINormal parent)
|
|
{
|
|
_parent = parent;
|
|
gameObject.SetActive(false);
|
|
_isVisible = false;
|
|
}
|
|
|
|
//注册事件
|
|
protected virtual void OnRegisterEvents()
|
|
{
|
|
|
|
}
|
|
|
|
//显示之前
|
|
protected virtual void OnShowBefore()
|
|
{
|
|
|
|
}
|
|
//显示之后
|
|
protected virtual void OnShowAfter()
|
|
{
|
|
|
|
}
|
|
//关闭之前
|
|
protected virtual void OnHideBefore()
|
|
{
|
|
|
|
}
|
|
//关闭之后
|
|
protected virtual void OnHideAfter()
|
|
{
|
|
|
|
}
|
|
//尝试关闭
|
|
public virtual bool OnTryHide()
|
|
{
|
|
return true;
|
|
}
|
|
//执行刷新
|
|
public virtual void Refresh()
|
|
{
|
|
|
|
}
|
|
|
|
protected override void OnFormDestroy()
|
|
{
|
|
UnRegisterEvents();
|
|
base.OnFormDestroy();
|
|
}
|
|
#endregion
|
|
|
|
#region//公有函数
|
|
//打开
|
|
public void Open()
|
|
{
|
|
OnShowBefore();
|
|
PlayEnableAnimation(OnShowAnimFinish);
|
|
_isVisible = true;
|
|
OnShowAfter();
|
|
}
|
|
//关闭
|
|
public void Close()
|
|
{
|
|
if (!_isVisible)
|
|
return;
|
|
if (!gameObject.activeSelf)
|
|
return;
|
|
|
|
_isVisible = false;
|
|
OnHideBefore();
|
|
PlayDisableAnimation(OnHideAnimFinish);
|
|
}
|
|
|
|
|
|
//注册一个事件
|
|
public void RegisterEvent(UIEventDefine eventName, EventSystemHandler eventHandler)
|
|
{
|
|
_allEvents.Add((int)eventName, eventHandler);
|
|
}
|
|
//注册一个事件
|
|
public void RegisterEvent(LogicEventDefine eventName, EventSystemHandler eventHandler)
|
|
{
|
|
_allEvents.Add((int)eventName, eventHandler);
|
|
}
|
|
//注册一个事件
|
|
public void RegisterEvent(int eventName, EventSystemHandler eventHandler)
|
|
{
|
|
_allEvents.Add(eventName, eventHandler);
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region//私有函数
|
|
private void OnEnable()
|
|
{
|
|
RegisterEvents();
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
UnRegisterEvents();
|
|
}
|
|
|
|
|
|
//注册事件
|
|
private void RegisterEvents()
|
|
{
|
|
_allEvents.Clear();
|
|
OnRegisterEvents();
|
|
var iter = _allEvents.GetEnumerator();
|
|
while (iter.MoveNext())
|
|
{
|
|
//TODO 注册UIevent
|
|
EventManager.SharedInstance.RegFixEventHandle((int)iter.Current.Key, iter.Current.Value);
|
|
}
|
|
}
|
|
|
|
//卸载事件
|
|
private void UnRegisterEvents()
|
|
{
|
|
var iter = _allEvents.GetEnumerator();
|
|
while (iter.MoveNext())
|
|
{
|
|
//TODO 注册UIevent
|
|
EventManager.SharedInstance.UnRegFixEventHandle((int)iter.Current.Key, iter.Current.Value);
|
|
}
|
|
}
|
|
|
|
protected virtual void OnShowAnimFinish()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
protected virtual void OnHideAnimFinish()
|
|
{
|
|
gameObject.SetActive(false);
|
|
OnHideAfter();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|