public ActorProxy Get(long id) { if (this.ActorProxys.TryGetValue(id, out ActorProxy actorProxy)) { return(actorProxy); } actorProxy = ComponentFactory.CreateWithId <ActorProxy>(id); this.ActorProxys[id] = actorProxy; return(actorProxy); }
public virtual async Task <Session> Accept() { AChannel channel = await this.Service.AcceptChannel(); Session session = ComponentFactory.CreateWithId <Session, NetworkComponent, AChannel>(IdGenerater.GenerateId(), this, channel); session.Parent = this; channel.ErrorCallback += (c, e) => { this.Remove(session.Id); }; this.sessions.Add(session.Id, session); return(session); }
public Task <bool> Add(Component disposer, string collectionName = "") { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); this.AddToCache(disposer, collectionName); if (string.IsNullOrEmpty(collectionName)) { collectionName = disposer.GetType().Name; } DBSaveTask task = ComponentFactory.CreateWithId <DBSaveTask, Component, string, TaskCompletionSource <bool> >(disposer.Id, disposer, collectionName, tcs); this.tasks[(int)((ulong)task.Id % taskCount)].Add(task); return(tcs.Task); }
public Task <Component> Get(string collectionName, long id) { Component disposer = GetFromCache(collectionName, id); if (disposer != null) { return(Task.FromResult(disposer)); } TaskCompletionSource <Component> tcs = new TaskCompletionSource <Component>(); DBQueryTask dbQueryTask = ComponentFactory.CreateWithId <DBQueryTask, string, TaskCompletionSource <Component> >(id, collectionName, tcs); this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask); return(tcs.Task); }
/// <summary> /// 创建一个新Session /// </summary> public virtual Session Create(IPEndPoint ipEndPoint) { try { AChannel channel = this.Service.ConnectChannel(ipEndPoint); Session session = ComponentFactory.CreateWithId <Session, NetworkComponent, AChannel>(IdGenerater.GenerateId(), this, channel); session.Parent = this; channel.ErrorCallback += (c, e) => { this.Remove(session.Id); }; this.sessions.Add(session.Id, session); return(session); } catch (Exception e) { Log.Error(e.ToString()); return(null); } }
public static Unit Create(long id) { ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>(); GameObject bundleGameObject = resourcesComponent.GetAsset <GameObject>("Unit.unity3d", "Unit"); GameObject prefab = bundleGameObject.Get <GameObject>("Skeleton"); UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>(); Unit unit = ComponentFactory.CreateWithId <Unit>(id); unit.GameObject = UnityEngine.Object.Instantiate(prefab); GameObject parent = GameObject.Find($"/Global/Unit"); unit.GameObject.transform.SetParent(parent.transform, false); unit.AddComponent <AnimatorComponent>(); unit.AddComponent <MoveComponent>(); unitComponent.Add(unit); return(unit); }