打开窗口框架
This commit is contained in:
3
UnityGame/Assets/Scripts/GameLogic/UI/UILogic/Main.meta
Normal file
3
UnityGame/Assets/Scripts/GameLogic/UI/UILogic/Main.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2e66ce219a441108094ae188afcc745
|
||||
timeCreated: 1752663372
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CreatGame.UI
|
||||
{
|
||||
public partial class UIMainView
|
||||
{
|
||||
public override void InitView()
|
||||
{
|
||||
base.InitView();
|
||||
StarBtn.onClick.AddListener(OnStarBtnClick);
|
||||
}
|
||||
|
||||
private void OnStarBtnClick()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19a056c97ef74d2697f0bd0e7efc3651
|
||||
timeCreated: 1752663384
|
||||
@@ -1,10 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using CreatGame.AssetBundle;
|
||||
|
||||
namespace CreatGame.UI
|
||||
{
|
||||
public class UIManager : Singleton<UIManager>
|
||||
{
|
||||
private GameObject m_UIRoot;
|
||||
private Dictionary<UILayer,GameObject> m_UILayers;
|
||||
private Dictionary<UILayer, Queue<UIViewBase>> m_Windows;
|
||||
/// <summary>
|
||||
@@ -12,10 +15,33 @@ namespace CreatGame.UI
|
||||
/// </summary>
|
||||
public UIManager()
|
||||
{
|
||||
m_UILayers = new Dictionary<UILayer, GameObject>();
|
||||
m_UIRoot = GameObject.Find("UIRoot");
|
||||
InitLayer();
|
||||
m_Windows = new Dictionary<UILayer, Queue<UIViewBase>>();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化layer层的预制件
|
||||
/// </summary>
|
||||
private void InitLayer()
|
||||
{
|
||||
if (m_UIRoot == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_UILayers = new Dictionary<UILayer, GameObject>();
|
||||
|
||||
foreach (var layer in Enum.GetValues(typeof(UILayer)))
|
||||
{
|
||||
var layerObj = new GameObject(Enum.GetName(typeof(UILayer), layer));
|
||||
layerObj.transform.SetParent(m_UIRoot.transform);
|
||||
layerObj.transform.localScale = Vector3.one;
|
||||
layerObj.transform.localPosition = Vector3.zero;
|
||||
layerObj.layer = LayerMask.NameToLayer("UI");
|
||||
m_UILayers.Add((UILayer)layer,layerObj);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -26,8 +52,23 @@ namespace CreatGame.UI
|
||||
{
|
||||
var view = new T();
|
||||
//加载预制件
|
||||
|
||||
view.InitView();
|
||||
AssetBundleManager.Instance.LoadGameObject(view.PrefabPath, (obj) =>
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
Debug.LogError($"窗口加载失败{typeof(T).Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
view.PreLoad(obj);
|
||||
if (m_UILayers.TryGetValue(layer, out var uiLayer))
|
||||
{
|
||||
obj.transform.SetParent(uiLayer.transform);
|
||||
obj.transform.localPosition = Vector3.zero;
|
||||
obj.transform.localScale = Vector3.one;
|
||||
}
|
||||
view.InitView();
|
||||
});
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace CreatGame.UI
|
||||
public class UIViewBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 预制件的路径
|
||||
/// 预制件的Addressables地址
|
||||
/// 由导出代码自己添加
|
||||
/// </summary>
|
||||
public virtual string PrefabPath { get; set; }
|
||||
/// <summary>
|
||||
@@ -17,13 +18,17 @@ namespace CreatGame.UI
|
||||
/// </summary>
|
||||
protected UIExportTool m_ExportTool;
|
||||
/// <summary>
|
||||
/// 是否加载完成
|
||||
/// </summary>
|
||||
public bool IsPreLoad = false;
|
||||
/// <summary>
|
||||
/// 加载窗口的时候需要预先加载的东西
|
||||
/// </summary>
|
||||
public virtual void PreLoad(GameObject viewObject)
|
||||
{
|
||||
m_ViewObject = viewObject;
|
||||
|
||||
m_ExportTool = viewObject.GetComponent<UIExportTool>();
|
||||
IsPreLoad = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化界面
|
||||
|
||||
Reference in New Issue
Block a user