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 afont = GFGAsset.Load(ResPathUtil.GetFontPath("ALIBABAPUHUITI-2-55-REGULAR"));
FontManager.RegisterFont(new DynamicFont("ALIBABAPUHUITI-2-55-REGULAR", afont));
UIConfig.defaultFont = "ALIBABAPUHUITI-2-55-REGULAR";
Font afont1 = GFGAsset.Load(ResPathUtil.GetFontPath("ZIHUN125"));
FontManager.RegisterFont(new DynamicFont("ZIHUN125", afont1));
Font afont2 = GFGAsset.Load(ResPathUtil.GetFontPath("SIMKAI"));
FontManager.RegisterFont(new DynamicFont("SIMKAI", afont2));
Font afont3 = GFGAsset.Load(ResPathUtil.GetFontPath("SHUANGYUJUTI"));
FontManager.RegisterFont(new DynamicFont("SHUANGYUJUTI", afont3));
Font afont4 = GFGAsset.Load(ResPathUtil.GetFontPath("YUNJINSONG"));
FontManager.RegisterFont(new DynamicFont("YUNJINSONG", afont4));
Font afont5 = GFGAsset.Load(ResPathUtil.GetFontPath("NANSONG"));
FontManager.RegisterFont(new DynamicFont("NANSONG", afont5));
Font afont6 = GFGAsset.Load(ResPathUtil.GetFontPath("FANGZHENGYANSONG"));
FontManager.RegisterFont(new DynamicFont("FANGZHENGYANSONG", afont6));
_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);
}
///
/// ��ʾһ����ͼ
///
/// Ҫ��ʾ����ͼ����
/// Ҫ���ݸ���ͼ�IJ���
/// �Ӹ���ͼ���ص���ͼ��Ϣ
/// �Ƿ�ر�������ͼ
public static bool Show(string viewName, object viewData = null, object[] goBackParams = null, bool hideOthers = false, bool resetGobackParams = false)
{
string name = GetName(viewName);
if (!GameGlobal.skipCheckOpen && !FunctionOpenDataManager.Instance.CheckIsFunOpenById(name))
{
return false;
}
if (hideOthers)
{
HideAllView(name);
}
UIView obj = null;
if (_viewDic.ContainsKey(name))
{
obj = _viewDic[name];
}
else
{
obj = CreateViewInstance(viewName) as UIView;
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