public static Component Create(Entity behaviorTreeParent, HotfixAction hotfixAction) { try { var behaviorTreeConfig = (BehaviorTreeConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(BehaviorTreeConfig), hotfixAction.behaviorTreeConfigID); var type = Type.GetType($"ETHotfix.{behaviorTreeConfig.ComponentName}"); Component component = Game.ObjectPool.Fetch(type); ComponentWithId componentWithId = component as ComponentWithId; if (componentWithId != null) { componentWithId.Id = component.InstanceId; } Game.EventSystem.Awake(component, behaviorTreeParent, hotfixAction, behaviorTreeConfig); if (string.Equals(hotfixAction.FriendlyName, "Hotfix Action")) { hotfixAction.FriendlyName = behaviorTreeConfig.Name; } return(component); } catch (Exception e) { Log.Error(e); } return(null); }
protected override async ETTask Run(Session session, DBQueryRequest request, DBQueryResponse response, Action reply) { ComponentWithId component = await Game.Scene.GetComponent <DBComponent>().Get(request.CollectionName, request.Id); response.Component = component; reply(); }
public static T Create <T, A>(A a) where T : Component { T component = Game.ObjectPool.Fetch <T>(); ComponentWithId componentWithId = component as ComponentWithId; if (componentWithId != null) { componentWithId.Id = component.InstanceId; } Game.EventSystem.Awake(component, a); return(component); }
public static Component CreateWithParent(Type type, Component parent) { Component component = Game.ObjectPool.Fetch(type); component.Parent = parent; ComponentWithId componentWithId = component as ComponentWithId; if (componentWithId != null) { componentWithId.Id = component.InstanceId; } Game.EventSystem.Awake(component); return(component); }
public static T CreateWithParent <T, A, B, C>(Component parent, A a, B b, C c) where T : Component { T component = Game.ObjectPool.Fetch <T>(); component.Parent = parent; ComponentWithId componentWithId = component as ComponentWithId; if (componentWithId != null) { componentWithId.Id = component.InstanceId; } Game.EventSystem.Awake(component, a, b, c); return(component); }
public static Component CreateWithParent <P1, P2, P3>(Type type, Component parent, P1 p1, P2 p2, P3 p3) { Component component = Game.ComObjectPool.Fetch(type); component.Parent = parent; ComponentWithId componentWithId = component as ComponentWithId; if (componentWithId != null) { componentWithId.Id = component.InstanceId; } Game.EventSystem.Awake(component, p1, p2, p3); return(component); }
protected async ETVoid RunAsync(Session session, DBQueryRequest message, Action <DBQueryResponse> reply) { DBQueryResponse response = new DBQueryResponse(); try { ComponentWithId component = await Game.Scene.GetComponent <DBComponent>().Get(message.CollectionName, message.Id); response.Component = component; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected async ETVoid RunAsync(Session session, CacheQueryByUniqueRequest message, Action <CacheQueryResponse> reply) { CacheQueryResponse response = new CacheQueryResponse(); try { ComponentWithId component = await Game.Scene.GetComponent <CacheComponent>().QueryByUnique(message.CollectionName, message.UniqueName, message.Json); response.Component = component; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected async ETTask RunAsync(Session session, CacheUpdateByIdRequest message, Action <CacheQueryResponse> reply) { CacheQueryResponse response = new CacheQueryResponse(); try { ComponentWithId component = await Game.Scene.GetComponent <CacheComponent>().UpdateById(message.CollectionName, message.Id, message.DataJson); response.Component = component; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static async ETTask SaveLogBatch(this DBProxyComponent self, long uid, DBLog.LogType logType, List <ComponentWithId> components) { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); List <ComponentWithId> list = new List <ComponentWithId>(); for (int i = 0; i < components.Count; i++) { ComponentWithId record = null; DBLog dBLog = ComponentFactory.CreateWithId <DBLog>(IdGenerater.GenerateId()); dBLog.uid = uid; dBLog.logType = (int)logType; BsonDocument doc = null; BsonDocument.TryParse(record.ToJson(), out doc); dBLog.document = doc; dBLog.createAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); list.Add(dBLog); } await self.SaveBatch(list); }
public static async ETTask Load(this RedisEventSolverComponent self, long id) { var propNames = CacheHelper.GetSyncPropertyNames(self.type); ComponentWithId entity = await self.cacheProxyComponent.QueryById <ComponentWithId>(self.collectionName, id, propNames.Count == 0?null : propNames); if (entity != null) { self.Write(id, entity); self.onRefresh?.Invoke(id); } else { if (self.Data.TryGetValue(id, out var component)) { component.Dispose(); self.Data.Remove(id); self.mineSet.Remove(id); self.onRefresh?.Invoke(id); } } }
public static void Write(this RedisEventSolverComponent self, long id, ComponentWithId src) { if (self.Data.TryGetValue(id, out var des)) { var propNames = CacheHelper.GetSyncPropertyNames(self.type); for (int i = 0; i < propNames.Count; i++) { string propName = propNames[i]; PropertyInfo property = CacheHelper.GetSyncPropertyInfo(self.type, propName); object val = property.GetValue(src); property.SetValue(des, val); } } else { // 保險起見,避免Redis同步來的資料沒有id src.Id = id; // 如果有定義[ObjectSystem]就附加事件(Awake[必需提供一個無參數Awake]、Update等等) // 但帶有SyncIgnore的欄位會被忽略,所以只有擁有者才可以預先對這先欄位指派值,並且 // 也只有擁有者能使用這些值,其他人擁有的都是初始值:null、0等等,直接拿來使用會有問題的 if (self.isToUseObjectSystem) { var component = ComponentFactory.CreateWithId(self.type, src.Id); var propNames = CacheHelper.GetSyncPropertyNames(self.type); for (int i = 0; i < propNames.Count; i++) { string propName = propNames[i]; PropertyInfo property = CacheHelper.GetSyncPropertyInfo(self.type, propName); object val = property.GetValue(src); property.SetValue(component, val); } self.Data[id] = (ComponentWithId)component; } else { self.Data[id] = src; } } }
protected override async ETTask Run(Session session, DBQueryRequest request, DBQueryResponse response, Action reply) { try { DBCacheComponent dbCacheComponent = Game.Scene.GetComponent <DBCacheComponent>(); ComponentWithId component = await dbCacheComponent.Get(request.CollectionName, request.Id); response.Component = component; if (request.NeedCache && component != null) { dbCacheComponent.AddToCache(component, request.CollectionName); } reply(); await ETTask.CompletedTask; } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, DBQueryRequest message, Action <DBQueryResponse> reply) { DBQueryResponse response = new DBQueryResponse(); try { DBCacheComponent dbCacheComponent = Game.Scene.GetComponent <DBCacheComponent>(); ComponentWithId component = await dbCacheComponent.Get(message.CollectionName, message.Id); response.Component = component; if (message.NeedCache && component != null) { dbCacheComponent.AddToCache(component, message.CollectionName); } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static async ETVoid SaveLog(this DBProxyComponent self, ComponentWithId component) { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); await session.Call(new DBSaveRequest { Component = component, NeedCache = false, CollectionName = "Log" }); }
public static async ETTask Save(this DBProxyComponent self, ComponentWithId component, bool needCache, CancellationToken cancellationToken) { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); await session.Call(new DBSaveRequest { Component = component, NeedCache = needCache }, cancellationToken); }
//存储到数据库 public static async Task SaveDB(this FriendsCircleComponent friendsCircleComponent, ComponentWithId component) { await friendsCircleComponent.dbProxyComponent.Save(component); }
public static async ETTask SaveLog(this DBProxyComponent self, long uid, DBLog.LogType logType, ComponentWithId record) { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); DBLog dBLog = ComponentFactory.CreateWithId <DBLog>(IdGenerater.GenerateId()); dBLog.uid = uid; dBLog.logType = (int)logType; BsonDocument doc = null; BsonDocument.TryParse(record.ToJson(), out doc); dBLog.document = doc; dBLog.createAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); await self.SaveLog(dBLog); }
public static async ETTask Save(this DBProxyComponent self, ComponentWithId component) { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); await session.Call(new DBSaveRequest { Component = component, CollectionName = "UserInfo" }); }