using UnityEngine;
using System.Collections.Generic;
using System;
using FairyGUI;
using System.Linq;
using ET;
namespace GFGGame
{
///
/// 视图管理类
/// 管理视图的显示、隐藏
///
public class ViewManager
{
private static Dictionary _viewDic;
private static GComponent _bottomLayer;
private static GComponent _topLayer;
private static GComponent _guideLayer;
private static GComponent _modalLayer;
private static GComponent _alertLayer;
private static GComponent _debugLayer;
private static GComponent _floatLayer;
private static Dictionary> _goBackDatas = new Dictionary>();
public static void Init()
{
GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Common"));
UIConfig.buttonSound = (NAudioClip)UIPackage.GetItemAsset("Common", "click");
Font font0 = GFGAsset.Load(ResPathUtil.GetFontPath("FangZhengHeiTiJianTi-1", "ttf"));
FontManager.RegisterFont(new DynamicFont("FangZhengHeiTiJianTi-1", font0));
Font font1 = GFGAsset.Load(ResPathUtil.GetFontPath("FZKTJW--GB1-0", "ttf"));
FontManager.RegisterFont(new DynamicFont("FZKTJW--GB1-0", font1));
Font font2 = GFGAsset.Load(ResPathUtil.GetFontPath("SourceHanSerifCN-Regular-1", "otf"));
FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Regular-1", font2));
Font font3 = GFGAsset.Load(ResPathUtil.GetFontPath("SourceHanSerifCN-Bold-2", "otf"));
FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Bold-2", font3));
Font font4 = GFGAsset.Load(ResPathUtil.GetFontPath("SourceHanSerifCN-ExtraLight-3", "otf"));
FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-ExtraLight-3", font4));
Font font5 = GFGAsset.Load(ResPathUtil.GetFontPath("SourceHanSerifCN-Heavy-4", "otf"));
FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Heavy-4", font5));
Font font6 = GFGAsset.Load(ResPathUtil.GetFontPath("SourceHanSerifCN-Light-5", "otf"));
FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Light-5", font6));
Font font7 = GFGAsset.Load(ResPathUtil.GetFontPath("SourceHanSerifCN-Medium-6", "otf"));
FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Medium-6", font7));
Font font8 = GFGAsset.Load(ResPathUtil.GetFontPath("SourceHanSerifCN-SemiBold-7", "otf"));
FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-SemiBold-7", font8));
UIConfig.defaultFont = "FZKTJW--GB1-0";
//默认关闭点击窗口移至顶层的功能,不可打开,如哪个界面需要在界面中单独设置
UIConfig.bringWindowToFrontOnClick = false;
_viewDic = new Dictionary();
//初始化视图层容器
_bottomLayer = CreateLayer("BottomLayer");
_topLayer = CreateLayer("TopLayer");
_topLayer.sortingOrder = ConstSortingOrder.TOP;
_guideLayer = CreateLayer("GuideLayer");
_guideLayer.sortingOrder = ConstSortingOrder.Guide;
_modalLayer = CreateLayer("ModalLayer");
_modalLayer.sortingOrder = ConstSortingOrder.Modal;
_alertLayer = CreateLayer("AlertLayer");
_alertLayer.sortingOrder = ConstSortingOrder.Alert;
//debug层
_debugLayer = CreateLayer("DebugLayer");
_debugLayer.sortingOrder = ConstSortingOrder.Debug;
_floatLayer = CreateLayer("FloatLayer");
_floatLayer.sortingOrder = ConstSortingOrder.Float;
SetMaskAlpha(0.6f);
}
public static void AddChildToBottomLayer(GObject gObject)
{
_bottomLayer.AddChild(gObject);
}
public static void AddChildToTopLayer(GObject gObject)
{
_topLayer.AddChild(gObject);
}
public static void AddChildToGuideLayer(GObject gObject)
{
_guideLayer.AddChild(gObject);
}
public static void AddChildToModalLayer(GObject gObject)
{
_modalLayer.AddChild(gObject);
}
public static void AddChildToAlertLayer(GObject gObject)
{
_alertLayer.AddChild(gObject);
}
public static void AddChildToDebugLayer(GObject gObject)
{
_debugLayer.AddChild(gObject);
}
public static void AddChildToFloatLayer(GObject gObject)
{
_floatLayer.AddChild(gObject);
}
///
/// 显示一个视图
///
/// 要显示的视图名称
/// 要传递给视图的参数
/// 从该视图返回的视图信息
/// 是否关闭其他视图
public static bool Show(string fullViewName, object viewData = null, object[] goBackParams = null, bool hideOthers = false, bool resetGobackParams = false)
{
string name = GetName(fullViewName);
if (!GameGlobal.skipCheckOpen && !FunctionOpenDataManager.Instance.CheckIsFunOpenById(name))
{
return false;
}
if (hideOthers)
{
HideAllView(name);
}
IUIView obj = null;
if (_viewDic.ContainsKey(name))
{
obj = _viewDic[name];
}
else
{
obj = CreateViewInstance(fullViewName) as IUIView;
obj.viewName = name;
_viewDic.Add(name, obj);
}
if (obj != null)
{
IUIView view = (IUIView)obj;
view.viewData = viewData;
if (!view.isShowing)
{
view.Show();
}
else
{
view.Refresh();
}
if (resetGobackParams)
{
if (_goBackDatas.ContainsKey(name) == true)
{
_goBackDatas.Remove(name);
}
}
if (goBackParams != null)
{
if (!_goBackDatas.ContainsKey(name))
{
_goBackDatas.Add(name, new List