mod:优化处理方式;

目前逻辑为:
UI在面板上跟物体进行深度绑定,但是UI通过工厂进行创建;
场景物体在面板上跟物体进行深度绑定,但是场景物体通过工厂进行创建;
pull/1/head
zxl 2024-11-08 17:25:44 +08:00
parent 958d5d48aa
commit 31e77ef272
16 changed files with 206 additions and 92 deletions

View File

@ -1 +1 @@
{"ChildData":[{"Title":"大众","Type":0,"parent":null,"ChildData":[{"Title":"宝来","Type":0,"parent":null,"ChildData":[]},{"Title":"帕沙特","Type":0,"parent":null,"ChildData":[]}]},{"Title":"长安","Type":0,"parent":null,"ChildData":[{"Title":"cs35","Type":0,"parent":null,"ChildData":[]},{"Title":"cs55","Type":0,"parent":null,"ChildData":[]},{"Title":"cs75","Type":0,"parent":null,"ChildData":[]}]},{"Title":"吉利","Type":0,"parent":null,"ChildData":[{"Title":"星瑞","Type":0,"parent":null,"ChildData":[]},{"Title":"几何","Type":0,"parent":null,"ChildData":[]}]}],"name":"","hideFlags":0}
{"ChildData":[{"Title":"1.精神的撒打发打发","Type":0,"parent":null,"ChildData":[{"Title":"1.1.阿飞的方式方法","Type":0,"parent":null,"ChildData":[{"Title":"1.2.发的是凤飞飞","Type":0,"parent":null,"ChildData":[]}]}]},{"Title":"2.非官方的个人各方","Type":0,"parent":null,"ChildData":[{"Title":"2.1.丰富和提高提高电网","Type":0,"parent":null,"ChildData":[]},{"Title":"2.2.供热公司v的方法去外地","Type":0,"parent":null,"ChildData":[]},{"Title":"2.3.稳定个人观点v分","Type":0,"parent":null,"ChildData":[]},{"Title":"2.4.如果人工投入股市大幅","Type":0,"parent":null,"ChildData":[]}]},{"Title":"3.Greg突然感到十分发","Type":0,"parent":null,"ChildData":[{"Title":"3.1.而该人士对此娃娃","Type":0,"parent":null,"ChildData":[]},{"Title":"3.2.更高尚的人格力量地方","Type":0,"parent":null,"ChildData":[]},{"Title":"3.3.供电公司对方的身份","Type":0,"parent":null,"ChildData":[]},{"Title":"3.4.官方山豆根士大夫","Type":0,"parent":null,"ChildData":[]}]}]}

View File

@ -3,13 +3,14 @@ using UnityEngine;
namespace ZC
{
public class GameObjectBase<T> : MonoBehaviour, IBehaviour //, ICreateBindingGo
public class GameObjectBase<T> : MonoBehaviour, IBehaviour
{
private GameObject _go;
private long _id;
private long _id = 0;
private bool _isDisposed;
private bool _isPause;
public GameObject go => this._go;
GameObjectBinding _binding;
public GameObjectBinding binding => _binding;
public long Id => this._id;
@ -17,20 +18,19 @@ namespace ZC
public bool isPause => this._isPause;
#region mono
private void Awake()
{
_binding = gameObject.GetComponent<GameObjectBinding>();
OnInit();
}
private void OnDestroy()
public void SetID(long id)
{
OnDispose();
if (_id != 0)
throw new ArgumentException("id 不允许二次修改,一次固定的!");
_id = id;
}
#endregion
public virtual void OnInit()
{
this._isDisposed = false;
@ -54,6 +54,7 @@ namespace ZC
public virtual void OnDispose()
{
this._isDisposed = true;
DestroyImmediate(this.gameObject);
}
}
}

View File

@ -1,18 +1,43 @@
using System.Collections.Generic;
using Unity.Loader;
using UnityEngine;
namespace ZC
{
public static class GameObjectFactory
{
// public static T Create<T>(GameObject go = null) where T : GameObjectBase
// {
// var t = new T();
// var id = t.GetHashCode();
//
// t.OnInit();
// ZCGame.ObjectManager.Add(t);
// return t;
// }
private static Transform parent;
public static T CreateGameObject<T>(string path) where T : GameObjectBase<T>
{
var go = ResourcesLocalComponent.Instance.LoadGameObjectSync(path);
if (parent == null)
parent = Global.ObjectPool;
go.transform.SetParent(parent);
var objectBase = go.AddComponent<T>();
objectBase.SetID(IDGenerator.Generate());
Global.ObjectManager.Add(objectBase);
return objectBase;
}
public static void DeleteGameObject(long id)
{
Global.ObjectManager.Remove(id);
}
}
public static class UIGameObjectFactory
{
private static Transform parent;
public static T CreateUI<T>(UIType uiType, string path, UILayer uiLayer) where T : UIBase
{
return Global.UIManager.CreateUI<T>(uiType, path, uiLayer);
}
public static void DeleteUI(UIType uiType)
{
Global.UIManager.DeleteUI(uiType);
}
}
}

View File

@ -13,26 +13,31 @@ namespace ZC
private static readonly long twepoch = 1288834974657L; // Twitter Snowflake算法中的自定义起始时间
private static readonly long machineId = 1L; // 机器码,可以自定义
static object o = new object();
public static long Generate()
{
long timestamp = TimeGen();
if (lastTimestamp == timestamp)
lock (o)
{
sequence = (sequence + 1) & 4095L;
if (sequence == 0)
long timestamp = TimeGen();
if (lastTimestamp == timestamp)
{
timestamp = TilNextMillis(lastTimestamp);
sequence = (sequence + 1) & 4095L;
if (sequence == 0)
{
timestamp = TilNextMillis(lastTimestamp);
}
}
else
{
sequence = 0L;
}
}
else
{
sequence = 0L;
}
lastTimestamp = timestamp;
lastTimestamp = timestamp;
return (timestamp - twepoch) << 22 | machineId << 12 | sequence;
return (timestamp - twepoch) << 22 | machineId << 12 | sequence;
}
}
private static long TilNextMillis(long lastTimestamp)

View File

@ -5,6 +5,7 @@ namespace ZC
public interface ICreateBindingGo
{
GameObject go { get; }
GameObjectBinding binding { get; }
void SetGo(GameObject go);
}

View File

@ -6,8 +6,39 @@ namespace ZC
{
}
internal abstract class ManagerBase<T> : GameObjectBase<T>, IManager
internal abstract class ManagerBase<T> : IBehaviour, IManager
{
private long _id = IDGenerator.Generate();
private bool _isDisposed = false;
private bool _isPause = false;
public long Id => this._id;
public bool isDisposed => this._isDisposed;
public bool isPause => this._isPause;
public virtual void OnInit()
{
}
public virtual void OnUpdate(float dateTime)
{
}
public virtual void OnPause()
{
this._isPause = true;
}
public virtual void OnResume()
{
this._isPause = false;
}
public virtual void OnDispose()
{
this._isDisposed = true;
}
}
}

View File

@ -13,12 +13,11 @@ namespace ZC
{
base.OnInit();
// string filePath = $"{Application.dataPath}/DemoGame/GameRes/Config/TaskListData.json";
// var textAsset = ResourcesLocalComponent.Instance.LoadAssetSync<TextAsset>(AssetConst.Assets_DemoGame_GameRes_UIPanel_UIBattle_prefab);
// // var json = File.ReadAllText(textAsset.text);
// var datas = JsonConvert.DeserializeObject<TaskListDatas>(textAsset.text);
// _datas = datas;
// _datas.Init();
string filePath = $"{Application.dataPath}/DemoGame/GameRes/Config/TaskListData.json";
var textAsset = ResourcesLocalComponent.Instance.LoadAssetSync<TextAsset>(filePath);
var datas = JsonConvert.DeserializeObject<TaskListDatas>(textAsset.text);
_datas = datas;
_datas.Init();
}
public void SetState(string title, TaskListType type)

View File

@ -7,6 +7,8 @@ namespace ZC
[Procedure(ProcedureType.LoadingGameSceneProcedure)]
class LoadingGameSceneProcedure : ProcedureBase
{
private TestZhongLi _testZhongLi;
public override void OnEnter()
{
base.OnEnter();
@ -14,14 +16,32 @@ namespace ZC
UniTask.Create(async () =>
{
// await ResourcesLocalComponent.Instance.LoadSceneAsync(AssetConst.Assets_DemoGame_GameRes_Scene_Game_unity);
var loadAssetAsync = await ResourcesLocalComponent.Instance.LoadAssetAndInsAsync(AssetConst.Assets_DemoGame_GameRes_Entity_Cube_prefab);
Debug.Log("加载的是:" + loadAssetAsync);
// var loadAssetAsync = await ResourcesLocalComponent.Instance.LoadAssetAndInsAsync(AssetConst.Assets_DemoGame_GameRes_Entity_Cube_prefab);
// Debug.Log("加载的是:" + loadAssetAsync);
_testZhongLi = GameObjectFactory.CreateGameObject<TestZhongLi>(AssetConst
.Assets_DemoGame_GameRes_Entity_Cube_prefab);
// ZCGame.ProcedureManager.ChangeProcedure(ProcedureType.GameSceneLogicProcedure);
Global.UIManager.CreateUI(UIType.MainUI, AssetConst.Assets_DemoGame_GameRes_UIPanel_UIMain_prefab, UILayer.High);
UIGameObjectFactory.CreateUI<MainUI>(UIType.MainUI,
AssetConst.Assets_DemoGame_GameRes_UIPanel_UIMain_prefab, UILayer.High);
}).Forget();
}
public override void OnUpdate(float dateTime)
{
base.OnUpdate(dateTime);
if (Input.GetKeyDown(KeyCode.A))
{
GameObjectFactory.DeleteGameObject(_testZhongLi.Id);
}
if (Input.GetKeyDown(KeyCode.W))
{
_testZhongLi = GameObjectFactory.CreateGameObject<TestZhongLi>(AssetConst
.Assets_DemoGame_GameRes_Entity_Cube_prefab);
}
}
public override void OnLeave()
{
base.OnLeave();

View File

@ -19,6 +19,7 @@ namespace ZC
{
private Dictionary<ProcedureType, IProcedure> _procedures = new Dictionary<ProcedureType, IProcedure>();
private IProcedure currentProcedure;
public ProcedureType CurrentProcedureType => currentProcedure.procedureType;
public override void OnInit()
{
@ -31,7 +32,7 @@ namespace ZC
var procedureType = procedureAttribute.ProcedureType;
_procedures.Add(procedureType, (IProcedure)Activator.CreateInstance(type, false));
}
foreach (var procedureBase in _procedures.Values)
{
procedureBase.Init();
@ -94,6 +95,5 @@ namespace ZC
return null;
}
}
}

View File

@ -29,7 +29,8 @@ namespace ZC
{
if (instance == null)
{
instance = new ResourcesLocalComponent();
throw new NullReferenceException();
// instance = new ResourcesLocalComponent();
}
return instance;
@ -45,6 +46,8 @@ namespace ZC
public ResourcesLocalComponent()
{
instance = this;
resourcePackage = YooAssets.GetPackage("DefaultPackage");
var transform = Global.Self.transform;
@ -132,7 +135,8 @@ namespace ZC
return loadAssetAsync.AssetObject;
}
public async UniTask<GameObject> LoadAssetAndInsAsync(string location, Transform parent = null, uint priority = 0)
public async UniTask<GameObject> LoadAssetAndInsAsync(string location, Transform parent = null,
uint priority = 0)
{
var loadAssetAsync = YooAssets.LoadAssetAsync(location, priority);
while (!loadAssetAsync.IsDone)
@ -146,7 +150,8 @@ namespace ZC
return instantiateOperation.Result;
}
public async UniTask LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100U, Action<float> callback = null)
public async UniTask LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single,
bool suspendLoad = false, uint priority = 100U, Action<float> callback = null)
{
var loadAssetAsync = YooAssets.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
while (!loadAssetAsync.IsDone)

View File

@ -12,19 +12,20 @@ namespace ZC
public void Update()
{
if (SystemInfo.supportsGyroscope)
{
var gyro = Input.gyro;
gyro.enabled = true;
Debug.Log($"{gyro.rotationRate} , {gyro.attitude}");
// Camera.main.transform.Rotate(gyro.rotationRate);
Camera.main.transform.rotation = gyro.attitude;
Debug.Log($"raw: {Input.compass.rawVector}");
}
else
{
// Debug.Log("没找到?");
}
transform.Rotate(Vector3.up);
// if (SystemInfo.supportsGyroscope)
// {
// var gyro = Input.gyro;
// gyro.enabled = true;
// Debug.Log($"{gyro.rotationRate} , {gyro.attitude}");
// // Camera.main.transform.Rotate(gyro.rotationRate);
// Camera.main.transform.rotation = gyro.attitude;
// Debug.Log($"raw: {Input.compass.rawVector}");
// }
// else
// {
// // Debug.Log("没找到?");
// }
}
}
}

View File

@ -7,7 +7,8 @@ namespace ZC
public interface IUIManager
{
TMP_FontAsset font { get; set; }
IUI CreateUI(UIType uiType, string path, UILayer uiLayer);
T CreateUI<T>(UIType uiType, string path, UILayer uiLayer) where T : UIBase;
void DeleteUI(UIType uiType);
IUI ShowUI(UIType uiType);

View File

@ -16,8 +16,8 @@ namespace ZC
public abstract class UIBase : MonoBehaviour, IUI
{
private bool _isPause;
private bool _isActive;
private bool _isPause = true;
private bool _isActive = false;
private CanvasGroup _group;
public bool isPause => _isPause;
@ -31,15 +31,11 @@ namespace ZC
private void Awake()
{
_isPause = true;
_isActive = false;
_uiGameObjectBinding = GetComponent<GameObjectBinding>();
Init();
}
private void OnDestroy()
{
Dispose();
}
#endregion
@ -86,6 +82,7 @@ namespace ZC
{
_isActive = false;
_isPause = true;
DestroyImmediate(this.gameObject);
}
}
}

View File

@ -52,32 +52,28 @@ namespace ZC
}
public IUI CreateUI(UIType uiType, string path, UILayer uiLayer)
public T CreateUI<T>(UIType uiType, string path, UILayer uiLayer) where T : UIBase
{
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);
var uiBase = gameObject.GetComponent<UIBase>();
var uiBase = gameObject.AddComponent<T>();
uiBase.Init();
uiBase.Close();
_uiDic.Add(uiType, uiBase);
//#if UNITY_EDITOR
// view
// var addComponent = gameObject.GetComponent<UIInfo>();
// addComponent.SetStart(ui, this.font);
//#endif
return uiBase;
}
public void DeleteUI(UIType uiType)
{
if (_uiDic.TryGetValue(uiType, out var ui))
{
ui.Dispose();
}
else
{
throw new NullReferenceException();
}
}
public IUI ShowUI(UIType uiType)
{
if (_uiDic.TryGetValue(uiType, out var ui))

View File

@ -8,6 +8,8 @@ namespace Unity.Loader
{
public class Global : MonoBehaviour
{
private static Global _global;
private InitializePackage _initializePackage;
[SerializeField] EPlayMode playMode;
@ -26,12 +28,13 @@ namespace Unity.Loader
private Transform _objectPool;
private bool isDisposed;
private bool isPause;
private bool _isInitFinish;
private float gameTime;
public static Global _global;
private UIManager _uiManager;
private ProcedureManager _procedureManager;
private ObjectManager _objectManager;
private ResourcesLocalComponent _resourcesLocalComponent;
public static Transform Self => _global.transform;
@ -39,8 +42,13 @@ namespace Unity.Loader
public static float GameTime => _global.gameTime;
public static IUIManager UIManager => _global._uiManager;
public static IProcedureManager ProcedureManager => _global._procedureManager;
public static IObjectManager ObjectManager => _global._objectManager;
public static IResourcesLocalComponent ResourcesLocalComponent => _global._resourcesLocalComponent;
#region 可视化
#endregion
#region mono
@ -57,11 +65,14 @@ namespace Unity.Loader
private void Update()
{
if (this.isPause) return;
if (!_isInitFinish || this.isPause) return;
this.gameTime += Time.fixedTime;
updateTime?.Invoke(_globalData.runTimeStr);
// Debug.Log($"{_globalData.runTimeStr}");
_procedureManager.OnUpdate(gameTime);
// _uiManager.OnUpdate(gameTime);
// _objectManager.OnUpdate(gameTime);
}
private void OnDestroy()
@ -70,6 +81,7 @@ namespace Unity.Loader
_globalData.Dispose();
_procedureManager.OnDispose();
_uiManager.OnDispose();
_objectManager.OnDispose();
_resourcesLocalComponent.Dispose();
Debug.Log("关闭应用了");
@ -89,13 +101,16 @@ namespace Unity.Loader
AssemblyManager.Initialize();
this._resourcesLocalComponent = new ResourcesLocalComponent();
this._objectManager = new ObjectManager();
this._uiManager = new UIManager();
this._procedureManager = new ProcedureManager();
this._resourcesLocalComponent = new ResourcesLocalComponent();
_objectManager.OnInit();
_uiManager.OnInit();
_procedureManager.OnInit();
_isInitFinish = true;
this._procedureManager.ChangeProcedure(ProcedureType.LoadingGameSceneProcedure);
}
}

View File

@ -38,6 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@ -3264,10 +3265,22 @@ PrefabInstance:
propertyPath: m_Name
value: IngameDebugConsole
objectReference: {fileID: 0}
- target: {fileID: 11414302, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_Value
value: 1
objectReference: {fileID: 0}
- target: {fileID: 11452418, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: startMinimized
value: 1
objectReference: {fileID: 0}
- target: {fileID: 11490438, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_BlockingMask.m_Bits
value: 55
objectReference: {fileID: 0}
- target: {fileID: 22400762, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchoredPosition.y
value: -0.000061035156
objectReference: {fileID: 0}
- target: {fileID: 22426080, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchorMax.x
value: 0
@ -3276,6 +3289,10 @@ PrefabInstance:
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22426080, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22428984, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchorMax.y
value: 0