FairyGui

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FairyGui相关的知识,希望对你有一定的参考价值。

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using FairyGUI;
 
public class UIPackageManager : BaseManager<uipackagemanager>
{
 
    //记录包是否Add的字典
    private Dictionary<string, bool=""> packageAddDict = new Dictionary<string, bool="">();
 
    /// <summary>
    /// 将一个UI包add进来
    /// </summary>
    ///<param name="packageName">UI包名
    public void AddPackage(string packageName)
    {
        if (CheckPackageHaveAdd(packageName) == false)
        {
            UIPackage.AddPackage("UI/"+packageName);
        }
    }
 
    /// <summary>
    /// 检查UI包是否已经包进来
    /// </summary>
    ///<param name="packageName">UI包名
    public bool CheckPackageHaveAdd(string packageName)
    {
        return packageAddDict.ContainsKey(packageName);
    }
 
    /// <summary>
    /// 清理没有用到的UI包
    /// </summary>
    public void ClearNotUsePackage()
    {
        //*****************************
    }
}</string,></string,></uipackagemanager>
 
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using FairyGUI;
 
public class DialogManager : BaseManager<dialogmanager>
{
 
    Dictionary<dialogtype, basedialog=""> dialogDict = new Dictionary<dialogtype, basedialog="">();
    /// <summary>
    /// 打开界面
    /// </summary>
    public void OpenDialog(DialogType dialogType)
    {
        DialogInfo dialogInfo = DialogConfigManager.GetInstance().GetDialogInfo(dialogType);
        UIPackageManager.GetInstance().AddPackage(dialogInfo.GetPackName());
        GComponent view = UIPackage.CreateObject(dialogInfo.GetPackName(), dialogInfo.GetDialogName()) as GComponent;
        view.SetSize(GRoot.inst.width, GRoot.inst.height);
        GRoot.inst.AddChild(view);
        dialogDict[dialogType] = DialogConfigManager.GetInstance().GetDialogControl(dialogType);
        dialogDict[dialogType].SetDialogView(view);
        dialogDict[dialogType].OnBeforeCreate();
        dialogDict[dialogType].AddListener();
        dialogDict[dialogType].OnCreate();
        dialogDict[dialogType].OnRefresh();
    }
 
    /// <summary>
    /// 关闭界面
    /// </summary>
    public void CloseDialog(DialogType dialogType)
    {
        if (dialogDict.ContainsKey(dialogType))
        {
            dialogDict[dialogType].RemoveListener();
            dialogDict[dialogType].OnHide();
            dialogDict[dialogType].OnDestory();
            dialogDict[dialogType].GetView().Dispose();
            dialogDict.Remove(dialogType);
        }
    }
 
}
</dialogtype,></dialogtype,></dialogmanager>
 
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using FairyGUI;
 
public class DialogConfigManager : BaseManager<dialogconfigmanager>
{
 
    public Dictionary<dialogtype, dialoginfo=""> dialogDict;
 
    public DialogConfigManager()
    {
        InitDialogConfig();
    }
 
    public void InitDialogConfig()
    {
        dialogDict = new Dictionary<dialogtype, dialoginfo="">();
        dialogDict[DialogType.Main] = new DialogInfo("MainUI", "Win_Main");
        dialogDict[DialogType.Farm] = new DialogInfo("FarmUI", "Win_Farm");
    }
 
    public DialogInfo GetDialogInfo(DialogType dialogType)
    {
        return dialogDict[dialogType];
    }
 
    public BaseDialog GetDialogControl(DialogType dialogType)
    {
        switch (dialogType)
        {
            case DialogType.Main:
                return new MainUIDialog();
            case DialogType.Farm:
                return new FramUIDialog();
            default:
                return null;
        }
 
    }
}
 
 
public class DialogInfo {
 
    private string _packName;
    private string _dialogName;
 
    public DialogInfo(string packName, string dialogName)
    {
        _packName = packName;
        _dialogName = dialogName;
    }
 
    public string GetPackName()
    {
        return _packName;
    }
 
    public string GetDialogName()
    {
        return _dialogName;
    }
 
}</dialogtype,></dialogtype,></dialogconfigmanager>
 
using UnityEngine;
using System.Collections;
using FairyGUI;
 
public class BaseDialog {
 
    private GComponent _view;
    private DialogType _dialogType;
 
    public BaseDialog()
    {
 
    }
 
    public void SetDialogView(GComponent view)
    {
        _view = view;
    }
 
    public void SetDialogType(DialogType dialogType)
    {
        _dialogType = dialogType;
    }
 
    public GComponent GetView()
    {
        return _view;
    }
 
    /// <summary>
    /// 创建前期 主要用于寻找view上的组件
    /// </summary>
    public virtual void OnBeforeCreate()
    {
 
    }
 
    /// <summary>
    /// 添加监听事件
    /// </summary>
    public virtual void AddListener()
    {
 
    }
 
    /// <summary>
    /// 删除添加事件
    /// </summary>
    public virtual void RemoveListener()
    {
 
    }
 
    /// <summary>
    /// 创建成功 主要用于逻辑注册
    /// </summary>
    public virtual void OnCreate()
    {
 
    }
 
    /// <summary>
    /// 用于缓存界面后的第二次以上打开
    /// </summary>
    public virtual void OnRefresh()
    {
 
    }
 
    /// <summary>
    /// 界面隐藏
    /// </summary>
    public virtual void OnHide()
    {
 
    }
 
    /// <summary>
    /// 界面销毁
    /// </summary>
    public virtual void OnDestory()
    {
 
    }
 
    public void Update()
    {
 
    }
}

以上是关于FairyGui的主要内容,如果未能解决你的问题,请参考以下文章

UnityUI界面的热更新技术 FairyGUI的使用流程

UnityUI界面的热更新技术 FairyGUI的使用流程

Cocos2dLua3.17.2集成FairyGUI

Cocos2dLua3.17.2集成FairyGUI之 lua绑定 getGroup() 调用问题

xlua整合fairyGui

FairyGUI学习