├── Example
├── ProjectSettings
│ ├── ProjectVersion.txt
│ ├── ClusterInputManager.asset
│ ├── NetworkManager.asset
│ ├── TimeManager.asset
│ ├── EditorBuildSettings.asset
│ ├── PresetManager.asset
│ ├── AudioManager.asset
│ ├── TagManager.asset
│ ├── EditorSettings.asset
│ ├── UnityConnectSettings.asset
│ ├── DynamicsManager.asset
│ ├── Physics2DSettings.asset
│ └── NavMeshAreas.asset
├── Assets
│ ├── Plugins
│ │ └── ETClient.dll
│ └── Example
│ │ ├── Scripts
│ │ └── Handlers
│ │ │ ├── Actor_TestHandler.cs
│ │ │ ├── TestHotfixSubscribMonoEvent_LogString.cs
│ │ │ └── Frame_ClickMapHandler.cs
│ │ └── Readme.txt
├── Example.sln
└── ETClient.sln
├── Source
├── Base
│ ├── Object
│ │ ├── ISerializeToEntity.cs
│ │ ├── ObjectSystemAttribute.cs
│ │ ├── BaseAttribute.cs
│ │ ├── EntityEventAttribute.cs
│ │ ├── Object.cs
│ │ ├── IComponentSerialize.cs
│ │ ├── ILoadSystem.cs
│ │ ├── IStartSystem.cs
│ │ ├── IChangeSystem.cs
│ │ ├── IUpdateSystem.cs
│ │ ├── IDestroySystem.cs
│ │ ├── ILateUpdateSystem.cs
│ │ ├── ComponentWithId.cs
│ │ ├── EventProxy.cs
│ │ ├── ObjectPool.cs
│ │ ├── IAwakeSystem.cs
│ │ └── Component.cs
│ ├── Math
│ │ ├── VLine.cs
│ │ └── VInt.cs
│ ├── LogType.cs
│ ├── Event
│ │ ├── EnvKey.cs
│ │ ├── EventAttribute.cs
│ │ ├── EventIdType.cs
│ │ └── Env.cs
│ ├── Helper
│ │ ├── ObjectHelper.cs
│ │ ├── IdGenerater.cs
│ │ ├── MD5Helper.cs
│ │ ├── NetHelper.cs
│ │ ├── MethodInfoHelper.cs
│ │ ├── EnumHelper.cs
│ │ ├── TimeHelper.cs
│ │ ├── RandomHelper.cs
│ │ ├── JsonHelper.cs
│ │ ├── StringHelper.cs
│ │ └── FileHelper.cs
│ ├── TryLocker.cs
│ ├── Log.cs
│ ├── OneThreadSynchronizationContext.cs
│ └── QueueDictionary.cs
├── ThirdParty
│ ├── Lib
│ │ ├── UnityEngine.dll
│ │ ├── UnityEngine.UI.dll
│ │ ├── UnityEngine.CoreModule.dll
│ │ ├── UnityEngine.AnimationModule.dll
│ │ ├── UnityEngine.UnityWebRequestModule.dll
│ │ ├── UnityEngine.UnityWebRequestWWWModule.dll
│ │ └── UnityEngine.xml
│ ├── LitJson
│ │ ├── JsonWriter.cs
│ │ ├── ParserToken.cs
│ │ ├── IJsonWrapper.cs
│ │ └── JsonException.cs
│ └── MongoDB
│ │ ├── MongoDB.Bson
│ │ ├── Serialization
│ │ │ ├── ICreatorSelector.cs
│ │ │ ├── Conventions
│ │ │ │ ├── IConvention.cs
│ │ │ │ ├── IConventionPack.cs
│ │ │ │ ├── IClassMapConvention.cs
│ │ │ │ ├── IMemberMapConvention.cs
│ │ │ │ ├── ICreatorMapConvention.cs
│ │ │ │ ├── IPostProcessingConvention.cs
│ │ │ │ ├── ResetClassMapConvention.cs
│ │ │ │ ├── ResetMemberMapsConvention.cs
│ │ │ │ ├── MemberNameElementNameConvention.cs
│ │ │ │ ├── NoIdMemberConvention.cs
│ │ │ │ ├── IgnoreIfNullConvention.cs
│ │ │ │ ├── IgnoreIfDefaultConvention.cs
│ │ │ │ ├── LookupIdGeneratorConvention.cs
│ │ │ │ ├── IgnoreExtraElementsConvention.cs
│ │ │ │ ├── IDiscriminatorConvention.cs
│ │ │ │ ├── DelegateClassMapConvention.cs
│ │ │ │ ├── DelegateMemberMapConvention.cs
│ │ │ │ ├── CamelCaseElementNameConvention.cs
│ │ │ │ ├── DelegatePostProcessingConvention.cs
│ │ │ │ ├── StringObjectIdIdGeneratorConvention.cs
│ │ │ │ └── MemberDefaultValueConvention.cs
│ │ │ ├── Attributes
│ │ │ │ ├── BsonIgnoreAttribute.cs
│ │ │ │ ├── IBsonClassMapAttribute.cs
│ │ │ │ ├── IBsonMemberMapAttribute.cs
│ │ │ │ ├── IBsonCreatorMapAttribute.cs
│ │ │ │ ├── IBsonPostProcessingAttribute.cs
│ │ │ │ ├── BsonRequiredAttribute.cs
│ │ │ │ ├── BsonNoIdAttribute.cs
│ │ │ │ ├── BsonExtraElementsAttribute.cs
│ │ │ │ └── BsonMemberMapAttributeUsageAttribute.cs
│ │ │ ├── Serializers
│ │ │ │ ├── StructSerializerBase.cs
│ │ │ │ └── AbstractClassSerializer.cs
│ │ │ ├── IBsonPolymorphicSerializer.cs
│ │ │ ├── IBsonArraySerializer.cs
│ │ │ ├── Options
│ │ │ │ ├── DictionaryRepresentation.cs
│ │ │ │ └── TimeSpanUnits.cs
│ │ │ ├── IBsonDocumentSerializer.cs
│ │ │ ├── IBsonSerializerRegistry.cs
│ │ │ ├── IIdGenerator.cs
│ │ │ ├── BsonDeserializationArgs.cs
│ │ │ ├── IBsonDictionarySerializer.cs
│ │ │ ├── IBsonIdProvider.cs
│ │ │ ├── IChildSerializerConfigurable.cs
│ │ │ ├── DiscriminatedInterfaceSerializationProvider.cs
│ │ │ └── IBsonSerializationProvider.cs
│ │ ├── ObjectModel
│ │ │ ├── IConvertibleToBsonDocument.cs
│ │ │ ├── ICustomBsonTypeMapper.cs
│ │ │ ├── BsonBinarySubType.cs
│ │ │ ├── GuidRepresentation.cs
│ │ │ └── BsonSymbolTable.cs
│ │ ├── IO
│ │ │ ├── IBsonChunkSource.cs
│ │ │ ├── IBsonChunk.cs
│ │ │ ├── ContextType.cs
│ │ │ ├── INameDecoder.cs
│ │ │ ├── JsonOutputMode.cs
│ │ │ ├── Utf8Encodings.cs
│ │ │ ├── BsonWriterState.cs
│ │ │ ├── IElementNameValidator.cs
│ │ │ ├── BsonBinaryReaderBookmark.cs
│ │ │ ├── BsonDocumentReaderBookmark.cs
│ │ │ ├── JsonReaderContext.cs
│ │ │ ├── JsonWriterContext.cs
│ │ │ ├── BsonBinaryWriterContext.cs
│ │ │ └── BsonReaderState.cs
│ │ └── PowerOf2.cs
│ │ └── MongoDB.Shared
│ │ └── ApplicationNameHelper.cs
├── Other
│ ├── MotionType.cs
│ ├── IInstanceMethod.cs
│ ├── Define.cs
│ └── AppType.cs
├── Module
│ ├── Numeric
│ │ ├── INumericWatcher.cs
│ │ ├── NumericWatcher_Hp_ShowUI.cs
│ │ ├── NumericWatcherAttribute.cs
│ │ ├── NumericChangeEvent_NotifyWatcher.cs
│ │ ├── NumericType.cs
│ │ └── NumericWatcherComponent.cs
│ ├── UI
│ │ ├── CanvasConfig.cs
│ │ ├── IUIFactory.cs
│ │ ├── UIType.cs
│ │ ├── UIFactoryAttribute.cs
│ │ ├── LayerNames.cs
│ │ └── UI.cs
│ ├── Message
│ │ ├── IMessageDispatcher.cs
│ │ ├── NetOuterComponent.cs
│ │ ├── IMHandler.cs
│ │ ├── Opcode.cs
│ │ ├── MessageAttribute.cs
│ │ ├── MessageInfo.cs
│ │ ├── MessageHandlerAttribute.cs
│ │ ├── SessionCallbackComponent.cs
│ │ ├── IMessagePacker.cs
│ │ ├── RpcException.cs
│ │ ├── MessageProxy.cs
│ │ ├── Network
│ │ │ ├── NetworkHelper.cs
│ │ │ ├── AService.cs
│ │ │ └── AChannel.cs
│ │ ├── OpcodeHelper.cs
│ │ ├── OuterMessageDispatcher.cs
│ │ ├── AMHandler.cs
│ │ ├── IMessage.cs
│ │ ├── ProtobufPacker.cs
│ │ ├── NetOuterComponentSystem.cs
│ │ ├── MessagePool.cs
│ │ ├── HotfixOpcode.cs
│ │ └── ErrorCode.cs
│ ├── FrameSync
│ │ ├── Player.cs
│ │ ├── PlayerFactory.cs
│ │ ├── FrameOpcode.cs
│ │ ├── SessionComponent.cs
│ │ ├── Unit.cs
│ │ ├── CameraComponent.cs
│ │ ├── PlayerComponent.cs
│ │ └── UnitComponent.cs
│ ├── ActorLocation
│ │ └── IActorLocationMessage.cs
│ ├── Filter
│ │ ├── FilterAttribute.cs
│ │ ├── IFilter.cs
│ │ └── FilterEntity.cs
│ └── Actor
│ │ └── IActorMessage.cs
├── Helper
│ ├── ActionHelper.cs
│ ├── ResourcesHelper.cs
│ ├── GameObjectHelper.cs
│ └── PathHelper.cs
├── Entity
│ ├── Scene.cs
│ ├── Game.cs
│ └── UnityWebRequestAsync.cs
├── Properties
│ └── AssemblyInfo.cs
└── Component
│ └── SceneChangeComponent.cs
└── README.md
/Example/ProjectSettings/ProjectVersion.txt:
--------------------------------------------------------------------------------
1 | m_EditorVersion: 2018.1.0f2
2 |
--------------------------------------------------------------------------------
/Example/Assets/Plugins/ETClient.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SecodeCN/ETClient/HEAD/Example/Assets/Plugins/ETClient.dll
--------------------------------------------------------------------------------
/Source/Base/Object/ISerializeToEntity.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public interface ISerializeToEntity
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/Source/ThirdParty/Lib/UnityEngine.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SecodeCN/ETClient/HEAD/Source/ThirdParty/Lib/UnityEngine.dll
--------------------------------------------------------------------------------
/Source/Other/MotionType.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public enum MotionType
4 | {
5 | None,
6 | Idle,
7 | Run,
8 | }
9 | }
--------------------------------------------------------------------------------
/Source/ThirdParty/Lib/UnityEngine.UI.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SecodeCN/ETClient/HEAD/Source/ThirdParty/Lib/UnityEngine.UI.dll
--------------------------------------------------------------------------------
/Source/ThirdParty/LitJson/JsonWriter.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SecodeCN/ETClient/HEAD/Source/ThirdParty/LitJson/JsonWriter.cs
--------------------------------------------------------------------------------
/Source/Base/Math/VLine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | public struct VLine
4 | {
5 | public VInt2 point;
6 |
7 | public VInt2 direction;
8 | }
9 |
--------------------------------------------------------------------------------
/Source/ThirdParty/Lib/UnityEngine.CoreModule.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SecodeCN/ETClient/HEAD/Source/ThirdParty/Lib/UnityEngine.CoreModule.dll
--------------------------------------------------------------------------------
/Source/Base/LogType.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public enum LogType
4 | {
5 | Warning,
6 | Info,
7 | Debug,
8 | Error,
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Source/Module/Numeric/INumericWatcher.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public interface INumericWatcher
4 | {
5 | void Run(long id, int value);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Source/ThirdParty/Lib/UnityEngine.AnimationModule.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SecodeCN/ETClient/HEAD/Source/ThirdParty/Lib/UnityEngine.AnimationModule.dll
--------------------------------------------------------------------------------
/Source/ThirdParty/Lib/UnityEngine.UnityWebRequestModule.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SecodeCN/ETClient/HEAD/Source/ThirdParty/Lib/UnityEngine.UnityWebRequestModule.dll
--------------------------------------------------------------------------------
/Source/ThirdParty/Lib/UnityEngine.UnityWebRequestWWWModule.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SecodeCN/ETClient/HEAD/Source/ThirdParty/Lib/UnityEngine.UnityWebRequestWWWModule.dll
--------------------------------------------------------------------------------
/Source/Base/Event/EnvKey.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | ///
4 | /// 一般使用事件名+变量名
5 | ///
6 | public enum EnvKey
7 | {
8 | ChannelError
9 | }
10 | }
--------------------------------------------------------------------------------
/Example/ProjectSettings/ClusterInputManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!236 &1
4 | ClusterInputManager:
5 | m_ObjectHideFlags: 0
6 | m_Inputs: []
7 |
--------------------------------------------------------------------------------
/Source/Module/UI/CanvasConfig.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace ETModel
4 | {
5 | public class CanvasConfig: MonoBehaviour
6 | {
7 | public string CanvasName;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Source/Module/Message/IMessageDispatcher.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public interface IMessageDispatcher
4 | {
5 | void Dispatch(Session session, ushort opcode, object message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Source/Module/Message/NetOuterComponent.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public class NetOuterComponent : NetworkComponent
4 | {
5 | public NetworkProtocol Protocol = NetworkProtocol.TCP;
6 | }
7 | }
--------------------------------------------------------------------------------
/Source/Module/Message/IMHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public interface IMHandler
6 | {
7 | void Handle(Session session, object message);
8 | Type GetMessageType();
9 | }
10 | }
--------------------------------------------------------------------------------
/Example/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!149 &1
4 | NetworkManager:
5 | m_ObjectHideFlags: 0
6 | m_DebugLevel: 0
7 | m_Sendrate: 15
8 | m_AssetToPrefab: {}
9 |
--------------------------------------------------------------------------------
/Source/ThirdParty/Lib/UnityEngine.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | UnityEngine
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/Base/Object/ObjectSystemAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
6 | public class ObjectSystemAttribute: BaseAttribute
7 | {
8 | }
9 | }
--------------------------------------------------------------------------------
/Source/Module/UI/IUIFactory.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace ETModel
4 | {
5 | public interface IUIFactory
6 | {
7 | UI Create(Scene scene, string type, GameObject parent);
8 | void Remove(string type);
9 | }
10 | }
--------------------------------------------------------------------------------
/Source/Base/Helper/ObjectHelper.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public static class ObjectHelper
4 | {
5 | public static void Swap(ref T t1, ref T t2)
6 | {
7 | T t3 = t1;
8 | t1 = t2;
9 | t2 = t3;
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Source/Module/Message/Opcode.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public static partial class Opcode
4 | {
5 | public const ushort ActorResponse = 1;
6 | public const ushort FrameMessage = 2;
7 | public const ushort OneFrameMessage = 3;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Source/Module/UI/UIType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace ETModel
5 | {
6 | public static class UIType
7 | {
8 | public const string Root = "Root";
9 | public const string UILoading = "UILoading";
10 | }
11 | }
--------------------------------------------------------------------------------
/Example/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!5 &1
4 | TimeManager:
5 | m_ObjectHideFlags: 0
6 | Fixed Timestep: 0.0167
7 | Maximum Allowed Timestep: 0.1
8 | m_TimeScale: 1
9 | Maximum Particle Timestep: 0.03
10 |
--------------------------------------------------------------------------------
/Source/Module/Message/MessageAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public class MessageAttribute: BaseAttribute
6 | {
7 | public ushort Opcode { get; }
8 |
9 | public MessageAttribute(ushort opcode)
10 | {
11 | this.Opcode = opcode;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/Example/Assets/Example/Scripts/Handlers/Actor_TestHandler.cs:
--------------------------------------------------------------------------------
1 | using ETModel;
2 |
3 | [MessageHandler]
4 | public class Actor_TestHandler : AMHandler
5 | {
6 | protected override void Run(ETModel.Session session, Actor_Test message)
7 | {
8 | Log.Debug(message.Info);
9 | }
10 | }
--------------------------------------------------------------------------------
/Source/Module/FrameSync/Player.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public sealed class Player : Entity
4 | {
5 | public long UnitId { get; set; }
6 |
7 | public override void Dispose()
8 | {
9 | if (this.IsDisposed)
10 | {
11 | return;
12 | }
13 |
14 | base.Dispose();
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Source/Module/ActorLocation/IActorLocationMessage.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public interface IActorLocationMessage : IActorRequest
4 | {
5 | }
6 |
7 | public interface IActorLocationRequest : IActorRequest
8 | {
9 | }
10 |
11 | public interface IActorLocationResponse : IActorResponse
12 | {
13 | }
14 | }
--------------------------------------------------------------------------------
/Source/Module/Numeric/NumericWatcher_Hp_ShowUI.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | ///
4 | /// 监视hp数值变化,改变血条值
5 | ///
6 | [NumericWatcher(NumericType.Hp)]
7 | public class NumericWatcher_Hp_ShowUI : INumericWatcher
8 | {
9 | public void Run(long id, int value)
10 | {
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Source/Helper/ActionHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine.UI;
3 |
4 | namespace ETModel
5 | {
6 | public static class ActionHelper
7 | {
8 | public static void Add(this Button.ButtonClickedEvent buttonClickedEvent, Action action)
9 | {
10 | buttonClickedEvent.AddListener(()=> { action(); });
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/Source/Module/Message/MessageInfo.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public struct MessageInfo
4 | {
5 | public ushort Opcode { get; }
6 | public object Message { get; }
7 |
8 | public MessageInfo(ushort opcode, object message)
9 | {
10 | this.Opcode = opcode;
11 | this.Message = message;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Source/Module/Numeric/NumericWatcherAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public class NumericWatcherAttribute : BaseAttribute
6 | {
7 | public NumericType NumericType { get; }
8 |
9 | public NumericWatcherAttribute(NumericType type)
10 | {
11 | this.NumericType = type;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/Source/Module/UI/UIFactoryAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | [AttributeUsage(AttributeTargets.Class)]
6 | public class UIFactoryAttribute: BaseAttribute
7 | {
8 | public string Type { get; }
9 |
10 | public UIFactoryAttribute(string type)
11 | {
12 | this.Type = type;
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/Source/Base/Event/EventAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
6 | public class EventAttribute: BaseAttribute
7 | {
8 | public string Type { get; }
9 |
10 | public EventAttribute(string type)
11 | {
12 | this.Type = type;
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/Example/Assets/Example/Scripts/Handlers/TestHotfixSubscribMonoEvent_LogString.cs:
--------------------------------------------------------------------------------
1 | using ETModel;
2 |
3 | // 分发数值监听
4 | [Event(ETModel.EventIdType.TestHotfixSubscribMonoEvent)]
5 | public class TestHotfixSubscribMonoEvent_LogString : AEvent
6 | {
7 | public override void Run(string info)
8 | {
9 | Log.Info(info);
10 | }
11 | }
--------------------------------------------------------------------------------
/Example/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1045 &1
4 | EditorBuildSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Scenes:
8 | - enabled: 1
9 | path: Assets/Scenes/SampleScene.unity
10 | guid: 2cda990e2423bbf4892e6590ba056729
11 | m_configObjects: {}
12 |
--------------------------------------------------------------------------------
/Source/Base/Object/BaseAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
6 | public class BaseAttribute: Attribute
7 | {
8 | public Type AttributeType { get; }
9 |
10 | public BaseAttribute()
11 | {
12 | this.AttributeType = this.GetType();
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/Source/Base/Object/EntityEventAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
6 | public class EntityEventAttribute: Attribute
7 | {
8 | public int ClassType;
9 |
10 | public EntityEventAttribute(int classType)
11 | {
12 | this.ClassType = classType;
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/Source/Module/Message/MessageHandlerAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public class MessageHandlerAttribute : BaseAttribute
6 | {
7 | public AppType Type { get; }
8 |
9 | public MessageHandlerAttribute()
10 | {
11 | }
12 |
13 | public MessageHandlerAttribute(AppType appType)
14 | {
15 | this.Type = appType;
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/Source/Base/Object/Object.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 |
3 | namespace ETModel
4 | {
5 | public abstract class Object: ISupportInitialize
6 | {
7 | public virtual void BeginInit()
8 | {
9 | }
10 |
11 | public virtual void EndInit()
12 | {
13 | }
14 |
15 | public override string ToString()
16 | {
17 | return JsonHelper.ToJson(this);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Example/Assets/Example/Readme.txt:
--------------------------------------------------------------------------------
1 | ET客户端组件整理:kkc
2 | ET客户端组件开源地址:https://github.com/kkc001/ETClient
3 |
4 | ET源框架地址:https://github.com/egametang/ET
5 | 讨论QQ群 : 474643097
6 |
7 | ETClient版本说明
8 | 1.这是基于ET 4.0 ET客户端的组件版本,适合于学习,或附加其他项目使用
9 | 2.只供学习交流使用
10 | 3.只有一个极小的开发包dll,导入项目即可使用,基于C# 4.5开发请确认项目开启了C# 4.X的支持
11 |
12 | ETClient组件使用方法
13 | 1.使用Unity打开并导入组件,确认项目开启了C# 4.X的支持,运行Example下测试场景
14 | 2.服务端版本保持参考源框架
15 |
--------------------------------------------------------------------------------
/Source/Base/Object/IComponentSerialize.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | // 在序列化前或者反序列化之后需要做一些操作,可以实现该接口,该接口的方法需要手动调用
4 | // 相比ISupportInitialize接口,BeginSerialize在BeginInit之前调用,EndDeSerialize在EndInit之后调用
5 | // 并且需要手动调用,可以在反序列化之后,在次方法中将注册组件到EventSystem之中等等
6 | public interface IComponentSerialize
7 | {
8 | // 序列化之前调用
9 | void BeginSerialize();
10 | // 反序列化之后调用
11 | void EndDeSerialize();
12 | }
13 | }
--------------------------------------------------------------------------------
/Source/Module/Filter/FilterAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
6 | public class FilterAttribute: BaseAttribute
7 | {
8 | // 指定管理器的类型名
9 | public string ManagerTypeName { get; }
10 |
11 | public FilterAttribute(string managerTypeName)
12 | {
13 | this.ManagerTypeName = managerTypeName;
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/Source/Module/Numeric/NumericChangeEvent_NotifyWatcher.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | // 分发数值监听
4 | [Event(EventIdType.NumbericChange)]
5 | public class NumericChangeEvent_NotifyWatcher: AEvent
6 | {
7 | public override void Run(NumericType numericType, long id, int value)
8 | {
9 | Game.Scene.GetComponent().Run(numericType, id, value);
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Example/ProjectSettings/PresetManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1386491679 &1
4 | PresetManager:
5 | m_ObjectHideFlags: 0
6 | m_DefaultList:
7 | - type:
8 | m_NativeTypeID: 20
9 | m_ManagedTypePPtr: {fileID: 0}
10 | m_ManagedTypeFallback:
11 | defaultPresets:
12 | - m_Preset: {fileID: 2655988077585873504, guid: bfcfc320427f8224bbb7a96f3d3aebad,
13 | type: 2}
14 |
--------------------------------------------------------------------------------
/Source/Helper/ResourcesHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using UnityEngine;
6 |
7 | #if UNITY_EDITOR
8 | using UnityEditor;
9 | #endif
10 |
11 | namespace ETModel
12 | {
13 | public static class ResourcesHelper
14 | {
15 | public static UnityEngine.Object Load(string path)
16 | {
17 | return Resources.Load(path);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Source/Module/Actor/IActorMessage.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | // 不需要返回消息
4 | public interface IActorMessage: IMessage
5 | {
6 | long ActorId { get; set; }
7 | }
8 |
9 | public interface IActorRequest : IRequest
10 | {
11 | long ActorId { get; set; }
12 | }
13 |
14 | public interface IActorResponse : IResponse
15 | {
16 | }
17 |
18 | public interface IFrameMessage : IMessage
19 | {
20 | long Id { get; set; }
21 | }
22 | }
--------------------------------------------------------------------------------
/Source/Module/FrameSync/PlayerFactory.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public static class PlayerFactory
4 | {
5 | public static Player Create(long id)
6 | {
7 | Player player = ComponentFactory.CreateWithId(id);
8 | PlayerComponent playerComponent = Game.Scene.GetComponent();
9 | playerComponent.Add(player);
10 | return player;
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/Source/Base/Object/ILoadSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public interface ILoadSystem
6 | {
7 | Type Type();
8 | void Run(object o);
9 | }
10 |
11 | public abstract class LoadSystem : ILoadSystem
12 | {
13 | public void Run(object o)
14 | {
15 | this.Load((T)o);
16 | }
17 |
18 | public Type Type()
19 | {
20 | return typeof(T);
21 | }
22 |
23 | public abstract void Load(T self);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/Base/Object/IStartSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public interface IStartSystem
6 | {
7 | Type Type();
8 | void Run(object o);
9 | }
10 |
11 | public abstract class StartSystem : IStartSystem
12 | {
13 | public void Run(object o)
14 | {
15 | this.Start((T)o);
16 | }
17 |
18 | public Type Type()
19 | {
20 | return typeof(T);
21 | }
22 |
23 | public abstract void Start(T self);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Example/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!11 &1
4 | AudioManager:
5 | m_ObjectHideFlags: 0
6 | m_Volume: 1
7 | Rolloff Scale: 1
8 | Doppler Factor: 1
9 | Default Speaker Mode: 2
10 | m_SampleRate: 0
11 | m_DSPBufferSize: 1024
12 | m_VirtualVoiceCount: 512
13 | m_RealVoiceCount: 32
14 | m_SpatializerPlugin:
15 | m_AmbisonicDecoderPlugin:
16 | m_DisableAudio: 0
17 | m_VirtualizeEffects: 1
18 |
--------------------------------------------------------------------------------
/Source/Base/Object/IChangeSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public interface IChangeSystem
6 | {
7 | Type Type();
8 | void Run(object o);
9 | }
10 |
11 | public abstract class ChangeSystem : IChangeSystem
12 | {
13 | public void Run(object o)
14 | {
15 | this.Change((T)o);
16 | }
17 |
18 | public Type Type()
19 | {
20 | return typeof(T);
21 | }
22 |
23 | public abstract void Change(T self);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/Base/Object/IUpdateSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public interface IUpdateSystem
6 | {
7 | Type Type();
8 | void Run(object o);
9 | }
10 |
11 | public abstract class UpdateSystem : IUpdateSystem
12 | {
13 | public void Run(object o)
14 | {
15 | this.Update((T)o);
16 | }
17 |
18 | public Type Type()
19 | {
20 | return typeof(T);
21 | }
22 |
23 | public abstract void Update(T self);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/Base/Object/IDestroySystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public interface IDestroySystem
6 | {
7 | Type Type();
8 | void Run(object o);
9 | }
10 |
11 | public abstract class DestroySystem : IDestroySystem
12 | {
13 | public void Run(object o)
14 | {
15 | this.Destroy((T)o);
16 | }
17 |
18 | public Type Type()
19 | {
20 | return typeof(T);
21 | }
22 |
23 | public abstract void Destroy(T self);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### ET客户端组件整理:kkc
2 | ### ET客户端组件开源地址:https://github.com/kkc001/ETClient
3 |
4 | ### ET源框架作者:熊猫,社区参与者 哲学绅士,Justin沙特王子
5 | ### ET源框架地址:https://github.com/egametang/ET
6 | __ET源框架讨论QQ群 : 474643097__
7 |
8 | ## ETClient版本说明
9 | 1.这是基于ET 4.0 ET客户端的组件版本,适合于学习,或附加其他项目使用
10 |
11 | 2.只供学习交流使用
12 |
13 | 3.只有一个极小的开发包dll,导入项目即可使用,基于C# 4.5开发请确认项目开启了C# 4.X的支持
14 |
15 | ## ETClient运行使用方法
16 | 1.使用Unity打开并导入组件,确认项目开启了C# 4.X的支持,运行Example下测试场景
17 |
18 | 2.服务端版本保持参考源框架
19 |
--------------------------------------------------------------------------------
/Source/Base/Helper/IdGenerater.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public static class IdGenerater
4 | {
5 | public static long AppId { private get; set; }
6 |
7 | private static ushort value;
8 |
9 | public static long GenerateId()
10 | {
11 | long time = TimeHelper.ClientNowSeconds();
12 |
13 | return (AppId << 48) + (time << 16) + ++value;
14 | }
15 |
16 | public static int GetAppIdFromId(long id)
17 | {
18 | return (int)(id >> 48);
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/Source/Base/Object/ILateUpdateSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public interface ILateUpdateSystem
6 | {
7 | Type Type();
8 | void Run(object o);
9 | }
10 |
11 | public abstract class LateUpdateSystem : ILateUpdateSystem
12 | {
13 | public void Run(object o)
14 | {
15 | this.LateUpdate((T)o);
16 | }
17 |
18 | public Type Type()
19 | {
20 | return typeof(T);
21 | }
22 |
23 | public abstract void LateUpdate(T self);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/Base/Helper/MD5Helper.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Security.Cryptography;
3 |
4 | namespace ETModel
5 | {
6 | public static class MD5Helper
7 | {
8 | public static string FileMD5(string filePath)
9 | {
10 | byte[] retVal;
11 | using (FileStream file = new FileStream(filePath, FileMode.Open))
12 | {
13 | MD5 md5 = new MD5CryptoServiceProvider();
14 | retVal = md5.ComputeHash(file);
15 | }
16 | return retVal.ToHex("x2");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Module/FrameSync/FrameOpcode.cs:
--------------------------------------------------------------------------------
1 | using ETModel;
2 | namespace ETModel
3 | {
4 | [Message(FrameOpcode.OneFrameMessage)]
5 | public partial class OneFrameMessage : IActorLocationMessage {}
6 |
7 | [Message(FrameOpcode.FrameMessage)]
8 | public partial class FrameMessage : IActorMessage {}
9 |
10 | }
11 | namespace ETModel
12 | {
13 | public static partial class FrameOpcode
14 | {
15 | public const ushort OneFrameMessage = 11;
16 | public const ushort FrameMessage = 12;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Source/Helper/GameObjectHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace ETModel
5 | {
6 | public static class GameObjectHelper
7 | {
8 | public static T Get(this GameObject gameObject, string key) where T : class
9 | {
10 | try
11 | {
12 | return gameObject.GetComponent().Get(key);
13 | }
14 | catch (Exception e)
15 | {
16 | throw new Exception($"获取{gameObject.name}的ReferenceCollector key失败, key: {key}", e);
17 | }
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Source/Module/Message/SessionCallbackComponent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace ETModel
5 | {
6 | public class SessionCallbackComponent: Component
7 | {
8 | public Action MessageCallback;
9 | public Action DisposeCallback;
10 |
11 | public override void Dispose()
12 | {
13 | if (this.IsDisposed)
14 | {
15 | return;
16 | }
17 | base.Dispose();
18 |
19 | this.DisposeCallback?.Invoke(this.GetParent());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Source/Module/Message/IMessagePacker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace ETModel
5 | {
6 | public interface IMessagePacker
7 | {
8 | byte[] SerializeTo(object obj);
9 | void SerializeTo(object obj, MemoryStream stream);
10 | object DeserializeFrom(Type type, byte[] bytes, int index, int count);
11 | object DeserializeFrom(object instance, byte[] bytes, int index, int count);
12 | object DeserializeFrom(Type type, MemoryStream stream);
13 | object DeserializeFrom(object instance, MemoryStream stream);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Source/Other/IInstanceMethod.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public abstract class IInstanceMethod
4 | {
5 | public abstract void Run();
6 | public abstract void Run(object a);
7 | public abstract void Run(object a, object b);
8 | public abstract void Run(object a, object b, object c);
9 | }
10 |
11 | public abstract class IStaticMethod
12 | {
13 | public abstract void Run();
14 | public abstract void Run(object a);
15 | public abstract void Run(object a, object b);
16 | public abstract void Run(object a, object b, object c);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Source/Base/Helper/NetHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Net;
3 |
4 | namespace ETModel
5 | {
6 | public static class NetHelper
7 | {
8 | public static string[] GetAddressIPs()
9 | {
10 | //获取本地的IP地址
11 | List addressIPs = new List();
12 | foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
13 | {
14 | if (address.AddressFamily.ToString() == "InterNetwork")
15 | {
16 | addressIPs.Add(address.ToString());
17 | }
18 | }
19 | return addressIPs.ToArray();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Source/Module/Message/RpcException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | ///
6 | /// RPC异常,带ErrorCode
7 | ///
8 | [Serializable]
9 | public class RpcException: Exception
10 | {
11 | public int Error { get; private set; }
12 |
13 | public RpcException(int error, string message): base($"Error: {error} Message: {message}")
14 | {
15 | this.Error = error;
16 | }
17 |
18 | public RpcException(int error, string message, Exception e): base($"Error: {error} Message: {message}", e)
19 | {
20 | this.Error = error;
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Source/Module/Message/MessageProxy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public class MessageProxy: IMHandler
6 | {
7 | private readonly Type type;
8 | private readonly Action action;
9 |
10 | public MessageProxy(Type type, Action action)
11 | {
12 | this.type = type;
13 | this.action = action;
14 | }
15 |
16 | public void Handle(Session session, object message)
17 | {
18 | this.action.Invoke(session, message);
19 | }
20 |
21 | public Type GetMessageType()
22 | {
23 | return this.type;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Source/Base/Helper/MethodInfoHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace ETModel
4 | {
5 | public static class MethodInfoHelper
6 | {
7 | public static void Run(this MethodInfo methodInfo, object obj, params object[] param)
8 | {
9 |
10 | if (methodInfo.IsStatic)
11 | {
12 | object[] p = new object[param.Length + 1];
13 | p[0] = obj;
14 | for (int i = 0; i < param.Length; ++i)
15 | {
16 | p[i + 1] = param[i];
17 | }
18 | methodInfo.Invoke(null, p);
19 | }
20 | else
21 | {
22 | methodInfo.Invoke(obj, param);
23 | }
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/Source/Module/Message/Network/NetworkHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 |
3 | namespace ETModel
4 | {
5 | public static class NetworkHelper
6 | {
7 | public static IPEndPoint ToIPEndPoint(string host, int port)
8 | {
9 | return new IPEndPoint(IPAddress.Parse(host), port);
10 | }
11 |
12 | public static IPEndPoint ToIPEndPoint(string address)
13 | {
14 | int index = address.LastIndexOf(':');
15 | string host = address.Substring(0, index);
16 | string p = address.Substring(index + 1);
17 | int port = int.Parse(p);
18 | return ToIPEndPoint(host, port);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Example/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!78 &1
4 | TagManager:
5 | serializedVersion: 2
6 | tags: []
7 | layers:
8 | - Default
9 | - TransparentFX
10 | - Ignore Raycast
11 | -
12 | - Water
13 | - UI
14 | -
15 | -
16 | -
17 | -
18 | -
19 | -
20 | -
21 | -
22 | -
23 | -
24 | -
25 | -
26 | -
27 | -
28 | -
29 | -
30 | -
31 | -
32 | -
33 | -
34 | -
35 | -
36 | -
37 | -
38 | -
39 | -
40 | m_SortingLayers:
41 | - name: Default
42 | uniqueID: 0
43 | locked: 0
44 |
--------------------------------------------------------------------------------
/Source/Module/Numeric/NumericType.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public enum NumericType
4 | {
5 | Max = 10000,
6 |
7 | Speed = 1000,
8 | SpeedBase = Speed * 10 + 1,
9 | SpeedAdd = Speed * 10 + 2,
10 | SpeedPct = Speed * 10 + 3,
11 | SpeedFinalAdd = Speed * 10 + 4,
12 | SpeedFinalPct = Speed * 10 + 5,
13 |
14 | Hp = 1001,
15 | HpBase = Hp * 10 + 1,
16 |
17 | MaxHp = 1002,
18 | MaxHpBase = MaxHp * 10 + 1,
19 | MaxHpAdd = MaxHp * 10 + 2,
20 | MaxHpPct = MaxHp * 10 + 3,
21 | MaxHpFinalAdd = MaxHp * 10 + 4,
22 | MaxHpFinalPct = MaxHp * 10 + 5,
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Source/Base/TryLocker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | namespace ETModel
5 | {
6 | public class TryLock : IDisposable
7 | {
8 | private object locked;
9 |
10 | public bool HasLock { get; private set; }
11 |
12 | public TryLock(object obj)
13 | {
14 | if (!Monitor.TryEnter(obj))
15 | {
16 | return;
17 | }
18 |
19 | this.HasLock = true;
20 | this.locked = obj;
21 | }
22 |
23 | public void Dispose()
24 | {
25 | if (!this.HasLock)
26 | {
27 | return;
28 | }
29 |
30 | Monitor.Exit(this.locked);
31 | this.locked = null;
32 | this.HasLock = false;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/Assets/Example/Scripts/Handlers/Frame_ClickMapHandler.cs:
--------------------------------------------------------------------------------
1 | using ETModel;
2 | using UnityEngine;
3 |
4 | [MessageHandler]
5 | public class Frame_ClickMapHandler : AMHandler
6 | {
7 | protected override void Run(ETModel.Session session, Frame_ClickMap message)
8 | {
9 | Unit unit = ETModel.Game.Scene.GetComponent().Get(message.Id);
10 | MoveComponent moveComponent = unit.GetComponent();
11 | Vector3 dest = new Vector3(message.X / 1000f, 0, message.Z / 1000f);
12 | moveComponent.MoveToDest(dest, 1);
13 | moveComponent.Turn2D(dest - unit.Position);
14 | }
15 | }
--------------------------------------------------------------------------------
/Source/Base/Helper/EnumHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public static class EnumHelper
6 | {
7 | public static int EnumIndex(int value)
8 | {
9 | int i = 0;
10 | foreach (object v in Enum.GetValues(typeof (T)))
11 | {
12 | if ((int) v == value)
13 | {
14 | return i;
15 | }
16 | ++i;
17 | }
18 | return -1;
19 | }
20 |
21 | public static T FromString(string str)
22 | {
23 | if (!Enum.IsDefined(typeof(T), str))
24 | {
25 | return default(T);
26 | }
27 | return (T)Enum.Parse(typeof(T), str);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Source/Base/Object/ComponentWithId.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using MongoDB.Bson.Serialization.Attributes;
3 |
4 | namespace ETModel
5 | {
6 | [BsonIgnoreExtraElements]
7 | public abstract class ComponentWithId : Component
8 | {
9 | [BsonIgnoreIfDefault]
10 | [BsonDefaultValue(0L)]
11 | [BsonElement]
12 | [BsonId]
13 | public long Id { get; set; }
14 |
15 | protected ComponentWithId()
16 | {
17 | }
18 |
19 | protected ComponentWithId(long id)
20 | {
21 | this.Id = id;
22 | }
23 |
24 | public override void Dispose()
25 | {
26 | if (this.IsDisposed)
27 | {
28 | return;
29 | }
30 |
31 | base.Dispose();
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/Source/Module/Message/OpcodeHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace ETModel
4 | {
5 | public static class OpcodeHelper
6 | {
7 | private static readonly HashSet needDebugLogMessageSet = new HashSet { 1 };
8 |
9 | public static bool IsNeedDebugLogMessage(ushort opcode)
10 | {
11 | //return true;
12 | if (opcode > 1000)
13 | {
14 | return true;
15 | }
16 |
17 | if (needDebugLogMessageSet.Contains(opcode))
18 | {
19 | return true;
20 | }
21 |
22 | return false;
23 | }
24 |
25 | public static bool IsClientHotfixMessage(ushort opcode)
26 | {
27 | return opcode > 10000;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Source/Other/Define.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public static class Define
4 | {
5 | #if UNITY_EDITOR && !ASYNC
6 | public static bool IsAsync = false;
7 | #else
8 | public static bool IsAsync = true;
9 | #endif
10 |
11 | #if UNITY_EDITOR
12 | public static bool IsEditorMode = true;
13 | #else
14 | public static bool IsEditorMode = false;
15 | #endif
16 |
17 | #if DEVELOPMENT_BUILD
18 | public static bool IsDevelopmentBuild = true;
19 | #else
20 | public static bool IsDevelopmentBuild = false;
21 | #endif
22 |
23 | #if ILRuntime
24 | public static bool IsILRuntime = true;
25 | #else
26 | public static bool IsILRuntime = false;
27 | #endif
28 | }
29 | }
--------------------------------------------------------------------------------
/Source/Module/Message/OuterMessageDispatcher.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public class OuterMessageDispatcher: IMessageDispatcher
4 | {
5 | public void Dispatch(Session session, ushort opcode, object message)
6 | {
7 | // 如果是帧同步消息,交给ClientFrameComponent处理
8 | FrameMessage frameMessage = message as FrameMessage;
9 | if (frameMessage != null)
10 | {
11 | Game.Scene.GetComponent().Add(session, frameMessage);
12 | return;
13 | }
14 |
15 | // 普通消息或者是Rpc请求消息
16 | MessageInfo messageInfo = new MessageInfo(opcode, message);
17 | Game.Scene.GetComponent().Handle(session, messageInfo);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Source/Entity/Scene.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public enum SceneType
4 | {
5 | Share,
6 | Game,
7 | Login,
8 | Lobby,
9 | Map,
10 | Launcher,
11 | Robot,
12 | BehaviorTreeScene,
13 | RobotClient,
14 |
15 | Realm
16 | }
17 |
18 | public sealed class Scene: Entity
19 | {
20 | public string Name { get; set; }
21 |
22 | public Scene()
23 | {
24 | this.InstanceId = IdGenerater.GenerateId();
25 | }
26 |
27 | public Scene(long id): base(id)
28 | {
29 | this.InstanceId = IdGenerater.GenerateId();
30 | }
31 |
32 | public override void Dispose()
33 | {
34 | if (this.IsDisposed)
35 | {
36 | return;
37 | }
38 |
39 | base.Dispose();
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Source/Base/Log.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public static class Log
6 | {
7 | public static void Trace(string msg)
8 | {
9 | UnityEngine.Debug.Log(msg);
10 | }
11 |
12 | public static void Warning(string msg)
13 | {
14 | UnityEngine.Debug.LogWarning(msg);
15 | }
16 |
17 | public static void Info(string msg)
18 | {
19 | UnityEngine.Debug.Log(msg);
20 | }
21 |
22 | public static void Error(Exception e)
23 | {
24 | UnityEngine.Debug.LogError(e.ToString());
25 | }
26 |
27 | public static void Error(string msg)
28 | {
29 | UnityEngine.Debug.LogError(msg);
30 | }
31 |
32 | public static void Debug(string msg)
33 | {
34 | UnityEngine.Debug.Log(msg);
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/Example/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!159 &1
4 | EditorSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 7
7 | m_ExternalVersionControlSupport: Visible Meta Files
8 | m_SerializationMode: 2
9 | m_LineEndingsForNewScripts: 2
10 | m_DefaultBehaviorMode: 1
11 | m_SpritePackerMode: 4
12 | m_SpritePackerPaddingPower: 1
13 | m_EtcTextureCompressorBehavior: 1
14 | m_EtcTextureFastCompressor: 1
15 | m_EtcTextureNormalCompressor: 2
16 | m_EtcTextureBestCompressor: 4
17 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd
18 | m_ProjectGenerationRootNamespace:
19 | m_UserGeneratedProjectSuffix:
20 | m_CollabEditorSettings:
21 | inProgressEnabled: 1
22 |
--------------------------------------------------------------------------------
/Source/Base/Helper/TimeHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public static class TimeHelper
6 | {
7 | private static readonly long epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks;
8 | ///
9 | /// 客户端时间
10 | ///
11 | ///
12 | public static long ClientNow()
13 | {
14 | return (DateTime.UtcNow.Ticks - epoch) / 10000;
15 | }
16 |
17 | public static long ClientNowSeconds()
18 | {
19 | return (DateTime.UtcNow.Ticks - epoch) / 10000000;
20 | }
21 |
22 | ///
23 | /// 登陆前是客户端时间,登陆后是同步过的服务器时间
24 | ///
25 | ///
26 | public static long Now()
27 | {
28 | return ClientNow();
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/Source/Module/Message/AMHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public abstract class AMHandler : IMHandler where Message: class
6 | {
7 | protected abstract void Run(Session session, Message message);
8 |
9 | public void Handle(Session session, object msg)
10 | {
11 | Message message = msg as Message;
12 | if (message == null)
13 | {
14 | Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof(Message).Name}");
15 | return;
16 | }
17 | if (session.IsDisposed)
18 | {
19 | Log.Error($"session disconnect {msg}");
20 | return;
21 | }
22 | this.Run(session, message);
23 | }
24 |
25 | public Type GetMessageType()
26 | {
27 | return typeof(Message);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Source/Module/FrameSync/SessionComponent.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | [ObjectSystem]
4 | public class SessionComponentAwakeSystem : AwakeSystem
5 | {
6 | public override void Awake(SessionComponent self)
7 | {
8 | self.Awake();
9 | }
10 | }
11 |
12 | public class SessionComponent: Component
13 | {
14 | public static SessionComponent Instance;
15 |
16 | public Session Session;
17 |
18 | public void Awake()
19 | {
20 | Instance = this;
21 | }
22 |
23 | public override void Dispose()
24 | {
25 | if (this.IsDisposed)
26 | {
27 | return;
28 | }
29 |
30 | base.Dispose();
31 |
32 | this.Session.Dispose();
33 | this.Session = null;
34 | Instance = null;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Source/Base/Helper/RandomHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ETModel
4 | {
5 | public static class RandomHelper
6 | {
7 | private static readonly Random random = new Random();
8 |
9 | public static UInt64 RandUInt64()
10 | {
11 | var bytes = new byte[8];
12 | random.NextBytes(bytes);
13 | return BitConverter.ToUInt64(bytes, 0);
14 | }
15 |
16 | public static Int64 RandInt64()
17 | {
18 | var bytes = new byte[8];
19 | random.NextBytes(bytes);
20 | return BitConverter.ToInt64(bytes, 0);
21 | }
22 |
23 | ///
24 | /// 获取lower与Upper之间的随机数
25 | ///
26 | ///
27 | ///
28 | ///
29 | public static int RandomNumber(int lower, int upper)
30 | {
31 | int value = random.Next(lower, upper);
32 | return value;
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/Source/Base/OneThreadSynchronizationContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Threading;
4 |
5 | namespace ETModel
6 | {
7 | public class OneThreadSynchronizationContext : SynchronizationContext
8 | {
9 | public static OneThreadSynchronizationContext Instance { get; } = new OneThreadSynchronizationContext();
10 |
11 | // 线程同步队列,发送接收socket回调都放到该队列,由poll线程统一执行
12 | private readonly ConcurrentQueue queue = new ConcurrentQueue();
13 |
14 | private Action a;
15 |
16 | public void Update()
17 | {
18 | while (true)
19 | {
20 | if (!this.queue.TryDequeue(out a))
21 | {
22 | return;
23 | }
24 | a();
25 | }
26 | }
27 |
28 | public override void Post(SendOrPostCallback callback, object state)
29 | {
30 | this.queue.Enqueue(() => { callback(state); });
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Source/Module/FrameSync/Unit.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace ETModel
4 | {
5 | public enum UnitType
6 | {
7 | Hero,
8 | Npc
9 | }
10 |
11 | public sealed class Unit: Entity
12 | {
13 | public VInt3 IntPos;
14 |
15 | public GameObject GameObject;
16 |
17 | public void Awake()
18 | {
19 | }
20 |
21 | public Vector3 Position
22 | {
23 | get
24 | {
25 | return GameObject.transform.position;
26 | }
27 | set
28 | {
29 | GameObject.transform.position = value;
30 | }
31 | }
32 |
33 | public Quaternion Rotation
34 | {
35 | get
36 | {
37 | return GameObject.transform.rotation;
38 | }
39 | set
40 | {
41 | GameObject.transform.rotation = value;
42 | }
43 | }
44 |
45 | public override void Dispose()
46 | {
47 | if (this.IsDisposed)
48 | {
49 | return;
50 | }
51 |
52 | base.Dispose();
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/Source/Module/UI/LayerNames.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace ETModel
4 | {
5 | public static class LayerNames
6 | {
7 | ///
8 | /// UI层
9 | ///
10 | public const string UI = "UI";
11 |
12 | ///
13 | /// 游戏单位层
14 | ///
15 | public const string UNIT = "Unit";
16 |
17 | ///
18 | /// 地形层
19 | ///
20 | public const string MAP = "Map";
21 |
22 | ///
23 | /// 默认层
24 | ///
25 | public const string DEFAULT = "Default";
26 |
27 | ///
28 | /// 通过Layers名字得到对应层
29 | ///
30 | ///
31 | ///
32 | public static int GetLayerInt(string name)
33 | {
34 | return LayerMask.NameToLayer(name);
35 | }
36 |
37 | public static string GetLayerStr(int name)
38 | {
39 | return LayerMask.LayerToName(name);
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Source/Module/Message/Network/AService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 |
4 | namespace ETModel
5 | {
6 | public enum NetworkProtocol
7 | {
8 | KCP,
9 | TCP,
10 | WebSocket,
11 | }
12 |
13 | public abstract class AService: Component
14 | {
15 | public abstract AChannel GetChannel(long id);
16 |
17 | private Action acceptCallback;
18 |
19 | public event Action AcceptCallback
20 | {
21 | add
22 | {
23 | this.acceptCallback += value;
24 | }
25 | remove
26 | {
27 | this.acceptCallback -= value;
28 | }
29 | }
30 |
31 | protected void OnAccept(AChannel channel)
32 | {
33 | this.acceptCallback.Invoke(channel);
34 | }
35 |
36 | public abstract AChannel ConnectChannel(IPEndPoint ipEndPoint);
37 |
38 | public abstract AChannel ConnectChannel(string address);
39 |
40 | public abstract void Remove(long channelId);
41 |
42 | public abstract void Update();
43 | }
44 | }
--------------------------------------------------------------------------------
/Source/Module/Message/IMessage.cs:
--------------------------------------------------------------------------------
1 | using Google.Protobuf;
2 |
3 | namespace ETModel
4 | {
5 | public interface IMessage : Google.Protobuf.IMessage
6 | { }
7 |
8 | public interface IRequest : IMessage
9 | {
10 | int RpcId { get; set; }
11 | }
12 |
13 | public interface IResponse : IMessage
14 | {
15 | int Error { get; set; }
16 | string Message { get; set; }
17 | int RpcId { get; set; }
18 | }
19 |
20 | public class ResponseMessage : IResponse
21 | {
22 | public int Error { get; set; }
23 | public string Message { get; set; }
24 | public int RpcId { get; set; }
25 |
26 | public int CalculateSize()
27 | {
28 | return 0;
29 | }
30 |
31 | public void MergeFrom(CodedInputStream input)
32 | {
33 | }
34 |
35 | public void WriteTo(CodedOutputStream output)
36 | {
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/Source/Entity/Game.cs:
--------------------------------------------------------------------------------
1 | namespace ETModel
2 | {
3 | public static class Game
4 | {
5 | private static Scene scene;
6 |
7 | public static Scene Scene
8 | {
9 | get
10 | {
11 | if (scene != null)
12 | {
13 | return scene;
14 | }
15 | scene = new Scene();
16 | scene.AddComponent();
17 | return scene;
18 | }
19 | }
20 |
21 | private static EventSystem eventSystem;
22 |
23 | public static EventSystem EventSystem
24 | {
25 | get
26 | {
27 | return eventSystem ?? (eventSystem = new EventSystem());
28 | }
29 | }
30 |
31 | private static ObjectPool objectPool;
32 |
33 | public static ObjectPool ObjectPool
34 | {
35 | get
36 | {
37 | return objectPool ?? (objectPool = new ObjectPool());
38 | }
39 | }
40 |
41 | public static void Close()
42 | {
43 | scene.Dispose();
44 | eventSystem = null;
45 | scene = null;
46 | objectPool = null;
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/ICreatorSelector.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2010-2014 MongoDB Inc.
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | using System.Collections.Generic;
17 |
18 | namespace MongoDB.Bson.Serialization
19 | {
20 | internal interface ICreatorSelector
21 | {
22 | BsonCreatorMap SelectCreator(BsonClassMap classMap, Dictionary values);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Example/Example.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Assembly-CSharp.csproj", "{CC8ECD15-D248-3044-CBD9-85E15547FD38}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {CC8ECD15-D248-3044-CBD9-85E15547FD38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {CC8ECD15-D248-3044-CBD9-85E15547FD38}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {CC8ECD15-D248-3044-CBD9-85E15547FD38}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {CC8ECD15-D248-3044-CBD9-85E15547FD38}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/Example/ProjectSettings/UnityConnectSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!310 &1
4 | UnityConnectSettings:
5 | m_ObjectHideFlags: 0
6 | m_Enabled: 0
7 | m_TestMode: 0
8 | m_TestEventUrl:
9 | m_TestConfigUrl:
10 | m_TestInitMode: 0
11 | CrashReportingSettings:
12 | m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes
13 | m_NativeEventUrl: https://perf-events.cloud.unity3d.com/symbolicate
14 | m_Enabled: 0
15 | m_CaptureEditorExceptions: 1
16 | UnityPurchasingSettings:
17 | m_Enabled: 0
18 | m_TestMode: 0
19 | UnityAnalyticsSettings:
20 | m_Enabled: 1
21 | m_InitializeOnStartup: 1
22 | m_TestMode: 0
23 | m_TestEventUrl:
24 | m_TestConfigUrl:
25 | UnityAdsSettings:
26 | m_Enabled: 0
27 | m_InitializeOnStartup: 1
28 | m_TestMode: 0
29 | m_IosGameId:
30 | m_AndroidGameId:
31 | m_GameIds: {}
32 | m_GameId:
33 | PerformanceReportingSettings:
34 | m_Enabled: 0
35 |
--------------------------------------------------------------------------------
/Source/Base/Helper/JsonHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using ETModel.Json;
4 |
5 | namespace ETModel
6 | {
7 | public static class JsonHelper
8 | {
9 | public static string ToJson(object obj)
10 | {
11 | return JsonMapper.ToJson(obj);
12 | }
13 |
14 | public static T FromJson(string str)
15 | {
16 | T t = JsonMapper.ToObject(str);
17 | ISupportInitialize iSupportInitialize = t as ISupportInitialize;
18 | if (iSupportInitialize == null)
19 | {
20 | return t;
21 | }
22 | iSupportInitialize.EndInit();
23 | return t;
24 | }
25 |
26 | public static object FromJson(Type type, string str)
27 | {
28 | object t = JsonMapper.ToObject(type, str);
29 | ISupportInitialize iSupportInitialize = t as ISupportInitialize;
30 | if (iSupportInitialize == null)
31 | {
32 | return t;
33 | }
34 | iSupportInitialize.EndInit();
35 | return t;
36 | }
37 |
38 | public static T Clone(T t)
39 | {
40 | return FromJson(ToJson(t));
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IConvention.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2010-2014 MongoDB Inc.
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | namespace MongoDB.Bson.Serialization.Conventions
17 | {
18 | ///
19 | /// Represents a convention.
20 | ///
21 | public interface IConvention
22 | {
23 | ///
24 | /// Gets the name of the convention.
25 | ///
26 | string Name { get; }
27 | }
28 | }
--------------------------------------------------------------------------------
/Source/Base/Object/EventProxy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace ETModel
5 | {
6 | public class EventProxy: IEvent
7 | {
8 | public Action> action;
9 | public List