提交 4968032a 编写于 作者: T tanghai

mono层和hotfix层分别创建一份Entity系统,只使用命名空间区分,可以随时将Entity和Component放在任何一层上面

上级 58e129be
fileFormatVersion: 2
guid: 2a558a9c1a99ead44867c6b71472566f
folderAsset: yes
timeCreated: 1498117616
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e98bd4118f88e1c428e3af0983722aa8
folderAsset: yes
timeCreated: 1498118075
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
namespace Model
{
[BsonIgnoreExtraElements]
public class ClientConfig: AConfigComponent
......
fileFormatVersion: 2
guid: befeb8cfbdbfc5b4ea5f967c200d4751
timeCreated: 1498118076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
namespace Model
{
[BsonIgnoreExtraElements]
public class InnerConfig: AConfigComponent
......
fileFormatVersion: 2
guid: 35f166fd86ee5e44aaec9326bb0a5454
timeCreated: 1498118076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
namespace Model
{
[BsonIgnoreExtraElements]
public class OuterConfig: AConfigComponent
......
fileFormatVersion: 2
guid: 31224cfdac2f28c42bd641d5a2e80fe8
timeCreated: 1498118075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
namespace Model
{
[BsonIgnoreExtraElements]
public class RunServerConfig: AConfigComponent
......
fileFormatVersion: 2
guid: bceb49362f439a248b806059721da628
timeCreated: 1498118076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using Model;
namespace Model
{
[EntityEvent(EntityEventId.EventComponent)]
public class EventComponent : Component, IAwake
{
private Dictionary<int, List<object>> allEvents;
public void Awake()
{
this.Load();
}
public void Load()
{
this.allEvents = new Dictionary<int, List<object>>();
Type[] types = DllHelper.GetAllTypes();
foreach (Type type in types)
{
object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
foreach (object attr in attrs)
{
EventAttribute aEventAttribute = (EventAttribute)attr;
object obj = Activator.CreateInstance(type);
if (!this.allEvents.ContainsKey(aEventAttribute.Type))
{
this.allEvents.Add(aEventAttribute.Type, new List<object>());
}
this.allEvents[aEventAttribute.Type].Add(obj);
}
}
}
public void Run(int type)
{
List<object> iEvents = null;
if (!this.allEvents.TryGetValue(type, out iEvents))
{
return;
}
foreach (object obj in iEvents)
{
try
{
IEvent iEvent = (IEvent)obj;
iEvent.Run();
}
catch (Exception e)
{
Log.Error(e.ToString());
}
}
}
public void Run<A>(int type, A a)
{
List<object> iEvents = null;
if (!this.allEvents.TryGetValue(type, out iEvents))
{
return;
}
foreach (object obj in iEvents)
{
try
{
IEvent<A> iEvent = (IEvent<A>)obj;
iEvent.Run(a);
}
catch (Exception err)
{
Log.Error(err.ToString());
}
}
}
public void Run<A, B>(int type, A a, B b)
{
List<object> iEvents = null;
if (!this.allEvents.TryGetValue(type, out iEvents))
{
return;
}
foreach (object obj in iEvents)
{
try
{
IEvent<A, B> iEvent = (IEvent<A, B>)obj;
iEvent.Run(a, b);
}
catch (Exception err)
{
Log.Error(err.ToString());
}
}
}
public void Run<A, B, C>(int type, A a, B b, C c)
{
List<object> iEvents = null;
if (!this.allEvents.TryGetValue(type, out iEvents))
{
return;
}
foreach (object obj in iEvents)
{
try
{
IEvent<A, B, C> iEvent = (IEvent<A, B, C>)obj;
iEvent.Run(a, b, c);
}
catch (Exception err)
{
Log.Error(err.ToString());
}
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: fdeabd62f7ad9414fa74891de319729f
timeCreated: 1498117617
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using Model;
namespace Hotfix
namespace Model
{
/// <summary>
/// 消息分发组件
/// </summary>
[EntityEvent(EntityEventId.MessageDispatherComponent)]
public class MessageDispatherComponent: HotfixComponent, IAwake<AppType>, ILoad
[ObjectEvent(EntityEventId.MessageDispatherComponent)]
public class MessageDispatherComponent: Component, IAwake<AppType>, ILoad
{
private AppType AppType;
private Dictionary<ushort, List<IInstanceMethod>> handlers;
......
fileFormatVersion: 2
guid: 8e97599ee372f6f40aaa5e743851a74c
timeCreated: 1498117781
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using Model;
namespace Hotfix
namespace Model
{
[EntityEvent(EntityEventId.NetInnerComponent)]
public class NetInnerComponent: NetworkComponent
......
fileFormatVersion: 2
guid: 1ab11b2f08956d1499373e40ab1eba6b
timeCreated: 1498117616
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Model;
namespace Hotfix
namespace Model
{
[EntityEvent(EntityEventId.NetOuterComponent)]
public class NetOuterComponent: NetworkComponent, IAwake, IAwake<string, int>, IUpdate
......
fileFormatVersion: 2
guid: 2540893057b627148a6fe09470765227
timeCreated: 1498117616
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,11 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Model;
namespace Hotfix
namespace Model
{
public abstract class NetworkComponent: HotfixComponent
public abstract class NetworkComponent: Component
{
private AService Service;
......
fileFormatVersion: 2
guid: 151d2db7aab5bc8438bc039443ba0e3b
timeCreated: 1498117616
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Model;
namespace Model
{
public class Timer
{
public long Id { get; set; }
public long Time { get; set; }
public TaskCompletionSource<bool> tcs;
}
[EntityEvent(EntityEventId.TimerComponent)]
public class TimerComponent: Component, IUpdate
{
private readonly Dictionary<long, Timer> timers = new Dictionary<long, Timer>();
/// <summary>
/// key: time, value: timer id
/// </summary>
private readonly MultiMap<long, long> timeId = new MultiMap<long, long>();
private readonly Queue<long> timeoutTimer = new Queue<long>();
public void Update()
{
long timeNow = TimeHelper.Now();
foreach (long time in this.timeId.Keys)
{
if (time > timeNow)
{
break;
}
this.timeoutTimer.Enqueue(time);
}
while (this.timeoutTimer.Count > 0)
{
long key = this.timeoutTimer.Dequeue();
long[] timeOutId = this.timeId.GetAll(key);
foreach (long id in timeOutId)
{
Timer timer;
if (!this.timers.TryGetValue(id, out timer))
{
continue;
}
this.Remove(id);
timer.tcs.SetResult(true);
}
}
}
private void Remove(long id)
{
Timer timer;
if (!this.timers.TryGetValue(id, out timer))
{
return;
}
this.timers.Remove(id);
this.timeId.Remove(timer.Time, timer.Id);
}
public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs };
this.timers[timer.Id] = timer;
this.timeId.Add(timer.Time, timer.Id);
cancellationToken.Register(() => { this.Remove(timer.Id); });
return tcs.Task;
}
public Task WaitTillAsync(long tillTime)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs };
this.timers[timer.Id] = timer;
this.timeId.Add(timer.Time, timer.Id);
return tcs.Task;
}
public Task WaitAsync(long time, CancellationToken cancellationToken)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.Now() + time, tcs = tcs };
this.timers[timer.Id] = timer;
this.timeId.Add(timer.Time, timer.Id);
cancellationToken.Register(() => { this.Remove(timer.Id); });
return tcs.Task;
}
public Task WaitAsync(long time)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.Now() + time, tcs = tcs };
this.timers[timer.Id] = timer;
this.timeId.Add(timer.Time, timer.Id);
return tcs.Task;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2f4a73ac996f1404aa1866a86140fe38
timeCreated: 1498117617
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d574f09c5596d2440b51164c43606464
folderAsset: yes
timeCreated: 1498118203
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
namespace Hotfix
namespace Model
{
/// <summary>
/// 管理该所有的配置
......
namespace Hotfix
namespace Model
{
/// <summary>
/// 每个Config的基类
/// </summary>
public abstract class AConfig: HotfixEntity
public abstract class AConfig: Entity
{
protected AConfig(EntityType entityType): base(entityType)
{
......
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
namespace Model
{
/// <summary>
/// 每个Config的基类
......@@ -8,7 +8,7 @@ namespace Hotfix
[BsonKnownTypes(typeof (ClientConfig))]
[BsonKnownTypes(typeof (InnerConfig))]
[BsonKnownTypes(typeof (OuterConfig))]
public abstract class AConfigComponent: HotfixComponent
public abstract class AConfigComponent: Component
{
}
}
\ No newline at end of file
using System;
namespace Hotfix
namespace Model
{
[AttributeUsage(AttributeTargets.Class)]
public class ConfigAttribute: Attribute
......
......@@ -2,7 +2,7 @@
using Model;
using UnityEngine;
namespace Hotfix
namespace Model
{
public static class ConfigHelper
{
......
using System;
using System.ComponentModel;
namespace Hotfix
namespace Model
{
public interface ICategory: ISupportInitialize
{
......
......@@ -7,7 +7,7 @@ using ILRuntime.CLR.TypeSystem;
using Model;
using UnityEngine;
namespace Hotfix
namespace Model
{
public static class DllHelper
{
......
fileFormatVersion: 2
guid: 20fbd2b0398f14a4d89abd01726d5d25
timeCreated: 1498118075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d2b1f66f808fc9a4ba043d89e5d982f9
folderAsset: yes
timeCreated: 1498117616
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using System.Threading.Tasks;
using UnityEngine;
namespace Hotfix
namespace Model
{
public class AssetBundleLoaderAsync : HotfixEntity
public class AssetBundleLoaderAsync : Entity
{
private AssetBundle assetBundle;
......
fileFormatVersion: 2
guid: 3884a45c24f76244aa0697dcb9d95d15
timeCreated: 1498117617
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 1136de56973a671409ed0bf599b1f478
folderAsset: yes
timeCreated: 1498118075
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
namespace Model
{
[BsonIgnoreExtraElements]
public class BuffConfig: AConfig
......
fileFormatVersion: 2
guid: 8433bdafcbe56e140b3fe0c93722e0cf
timeCreated: 1498118076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
namespace Model
{
public class StartConfig: AConfig
{
......
fileFormatVersion: 2
guid: c181dc38f15288746960812611a7767e
timeCreated: 1498118076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace Model
{
public static class Game
{
private static Scene scene;
public static Scene Scene
{
get
{
if (scene != null)
{
return scene;
}
scene = new Scene();
scene.AddComponent<EventComponent>();
scene.AddComponent<TimerComponent>();
return scene;
}
}
public static void Close()
{
scene.Dispose();
scene = null;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 0e531b523752fbc4a837e52d4ba093dc
timeCreated: 1498117616
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace Model
{
public enum SceneType
{
Share,
Game,
Login,
Lobby,
Map,
Launcher,
Robot,
BehaviorTreeScene,
RobotClient,
Realm
}
public sealed class Scene: Entity
{
public Scene Parent { get; set; }
public string Name { get; set; }
public SceneType SceneType { get; private set; }
public Scene(): base(EntityType.Scene)
{
}
public Scene(long id): base(id, EntityType.Scene)
{
}
public override void Dispose()
{
if (this.Id == 0)
{
return;
}
base.Dispose();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 6a74878a3e383af45bac4995de1e0f53
timeCreated: 1498117617
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,13 +2,12 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using LitJson;
using Model;
using MongoDB.Bson;
namespace Hotfix
namespace Model
{
public sealed class Session : HotfixEntity
public sealed class Session : Entity
{
private static uint RpcId { get; set; }
private readonly NetworkComponent network;
......
fileFormatVersion: 2
guid: 73d149d0c325fa24d91a94843bd520b8
timeCreated: 1498117617
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -3,10 +3,10 @@ using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
namespace Hotfix
namespace Model
{
[EntityEvent(EntityEventId.WWWAsync)]
public class WWWAsync: HotfixEntity
public class WWWAsync: Entity
{
public WWW www;
......
fileFormatVersion: 2
guid: 4d789ae4ba23a73469b228352499a1d0
timeCreated: 1498117617
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f4a531a7e2c04874fb0e829ae1773978
folderAsset: yes
timeCreated: 1498117616
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using System;
namespace Model
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public abstract class AEventAttribute: Attribute
{
public int Type { get; private set; }
protected AEventAttribute(int type)
{
this.Type = type;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 288485f014836824b89d9a901bc5dcca
timeCreated: 1477377275
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
public class Env
{
[BsonElement, BsonIgnoreIfNull]
private Dictionary<EnvKey, object> values = new Dictionary<EnvKey, object>();
public object this[EnvKey key]
{
get
{
return this.values[key];
}
set
{
if (this.values == null)
{
this.values = new Dictionary<EnvKey, object>();
}
this.values[key] = value;
}
}
public T Get<T>(EnvKey key)
{
if (this.values == null || !this.values.ContainsKey(key))
{
return default(T);
}
object value = values[key];
try
{
return (T) value;
}
catch (InvalidCastException e)
{
throw new Exception($"不能把{value.GetType()}转换为{typeof (T)}", e);
}
}
public void Set(EnvKey key, object obj)
{
if (this.values == null)
{
this.values = new Dictionary<EnvKey, object>();
}
this.values[key] = obj;
}
public bool ContainKey(EnvKey key)
{
if (this.values == null)
{
return false;
}
return this.values.ContainsKey(key);
}
public void Remove(EnvKey key)
{
if (this.values == null)
{
return;
}
this.values.Remove(key);
if (this.values.Count == 0)
{
this.values = null;
}
}
public void Add(EnvKey key, object value)
{
if (this.values == null)
{
this.values = new Dictionary<EnvKey, object>();
}
this.values[key] = value;
}
public IEnumerator GetEnumerator()
{
return this.values.GetEnumerator();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 414e43d5bdd3d75458b86b1cf07ad175
timeCreated: 1477377275
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace Model
{
/// <summary>
/// 一般使用事件名+变量名
/// </summary>
public enum EnvKey
{
ChannelError
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: c6db3274f6a56f44eaaa14e0f2eecf54
timeCreated: 1476427109
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace Model
{
public class EventAttribute: AEventAttribute
{
public EventAttribute(int type): base(type)
{
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 46c83a3a046e502409ed650e1f3bc238
timeCreated: 1477377275
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace Model
{
public static class EventIdType
{
public const int InitSceneStart = 1;
public const int BehaviorTreeRunTreeEvent = 2;
public const int BehaviorTreeOpenEditor = 3;
public const int BehaviorTreeClickNode = 4;
public const int BehaviorTreeAfterChangeNodeType = 5;
public const int BehaviorTreeCreateNode = 6;
public const int BehaviorTreePropertyDesignerNewCreateClick = 7;
public const int BehaviorTreeMouseInNode = 8;
public const int BehaviorTreeConnectState = 9;
public const int BehaviorTreeReplaceClick = 10;
public const int BehaviorTreeRightDesignerDrag = 11;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 50aff527fd963e44fbce24e2ef3c1287
timeCreated: 1476421726
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace Model
{
public interface IEvent
{
void Run();
}
public interface IEvent<in A>
{
void Run(A uid);
}
public interface IEvent<in A, in B>
{
void Run(A a, B b);
}
public interface IEvent<in A, in B, in C>
{
void Run(A a, B b, C c);
}
public interface IEvent<in A, in B, in C, in D>
{
void Run(A a, B b, C c, D d);
}
public interface IEvent<in A, in B, in C, in D, in E>
{
void Run(A a, B b, C c, D d, E e);
}
public interface IEvent<in A, in B, in C, in D, in E, in F>
{
void Run(A a, B b, C c, D d, E e, F f);
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: dab16cc3acc616f4880a9cd714ba9be0
timeCreated: 1477377275
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
namespace Hotfix
namespace Model
{
public static class GameObjectHelper
{
......
fileFormatVersion: 2
guid: aae5801bb8dddb648b2347dc09067765
timeCreated: 1498118314
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using LitJson;
using Model;
namespace Hotfix
namespace Model
{
public static class JsonHelper
{
......
fileFormatVersion: 2
guid: 25b701814ea3740488abe9098cd34040
timeCreated: 1498118586
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,7 +5,7 @@ namespace Model
{
public static class ResourceHelper
{
public static Object LoadResource(string bundleName, string prefab)
public static UnityEngine.Object LoadResource(string bundleName, string prefab)
{
string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(bundleName.ToLower() + ".unity3d", prefab);
UnityEngine.Object resource = AssetDatabase.LoadAssetAtPath(realPath[0], typeof(GameObject));
......
using System;
namespace Hotfix
namespace Model
{
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class ILBindingAttribute : Attribute
......
......@@ -50,6 +50,8 @@ namespace Model
private void Update()
{
ObjectEvents.Instance.Update();
this.AppDomain.Invoke(this.update, null, this.param0);
}
......
fileFormatVersion: 2
guid: 2fafa040b653b9847a9348a31a0233af
folderAsset: yes
timeCreated: 1498117781
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using System;
using Model;
namespace Hotfix
namespace Model
{
public abstract class AMHandler<Message>: IMHandler where Message : AMessage
{
......
namespace Hotfix
namespace Model
{
public abstract class AMessage
{
......
using System;
using System.Collections.Generic;
namespace Hotfix
namespace Model
{
[Flags]
public enum AppType
......
namespace Hotfix
namespace Model
{
public static class ErrorCode
{
......
using System;
namespace Hotfix
namespace Model
{
public interface IMHandler
{
......
using System;
namespace Hotfix
namespace Model
{
public class MessageAttribute: Attribute
{
......
using System;
namespace Hotfix
namespace Model
{
/// <summary>
/// 搭配MessageComponent用来分发消息
......
namespace Hotfix
namespace Model
{
public class MessageInfo
{
......
using System.Collections.Generic;
namespace Hotfix
namespace Model
{
public static class OpcodeHelper
{
......
using System;
namespace Hotfix
namespace Model
{
/// <summary>
/// RPC异常,带ErrorCode
......
fileFormatVersion: 2
guid: 600c9bb417aba1641897df52e4ea0eeb
folderAsset: yes
timeCreated: 1498116852
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
public abstract class Component: Disposer
{
[BsonIgnore]
public Entity Owner { get; set; }
public T GetOwner<T>() where T : Entity
{
return this.Owner as T;
}
protected Component()
{
}
protected Component(long id): base(id)
{
}
public T GetComponent<T>() where T : Component
{
return this.Owner.GetComponent<T>();
}
public override void Dispose()
{
if (this.Id == 0)
{
return;
}
base.Dispose();
this.Owner.RemoveComponent(this.GetType());
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 596cc447d1a588e47b6105622727b588
timeCreated: 1498116852
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace Model
{
public abstract class Disposer: Object
{
protected Disposer(): base(IdGenerater.GenerateId())
{
ObjectEvents.Instance.Add(this);
}
protected Disposer(long id): base(id)
{
ObjectEvents.Instance.Add(this);
}
public override void Dispose()
{
this.Id = 0;
ObjectEvents.Instance.Remove(this);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 785b1815942ba374b9cea238401cd506
timeCreated: 1498116853
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
namespace Model
{
public class Entity: Disposer
{
public EntityType Type { get; set; }
private HashSet<Component> components = new HashSet<Component>();
private readonly Dictionary<Type, Component> componentDict = new Dictionary<Type, Component>();
protected Entity()
{
this.Type = EntityType.None;
}
protected Entity(EntityType entityType)
{
this.Type = entityType;
}
protected Entity(long id, EntityType entityType): base(id)
{
this.Type = entityType;
}
public override void Dispose()
{
if (this.Id == 0)
{
return;
}
base.Dispose();
foreach (Component component in this.GetComponents())
{
try
{
component.Dispose();
}
catch (Exception e)
{
Log.Error(e.ToString());
}
}
}
public K AddComponent<K>() where K : Component, new()
{
K component = (K) Activator.CreateInstance(typeof (K));
component.Owner = this;
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
}
if (this.components == null)
{
this.components = new HashSet<Component>();
}
this.components.Add(component);
this.componentDict.Add(component.GetType(), component);
IAwake awake = component as IAwake;
awake?.Awake();
return component;
}
public K AddComponent<K, P1>(P1 p1) where K : Component, new()
{
K component = (K) Activator.CreateInstance(typeof (K));
component.Owner = this;
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
}
if (this.components == null)
{
this.components = new HashSet<Component>();
}
this.components.Add(component);
this.componentDict.Add(component.GetType(), component);
IAwake<P1> awake = component as IAwake<P1>;
awake?.Awake(p1);
return component;
}
public K AddComponent<K, P1, P2>(P1 p1, P2 p2) where K : Component, new()
{
K component = (K) Activator.CreateInstance(typeof (K));
component.Owner = this;
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
}
if (this.components == null)
{
this.components = new HashSet<Component>();
}
this.components.Add(component);
this.componentDict.Add(component.GetType(), component);
IAwake<P1, P2> awake = component as IAwake<P1, P2>;
awake?.Awake(p1, p2);
return component;
}
public K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Component, new()
{
K component = (K) Activator.CreateInstance(typeof (K));
component.Owner = this;
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
}
if (this.components == null)
{
this.components = new HashSet<Component>();
}
this.components.Add(component);
this.componentDict.Add(component.GetType(), component);
IAwake<P1, P2, P3> awake = component as IAwake<P1, P2, P3>;
awake?.Awake(p1, p2, p3);
return component;
}
public void RemoveComponent<K>() where K : Component
{
Component component;
if (!this.componentDict.TryGetValue(typeof (K), out component))
{
return;
}
this.components.Remove(component);
this.componentDict.Remove(typeof (K));
if (this.components.Count == 0)
{
this.components = null;
}
component.Dispose();
}
public void RemoveComponent(Type type)
{
Component component;
if (!this.componentDict.TryGetValue(type, out component))
{
return;
}
this.components.Remove(component);
this.componentDict.Remove(type);
if (this.components.Count == 0)
{
this.components = null;
}
component.Dispose();
}
public K GetComponent<K>() where K : Component
{
Component component;
if (!this.componentDict.TryGetValue(typeof (K), out component))
{
return default(K);
}
return (K) component;
}
public Component[] GetComponents()
{
return components.ToArray();
}
}
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册