提交 8b4d081d 编写于 作者: T tanghai

UI相关重构

上级 e76a4fe0
......@@ -2,14 +2,15 @@ namespace ET
{
public static class SceneFactory
{
public static Scene CreateZoneScene(long id, int zone, string name)
public static async ETTask<Scene> CreateZoneScene(long id, int zone, string name)
{
Scene zoneScene = EntitySceneFactory.CreateScene(id, zone, SceneType.Zone, name, Game.Scene);
zoneScene.AddComponent<NetOuterComponent>();
zoneScene.AddComponent<ResourcesComponent>();
zoneScene.AddComponent<PlayerComponent>();
zoneScene.AddComponent<UnitComponent>();
await Game.EventSystem.Publish(new EventType.AfterCreateZoneScene());
return zoneScene;
}
......
......@@ -18,7 +18,7 @@ namespace ET
Game.Scene.AddComponent<MessageDispatcherComponent>();
SceneFactory.CreateZoneScene(1, 0, "Game");
Scene zoneScene = await SceneFactory.CreateZoneScene(1, 0, "Game");
}
}
}
\ No newline at end of file
using System.Collections.Generic;
namespace ET
{
public class UIComponentAwakeSystem : AwakeSystem<UIComponent>
{
public override void Awake(UIComponent self)
{
}
}
/// <summary>
/// 管理Scene上的UI
/// </summary>
public static class UIComponentSystem
{
public static async ETTask Create(this UIComponent self, string uiType)
{
UI ui = await UIEventComponent.Instance.OnCreate(self, uiType);
self.UIs.Add(uiType, ui);
}
public static void Remove(this UIComponent self, string uiType)
{
if (!self.UIs.TryGetValue(uiType, out UI ui))
{
return;
}
UIEventComponent.Instance.OnRemove(self, uiType);
self.UIs.Remove(uiType);
ui.Dispose();
}
public static UI Get(this UIComponent self, string name)
{
UI ui = null;
self.UIs.TryGetValue(name, out ui);
return ui;
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using UnityEngine;
namespace ET
{
public class UIEventComponentAwakeSystem : AwakeSystem<UIEventComponent>
{
public override void Awake(UIEventComponent self)
{
UIEventComponent.Instance = self;
var uiEvents = Game.EventSystem.GetTypes(typeof (UIEventAttribute));
foreach (Type type in uiEvents)
{
object[] attrs = type.GetCustomAttributes(typeof(UIEventAttribute), false);
if (attrs.Length == 0)
{
continue;
}
UIEventAttribute uiEventAttribute = attrs[0] as UIEventAttribute;
AUIEvent aUIEvent = Activator.CreateInstance(type) as AUIEvent;
self.UIEvents.Add(uiEventAttribute.UIType, aUIEvent);
}
}
}
/// <summary>
/// 管理所有UI GameObject 以及UI事件
/// </summary>
public static class UIEventComponentSystem
{
public static async ETTask<UI> OnCreate(this UIEventComponent self, UIComponent uiComponent, string uiType)
{
try
{
UI ui = await self.UIEvents[uiType].OnCreate(uiComponent);
return ui;
}
catch (Exception e)
{
throw new Exception($"on create ui error: {uiType}", e);
}
}
public static void OnRemove(this UIEventComponent self, UIComponent uiComponent, string uiType)
{
try
{
self.UIEvents[uiType].OnRemove(uiComponent);
}
catch (Exception e)
{
throw new Exception($"on remove ui error: {uiType}", e);
}
}
}
}
\ No newline at end of file
namespace ET
{
public class AfterCreateZoneScene_AddComponent: AEvent<EventType.AfterCreateZoneScene>
{
public override async ETTask Run(EventType.AfterCreateZoneScene args)
{
Scene zoneScene = args.ZoneScene;
zoneScene.AddComponent<ResourcesComponent>();
}
}
}
\ No newline at end of file
......@@ -2,13 +2,11 @@
namespace ET
{
[Event()]
public class LoadingBeginEvent_CreateLoadingUI : AEvent<EventType.LoadingBegin>
{
public override async ETTask Run(EventType.LoadingBegin args)
{
UI ui = UILoadingFactory.Create(args.Scene);
Game.Scene.GetComponent<UIComponent>().Add(ui);
await args.Scene.GetComponent<UIComponent>().Create(UIType.UILoading);
}
}
}
......@@ -4,7 +4,7 @@
{
public override async ETTask Run(EventType.LoadingFinish args)
{
Game.Scene.GetComponent<UIComponent>().Remove(UIType.UILoading);
args.Scene.GetComponent<UIComponent>().Remove(UIType.UILoading);
}
}
}
......@@ -3,16 +3,17 @@ using UnityEngine;
namespace ET
{
public static class UILoadingFactory
[UIEvent(UIType.UILoading)]
public class UILoadingEvent: AUIEvent
{
public static UI Create(Entity domain)
public override async ETTask<UI> OnCreate(UIComponent uiComponent)
{
try
{
GameObject bundleGameObject = ((GameObject)Resources.Load("KV")).Get<GameObject>(UIType.UILoading);
GameObject go = UnityEngine.Object.Instantiate(bundleGameObject);
go.layer = LayerMask.NameToLayer(LayerNames.UI);
UI ui = EntityFactory.Create<UI, string, GameObject>(domain, UIType.UILoading, go);
UI ui = EntityFactory.Create<UI, string, GameObject>(uiComponent.Domain, UIType.UILoading, go);
ui.AddComponent<UILoadingComponent>();
return ui;
......@@ -24,8 +25,9 @@ namespace ET
}
}
public static void Remove(string type)
{
}
public override void OnRemove(UIComponent uiComponent)
{
uiComponent.Remove(UIType.UILoading);
}
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@
public override async ETTask Run(EventType.EnterMapFinish args)
{
Game.Scene.GetComponent<UIComponent>().Remove(UIType.UILobby);
Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle(UIType.UILobby.StringToAB());
}
}
}
......@@ -6,8 +6,7 @@ namespace ET
{
public override async ETTask Run(EventType.LoginFinish args)
{
UI ui = UILobbyFactory.Create();
Game.Scene.GetComponent<UIComponent>().Add(ui);
await Game.Scene.GetComponent<UIComponent>().Create(UIType.UILobby);
}
}
}
using System;
using UnityEngine;
namespace ET
{
public static class UILobbyFactory
[UIEvent(UIType.UILobby)]
public class UILobbyEvent: AUIEvent
{
public static UI Create()
public override async ETTask<UI> OnCreate(UIComponent uiComponent)
{
try
{
......@@ -14,9 +14,9 @@ namespace ET
resourcesComponent.LoadBundle(UIType.UILobby.StringToAB());
GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(UIType.UILobby.StringToAB(), UIType.UILobby);
GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject);
UI ui = EntityFactory.Create<UI, string, GameObject>(Game.Scene, UIType.UILobby, gameObject);
ui.AddComponent<UILobbyComponent>();
UI ui = EntityFactory.Create<UI, string, GameObject>(uiComponent.Domain, UIType.UILobby, gameObject);
ui.AddComponent<UILobbyComponent>();
return ui;
}
catch (Exception e)
......@@ -25,5 +25,10 @@ namespace ET
return null;
}
}
public override void OnRemove(UIComponent uiComponent)
{
uiComponent.Remove(UIType.UILobby);
}
}
}
\ No newline at end of file
using System;
using UnityEngine;
namespace ET
{
[UIEvent(UIType.UILogin)]
public class UILoginEvent: AUIEvent
{
public override async ETTask<UI> OnCreate(UIComponent uiComponent)
{
ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
await resourcesComponent.LoadBundleAsync(UIType.UILogin.StringToAB());
GameObject bundleGameObject = (GameObject) resourcesComponent.GetAsset(UIType.UILogin.StringToAB(), UIType.UILogin);
GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject);
UI ui = EntityFactory.Create<UI, string, GameObject>(uiComponent.Domain, UIType.UILogin, gameObject);
ui.AddComponent<UILoginComponent>();
return ui;
}
public override void OnRemove(UIComponent uiComponent)
{
uiComponent.Remove(UIType.UILogin);
}
}
}
\ No newline at end of file
using System;
using UnityEngine;
namespace ET
{
public static class UILoginFactory
{
public static UI Create()
{
try
{
ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
resourcesComponent.LoadBundle(UIType.UILogin.StringToAB());
GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(UIType.UILogin.StringToAB(), UIType.UILogin);
GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject);
UI ui = EntityFactory.Create<UI, string, GameObject>(Game.Scene, UIType.UILogin, gameObject);
ui.AddComponent<UILoginComponent>();
return ui;
}
catch (Exception e)
{
Log.Error(e);
return null;
}
}
}
}
\ No newline at end of file
......@@ -13,5 +13,6 @@
// 客户端Model层
Client = 30,
Zone = 31,
Login = 32,
}
}
\ No newline at end of file
......@@ -5,6 +5,16 @@
public struct AppStart
{
}
public struct AfterCreateZoneScene
{
public Scene ZoneScene;
}
public struct AfterCreateLoginScene
{
public Scene LoginScene;
}
public struct LoginFinish
{
......@@ -17,6 +27,7 @@
public struct LoadingFinish
{
public Scene Scene;
}
public struct EnterMapFinish
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace ET
{
public abstract class ACategory : Object
public abstract class ACategory: ISupportInitialize
{
public abstract Type ConfigType { get; }
public virtual void BeginInit()
{
}
public virtual void EndInit()
{
}
}
/// <summary>
......@@ -17,7 +26,7 @@ namespace ET
{
protected Dictionary<long, T> dict;
public override void BeginInit()
public virtual void BeginInit()
{
this.dict = new Dictionary<long, T>();
......@@ -50,7 +59,7 @@ namespace ET
}
}
public override void EndInit()
public virtual void EndInit()
{
}
......
namespace ET
{
public abstract class AUIEvent
{
public abstract ETTask<UI> OnCreate(UIComponent uiComponent);
public abstract void OnRemove(UIComponent uiComponent);
}
}
\ No newline at end of file
......@@ -2,42 +2,11 @@
namespace ET
{
public class UIComponentAwakeSystem : AwakeSystem<UIComponent>
{
public override void Awake(UIComponent self)
{
}
}
/// <summary>
/// 管理所有UI
/// 管理Scene上的UI
/// </summary>
public class UIComponent: Entity
{
public Dictionary<string, UI> uis = new Dictionary<string, UI>();
public void Add(UI ui)
{
this.uis.Add(ui.Name, ui);
ui.Parent = this;
}
public void Remove(string name)
{
if (!this.uis.TryGetValue(name, out UI ui))
{
return;
}
this.uis.Remove(name);
ui.Dispose();
}
public UI Get(string name)
{
UI ui = null;
this.uis.TryGetValue(name, out ui);
return ui;
}
public Dictionary<string, UI> UIs = new Dictionary<string, UI>();
}
}
\ No newline at end of file
using System;
namespace ET
{
public class UIEventAttribute: Attribute
{
public string UIType { get; }
public UIEventAttribute(string uiType)
{
this.UIType = uiType;
}
}
}
\ No newline at end of file
......@@ -4,18 +4,13 @@ using UnityEngine;
namespace ET
{
public class UIViewComponentAwakeSystem : AwakeSystem<UIViewComponent>
{
public override void Awake(UIViewComponent self)
{
}
}
/// <summary>
/// 管理所有UI
/// 管理所有UI GameObject
/// </summary>
public class UIViewComponent: Entity
public class UIEventComponent: Entity
{
public static UIEventComponent Instance;
public Dictionary<string, AUIEvent> UIEvents = new Dictionary<string, AUIEvent>();
}
}
\ No newline at end of file
using System;
namespace ET
{
[AttributeUsage(AttributeTargets.Class)]
public class UIFactoryAttribute: BaseAttribute
{
public string Type { get; }
public UIFactoryAttribute(string type)
{
this.Type = type;
}
}
}
\ No newline at end of file
......@@ -65,6 +65,7 @@
<Compile Include="Assets\Hotfix\Move\M2C_PathfindingResultHandler.cs" />
<Compile Include="Assets\Hotfix\Scene\LoginHelper.cs" />
<Compile Include="Assets\Hotfix\Scene\MapHelper.cs" />
<Compile Include="Assets\Hotfix\Scene\SceneFactory.cs" />
<Compile Include="Assets\Hotfix\Unit\M2C_CreateUnitsHandler.cs" />
<Compile Include="Assets\Hotfix\Unit\PlayerFactory.cs" />
<Compile Include="Assets\Hotfix\Unit\UnitFactory.cs" />
......
......@@ -60,18 +60,20 @@
<ItemGroup>
<Compile Include="Assets\HotfixView\AppStart_Init.cs" />
<Compile Include="Assets\HotfixView\Module\Resource\GameObjectHelper.cs" />
<Compile Include="Assets\HotfixView\Scene\SceneFactory.cs" />
<Compile Include="Assets\HotfixView\Module\UI\UIComponentSystem.cs" />
<Compile Include="Assets\HotfixView\Module\UI\UIEventComponentSystem.cs" />
<Compile Include="Assets\HotfixView\Scene\AfterCreateZoneScene_AddComponent.cs" />
<Compile Include="Assets\HotfixView\UI\UILoading\LoadingBeginEvent_CreateLoadingUI.cs" />
<Compile Include="Assets\HotfixView\UI\UILoading\LoadingFinishEvent_RemoveLoadingUI.cs" />
<Compile Include="Assets\HotfixView\UI\UILoading\UILoadingComponentSystem.cs" />
<Compile Include="Assets\HotfixView\UI\UILoading\UILoadingFactory.cs" />
<Compile Include="Assets\HotfixView\UI\UILoading\UILoadingEvent.cs" />
<Compile Include="Assets\HotfixView\UI\UILobby\EnterMapFinish_RemoveLobbyUI.cs" />
<Compile Include="Assets\HotfixView\UI\UILobby\LoginFinish_CreateLobbyUI.cs" />
<Compile Include="Assets\HotfixView\UI\UILobby\UILobbyComponentSystem.cs" />
<Compile Include="Assets\HotfixView\UI\UILobby\UILobbyFactory.cs" />
<Compile Include="Assets\HotfixView\UI\UILobby\UILobbyEvent.cs" />
<Compile Include="Assets\HotfixView\UI\UILogin\LoginFinish_RemoveLoginUI.cs" />
<Compile Include="Assets\HotfixView\UI\UILogin\UILoginComponentSystem.cs" />
<Compile Include="Assets\HotfixView\UI\UILogin\UILoginFactory.cs" />
<Compile Include="Assets\HotfixView\UI\UILogin\UILoginEvent.cs" />
<Compile Include="Assets\HotfixView\Unit\AfterUnitCreate_CreateUnitView.cs" />
<None Include="Assets\HotfixView\Unity.HotfixView.asmdef" />
<Reference Include="UnityEditor.UI">
......
......@@ -61,13 +61,14 @@
<Compile Include="Assets\ModelView\Camera\CameraComponent.cs" />
<Compile Include="Assets\ModelView\GizmosDebug.cs" />
<Compile Include="Assets\ModelView\Init.cs" />
<Compile Include="Assets\ModelView\Module\UI\AUIEvent.cs" />
<Compile Include="Assets\ModelView\Module\UI\CanvasConfig.cs" />
<Compile Include="Assets\ModelView\Module\UI\LayerNames.cs" />
<Compile Include="Assets\ModelView\Module\UI\UI.cs" />
<Compile Include="Assets\ModelView\Module\UI\UIEventAttribute.cs" />
<Compile Include="Assets\ModelView\Module\UI\UIComponent.cs" />
<Compile Include="Assets\ModelView\Module\UI\UIFactoryAttribute.cs" />
<Compile Include="Assets\ModelView\Module\UI\UIType.cs" />
<Compile Include="Assets\ModelView\Module\UI\UIViewComponent.cs" />
<Compile Include="Assets\ModelView\Module\UI\UIEventComponent.cs" />
<Compile Include="Assets\ModelView\Opera\OperaComponent.cs" />
<Compile Include="Assets\ModelView\ReferenceCollector.cs" />
<Compile Include="Assets\ModelView\Scene\SceneChangeComponent.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册