ttt
zc 2024-11-07 23:51:24 +08:00
parent 94c37c178c
commit 41574b673e
5 changed files with 75 additions and 41 deletions

View File

@ -10,7 +10,7 @@ namespace ZC
void Init();
void Open();
void Update(float dateTime);
void OnUpdate(float dateTime);
void Close();
void Pause();
void Resume();

View File

@ -22,9 +22,9 @@ namespace ZC
txt_Time = GetValue<TMP_Text>("txt_Time");
btn_Start.onClick.AddListener(OnClickBtnStart);
Global.Instance.updateTime += UpdateTime;
Global.Instance.updateScore += UpdateScore;
Global.Instance.updateProgress += UpdateProgress;
Global.updateTime += UpdateTime;
Global.updateScore += UpdateScore;
Global.updateProgress += UpdateProgress;
}
private void UpdateTime(string obj)

View File

@ -14,26 +14,36 @@ namespace ZC
}
}
public abstract class UIBase : IUI
public abstract class UIBase : MonoBehaviour, IUI
{
private bool _isPause;
private bool _isActive;
private GameObject _self;
private CanvasGroup _group;
public bool isPause => _isPause;
public bool isActive => _isActive;
public GameObject self => _self;
public GameObject self => this.gameObject;
protected GameObjectBinding _uiGameObjectBinding;
public void SetGameObject(GameObject gameObject, bool isPause = true, bool isActive = false)
#region Mono
private void Awake()
{
this._self = gameObject;
_uiGameObjectBinding = _self.GetComponent<GameObjectBinding>();
_isPause = true;
_isActive = false;
_uiGameObjectBinding = GetComponent<GameObjectBinding>();
Init();
}
private void OnDestroy()
{
Dispose();
}
#endregion
internal T GetValue<T>(string name) where T : Component
{
return _uiGameObjectBinding.GetValue<T>(name);
@ -47,17 +57,17 @@ namespace ZC
public virtual void Open()
{
_self.SetActive(true);
transform.localScale = Vector3.one;
}
public void Update(float dateTime)
public virtual void OnUpdate(float dateTime)
{
if (_isPause) return;
}
public virtual void Close()
{
_self.SetActive(false);
transform.localScale = Vector3.zero;
}
public virtual void Pause()

View File

@ -9,19 +9,19 @@ namespace ZC
{
private Stack<UIBase> _uis = new Stack<UIBase>();
private Dictionary<UIType, UIBase> _uiDic = new Dictionary<UIType, UIBase>();
private Dictionary<UIType, Type> _types = new Dictionary<UIType, Type>();
// private Dictionary<UIType, Type> _types = new Dictionary<UIType, Type>();
public TMP_FontAsset font { get; set; }
public override void OnInit()
{
base.OnInit();
var types = new List<(Type, UITypeAttribute)>();
AssemblyManager.GetTypesInhertType<UITypeAttribute>(typeof(UIBase), types);
foreach (var (type, uiTypeAttribute) in types)
{
_types.Add(uiTypeAttribute.UIType, type);
}
// var types = new List<(Type, UITypeAttribute)>();
// AssemblyManager.GetTypesInhertType<UITypeAttribute>(typeof(UIBase), types);
// foreach (var (type, uiTypeAttribute) in types)
// {
// _types.Add(uiTypeAttribute.UIType, type);
// }
}
public override void OnUpdate(float time)
@ -29,7 +29,7 @@ namespace ZC
base.OnUpdate(time);
foreach (var ui in _uis)
{
ui.Update(time);
ui.OnUpdate(time);
}
}
@ -56,18 +56,18 @@ namespace ZC
{
var gameObject = ResourcesLocalComponent.Instance.LoadUIGameObjectSync(path, uiLayer);
if (!this._types.TryGetValue(uiType, out var type))
{
throw new InvalidOperationException();
}
if (Activator.CreateInstance(type, false) is not UIBase ui)
throw new NullReferenceException();
ui.SetGameObject(gameObject);
ui.Init();
ui.Close();
_uiDic.Add(uiType, ui);
// if (!this._types.TryGetValue(uiType, out var type))
// {
// throw new InvalidOperationException();
// }
//
// if (Activator.CreateInstance(type, false) is not UIBase ui)
// throw new NullReferenceException();
// ui.SetGameObject(gameObject);
var uiBase = gameObject.GetComponent<UIBase>();
uiBase.Init();
uiBase.Close();
_uiDic.Add(uiType, uiBase);
//#if UNITY_EDITOR
// view
@ -75,7 +75,7 @@ namespace ZC
// addComponent.SetStart(ui, this.font);
//#endif
return ui;
return uiBase;
}
public IUI ShowUI(UIType uiType)
@ -133,6 +133,5 @@ namespace ZC
ui.Close();
}
}
}
}

View File

@ -8,7 +8,6 @@ namespace Unity.Loader
{
public class Global : MonoBehaviour
{
public static Global Instance;
private InitializePackage _initializePackage;
[SerializeField] EPlayMode playMode;
@ -22,13 +21,34 @@ namespace Unity.Loader
public GlobalData Data => _globalData;
// Action
public Action<string> updateTime;
public Action<string> updateScore;
public Action<string> updateProgress;
public static Action<string> updateTime;
public static Action<string> updateScore;
public static Action<string> updateProgress;
private Transform _objectPool;
private bool isDisposed;
private bool isPause;
private float gameTime;
public static Global _global;
private ObjectManager _objectManager;
private UIManager _uiManager;
private ProcedureManager _procedureManager;
private ResourcesLocalComponent _resourcesLocalComponent;
public static Transform ObjectPool => _global._objectPool;
public static float GameTime => _global.gameTime;
public static IObjectManager ObjectManager => _global._objectManager;
public static IUIManager UIManager => _global._uiManager;
public static IProcedureManager ProcedureManager => _global._procedureManager;
public static IResourcesLocalComponent ResourcesLocalComponent => _global._resourcesLocalComponent;
private void Awake()
{
Instance = this;
_global = this;
DontDestroyOnLoad(this.gameObject);
}
@ -55,7 +75,12 @@ namespace Unity.Loader
{
// yoo init finish
Debug.Log($"yoo init finish {DateTime.Now}");
zcGame = new ZCGame(this.gameObject);
this._objectPool = transform.Find("ObjectPool");
this.isDisposed = false;
this.isPause = false;
AssemblyManager.Initialize();
}
}
}