mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
升级拓展GameEvent,支持基于Interface的方法调用抛出事件,以及自动化根据声明的Interface来生成实现代码。
升级拓展GameEvent,支持基于Interface的方法调用抛出事件,以及自动化根据声明的Interface来生成实现代码。
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件接口帮助类。
|
||||
/// </summary>
|
||||
internal class EventInterfaceHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化。
|
||||
/// </summary>
|
||||
public static void Init()
|
||||
{
|
||||
RegisterEventInterface_Logic.Register(GameEvent.EventMgr);
|
||||
RegisterEventInterface_UI.Register(GameEvent.EventMgr);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9afaf331ee7249adb5cc0953dfd3413c
|
||||
timeCreated: 1702379658
|
@@ -0,0 +1,16 @@
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
[System.AttributeUsage(System.AttributeTargets.Class)]
|
||||
internal class EventInterfaceImpAttribute : BaseAttribute
|
||||
{
|
||||
private EEventGroup _eGroup;
|
||||
public EEventGroup EventGroup => _eGroup;
|
||||
|
||||
public EventInterfaceImpAttribute(EEventGroup group)
|
||||
{
|
||||
_eGroup = group;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bbf40942b0e4470bb8d8a82577f713c
|
||||
timeCreated: 1702479403
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de49bf2e9f0a4fac85851a582e2fb4ed
|
||||
timeCreated: 1702379835
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bff68b49afffbe54b9d5ff4e4cad4f23
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,70 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by autoBindTool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public partial class IActorLogicEvent_Event
|
||||
{
|
||||
public static readonly int OnMainPlayerDataChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerDataChange");
|
||||
public static readonly int OnMainPlayerLevelChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerLevelChange");
|
||||
public static readonly int OnMainPlayerGoldChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerGoldChange");
|
||||
public static readonly int OnMainPlayerDiamondChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerDiamondChange");
|
||||
public static readonly int OnMainPlayerBindDiamondChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerBindDiamondChange");
|
||||
public static readonly int OnMainPlayerCurrencyChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerCurrencyChange");
|
||||
public static readonly int OnMainPlayerExpChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerExpChange");
|
||||
}
|
||||
|
||||
[EventInterfaceImp(EEventGroup.GroupLogic)]
|
||||
public partial class IActorLogicEvent_Gen : IActorLogicEvent
|
||||
{
|
||||
private EventDispatcher _dispatcher;
|
||||
public IActorLogicEvent_Gen(EventDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public void OnMainPlayerDataChange()
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerDataChange);
|
||||
}
|
||||
|
||||
public void OnMainPlayerLevelChange()
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerLevelChange);
|
||||
}
|
||||
|
||||
public void OnMainPlayerGoldChange(System.UInt32 oldVal,System.UInt32 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerGoldChange,oldVal,newVal);
|
||||
}
|
||||
|
||||
public void OnMainPlayerDiamondChange(System.UInt32 oldVal,System.UInt32 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerDiamondChange,oldVal,newVal);
|
||||
}
|
||||
|
||||
public void OnMainPlayerBindDiamondChange(System.UInt32 oldVal,System.UInt32 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerBindDiamondChange,oldVal,newVal);
|
||||
}
|
||||
|
||||
public void OnMainPlayerCurrencyChange(GameLogic.CurrencyType type,System.UInt32 oldVal,System.UInt32 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerCurrencyChange,type,oldVal,newVal);
|
||||
}
|
||||
|
||||
public void OnMainPlayerExpChange(System.UInt64 oldVal,System.UInt64 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerExpChange,oldVal,newVal);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12d7d4edd7d06bc4286ea4af153380c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 615ca01c7a524654c91935631f39f570
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,40 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by autoBindTool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public partial class ILoginUI_Event
|
||||
{
|
||||
public static readonly int OnRoleLogin = RuntimeId.ToRuntimeId("ILoginUI_Event.OnRoleLogin");
|
||||
public static readonly int OnRoleLoginOut = RuntimeId.ToRuntimeId("ILoginUI_Event.OnRoleLoginOut");
|
||||
}
|
||||
|
||||
[EventInterfaceImp(EEventGroup.GroupUI)]
|
||||
public partial class ILoginUI_Gen : ILoginUI
|
||||
{
|
||||
private EventDispatcher _dispatcher;
|
||||
public ILoginUI_Gen(EventDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public void OnRoleLogin(System.Boolean isReconnect)
|
||||
{
|
||||
_dispatcher.Send(ILoginUI_Event.OnRoleLogin,isReconnect);
|
||||
}
|
||||
|
||||
public void OnRoleLoginOut()
|
||||
{
|
||||
_dispatcher.Send(ILoginUI_Event.OnRoleLoginOut);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bde7ed0ea10cf29448370b39ecd69a97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cf3381dedbf4daeb53e710a5c544204
|
||||
timeCreated: 1702433587
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 610229edeca4417685ffd07f18b2b9f1
|
||||
timeCreated: 1702379817
|
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 示例货币枚举。
|
||||
/// </summary>
|
||||
public enum CurrencyType
|
||||
{
|
||||
None,
|
||||
Gold,
|
||||
Diamond,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 示意逻辑层事件。
|
||||
/// <remarks> 优化抛出事件,通过接口约束事件参数。</remarks>
|
||||
/// <remarks> example: GameEvent.Get<IActorLogicEvent>().OnMainPlayerCurrencyChange(CurrencyType.Gold,oldVal,newVal); </remarks>
|
||||
/// </summary>
|
||||
[EventInterface(EEventGroup.GroupLogic)]
|
||||
interface IActorLogicEvent
|
||||
{
|
||||
void OnMainPlayerDataChange();
|
||||
|
||||
void OnMainPlayerLevelChange();
|
||||
|
||||
void OnMainPlayerGoldChange(uint oldVal, uint newVal);
|
||||
|
||||
void OnMainPlayerDiamondChange(uint oldVal, uint newVal);
|
||||
|
||||
void OnMainPlayerBindDiamondChange(uint oldVal, uint newVal);
|
||||
|
||||
void OnMainPlayerCurrencyChange(CurrencyType type, uint oldVal, uint newVal);
|
||||
|
||||
void OnMainPlayerExpChange(ulong oldVal, ulong newVal);
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d4558cb74e8462a86f0ee3461f6b7c9
|
||||
timeCreated: 1702383645
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90e13cc92c5d42f28b4f5fab599f472a
|
||||
timeCreated: 1702379805
|
@@ -0,0 +1,17 @@
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 示意UI层事件。
|
||||
/// <remarks> 优化抛出事件,通过接口约束事件参数。</remarks>
|
||||
/// <remarks> example: GameEvent.Get<ILoginUI>().OnRoleLogin(isReconnect); </remarks>
|
||||
/// </summary>
|
||||
[EventInterface(EEventGroup.GroupUI)]
|
||||
public interface ILoginUI
|
||||
{
|
||||
public void OnRoleLogin(bool isReconnect);
|
||||
|
||||
public void OnRoleLoginOut();
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33b45e62bd3447498acfe874017b9a35
|
||||
timeCreated: 1702433755
|
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 逻辑层事件接口。
|
||||
/// </summary>
|
||||
internal class RegisterEventInterface_Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册逻辑层事件接口。
|
||||
/// </summary>
|
||||
/// <param name="mgr">事件管理器。</param>
|
||||
public static void Register(EventMgr mgr)
|
||||
{
|
||||
HashSet<Type> types = CodeTypes.Instance.GetTypes(typeof(EventInterfaceImpAttribute));
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
object[] attrs = type.GetCustomAttributes(typeof(EventInterfaceImpAttribute), false);
|
||||
if (attrs.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
EventInterfaceImpAttribute httpHandlerAttribute = (EventInterfaceImpAttribute)attrs[0];
|
||||
|
||||
if (httpHandlerAttribute.EventGroup != EEventGroup.GroupLogic)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object obj = Activator.CreateInstance(type, mgr.Dispatcher);
|
||||
|
||||
mgr.RegWrapInterface(obj.GetType().GetInterfaces()[0]?.FullName, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8bdf6c139b44758aa16db2e1837f5d9
|
||||
timeCreated: 1702379518
|
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// UI层事件接口。
|
||||
/// </summary>
|
||||
internal class RegisterEventInterface_UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册UI层事件接口。
|
||||
/// </summary>
|
||||
/// <param name="mgr">事件管理器。</param>
|
||||
public static void Register(EventMgr mgr)
|
||||
{
|
||||
HashSet<Type> types = CodeTypes.Instance.GetTypes(typeof(EventInterfaceImpAttribute));
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
object[] attrs = type.GetCustomAttributes(typeof(EventInterfaceImpAttribute), false);
|
||||
if (attrs.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
EventInterfaceImpAttribute httpHandlerAttribute = (EventInterfaceImpAttribute)attrs[0];
|
||||
|
||||
if (httpHandlerAttribute.EventGroup != EEventGroup.GroupUI)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object obj = Activator.CreateInstance(type, mgr.Dispatcher);
|
||||
|
||||
mgr.RegWrapInterface(obj.GetType().GetInterfaces()[0]?.FullName, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f53b67f2cfbe4912bffee9593cd60970
|
||||
timeCreated: 1702379505
|
Reference in New Issue
Block a user