1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using FairyGUI;
- using UI.Launcher;
- using UnityEngine;
- namespace GFGGame
- {
- public class HealthAdviceView
- {
- private static HealthAdviceView m_Instance = null;
- /// <summary>
- /// 单例
- /// </summary>
- public static HealthAdviceView Instance
- {
- get
- {
- if (m_Instance == null)
- {
- m_Instance = new HealthAdviceView();
- }
- return m_Instance;
- }
- }
- private UI_HealthAdviceUI _ui;
- /// <summary>
- /// 每1%耗时,单位秒
- /// </summary>
- private const float SPEED = 0.01f;
- /// <summary>
- /// 界面是否打开状态
- /// </summary>
- private bool isOpen = false;
- /// <summary>
- /// FairyGUI包名
- /// </summary>
- private string _packageName;
- #region private
- private void Dispose()
- {
- UIPackage.RemovePackage("UI/" + _packageName);
- _ui.Dispose(true);
- _ui = null;
- }
- #endregion
- public HealthAdviceView()
- {
- _packageName = UI_HealthAdviceUI.PACKAGE_NAME;
- UIPackage.AddPackage("UI/" + _packageName + "/" + _packageName);
- _ui = UI_HealthAdviceUI.Create();
- _ui.target.MakeFullScreen();
- _ui.target.AddRelation(GRoot.inst, RelationType.Size);
- }
- /// <summary>
- /// 打开界面
- /// </summary>
- public void Open()
- {
- if (isOpen)
- {
- return;
- }
- GRoot.inst.AddChild(_ui.target);
- isOpen = true;
- }
- /// <summary>
- /// 关闭界面
- /// </summary>
- /// <param name="toDestroy"></param>
- public void Close(bool toDestroy = false)
- {
- if (!isOpen)
- {
- return;
- }
- isOpen = false;
- _ui.target.RemoveFromParent();
- if (toDestroy)
- {
- Dispose();
- }
- }
- }
- }
|