/// <summary> /// 所有连接到服务器的客户端的会话 都会从这个方法中得到 /// </summary> /// <param name="channel">Channel.</param> public void OnAccept(AChannel channel) { Session session = ComponentFactory.CreateWithParent <Session, AChannel>(this, channel); this.sessions.Add(session.Id, session); session.Start(); }
public void OnAccept(AChannel channel) { Console.WriteLine("OnAccept:" + Thread.CurrentThread.ManagedThreadId); Session session = ComponentFactory.CreateWithParent <Session, NetworkComponent, AChannel>(this, this, channel); this.sessions.Add(session.Id, session); }
/// <summary> /// 加载一个bundle /// </summary> /// <param name="assetBundleName"></param> public void LoadOneBundle(string assetBundleName) { //Log.Debug($"---------------load one bundle {assetBundleName}"); ABInfo abInfo; if (this.bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; return; } if (!Define.IsAsync) { string[] realPath = null; #if UNITY_EDITOR realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); foreach (string s in realPath) { string assetName = Path.GetFileNameWithoutExtension(s); UnityEngine.Object resource = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s); AddResource(assetBundleName, assetName, resource); } abInfo = ComponentFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null); abInfo.Parent = this; this.bundles[assetBundleName] = abInfo; #endif return; } string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); AssetBundle assetBundle = null; if (File.Exists(p)) { assetBundle = AssetBundle.LoadFromFile(p); } else { p = Path.Combine(PathHelper.AppResPath, assetBundleName); assetBundle = AssetBundle.LoadFromFile(p); } if (assetBundle == null) { throw new Exception($"assets bundle not found: {assetBundleName}"); } if (!assetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 UnityEngine.Object[] assets = assetBundle.LoadAllAssets(); foreach (UnityEngine.Object asset in assets) { AddResource(assetBundleName, asset.name, asset); } } abInfo = ComponentFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle); this.bundles[assetBundleName] = abInfo; }
/// <summary> /// 创建一个新Session /// </summary> public Session Create(IPEndPoint ipEndPoint) { AChannel channel = this.Service.ConnectChannel(ipEndPoint); Session session = ComponentFactory.CreateWithParent <Session, AChannel>(this, channel); this.sessions.Add(session.Id, session); return(session); }
/// <summary> /// 创建一个新Session /// </summary> public Session Create(string address) { AChannel channel = this.Service.ConnectChannel(address); Session session = ComponentFactory.CreateWithParent <Session, AChannel>(this, channel); this.sessions.Add(session.Id, session); return(session); }
public virtual Component AddComponent(Type type) { if (this.componentDict.ContainsKey(type)) { throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {type.Name}"); } Component component = ComponentFactory.CreateWithParent(type, this); this.componentDict.Add(type, component); return(component); }
public Task <long> GetAsync(long key) { if (!this.lockDict.ContainsKey(key)) { this.locations.TryGetValue(key, out long instanceId); Log.Info($"location get key: {key} {instanceId}"); return(Task.FromResult(instanceId)); } LocationQueryTask task = ComponentFactory.CreateWithParent <LocationQueryTask, long>(this, key); this.AddTask(key, task); return(task.Task); }
private UnityGameObject Fetch(string path) { if (this.cachedPaths.TryGetValue(path, out UnityGameObject gameObject) && gameObject.Path == path) { return gameObject; } gameObject?.Dispose(); this.cachedPaths.Remove(path); gameObject = ComponentFactory.CreateWithParent<UnityGameObject, UnityEngine.GameObject>( this, UnityEngine.GameObject.Find(path)); this.cachedPaths[path] = gameObject; return gameObject; }
/// <summary> /// 异步请求位置 /// </summary> /// <param name="key"></param> /// <returns></returns> public Task <long> GetAsync(long key) { if (!this.lockDict.ContainsKey(key)) //如果这个位置没有在锁状态 { this.locations.TryGetValue(key, out long instanceId); //获取字典此key的值 Log.Info($"location get key: {key} {instanceId}"); return(Task.FromResult(instanceId)); //创建一个带返回值的、已完成的Task。 } LocationQueryTask task = ComponentFactory.CreateWithParent <LocationQueryTask, long>(this, key); this.AddTask(key, task); //添加到字典中缓存 待这个地址解锁后 会自动返回其新地址 return(task.Task); //等待位置转换完成 返回新的位置 }
public virtual K AddComponent <K, P1>(P1 p1) where K : Component, new() { Type type = typeof(K); if (this.componentDict.ContainsKey(type)) { throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } K component = ComponentFactory.CreateWithParent <K, P1>(this, p1); this.componentDict.Add(type, component); return(component); }
public K AddComponent <K, P1>(P1 p1) where K : Component, new() { K component = ComponentFactory.CreateWithParent <K, P1>(this, p1); if (this.componentDict.ContainsKey(component.GetType())) { throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } if (component is ISerializeToEntity) { this.components.Add(component); } this.componentDict.Add(component.GetType(), component); return(component); }
public Component AddComponent(Type type) { if (this.componentDict.ContainsKey(type)) { throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {type.Name}"); } Component component = ComponentFactory.CreateWithParent(type, this); if (component is ISerializeToEntity) { this.components.Add(component); } this.componentDict.Add(type, component); return(component); }
/// <summary> /// 创建一个Session /// </summary> public Session Create(string address) { //这里以TCP为例注释: //TCP的话 是调用TService的ConnectChannel 内部进行构建一个TChannel //注意:TChannel是对Socket的第一层封装,包括:连接、接收、发送、构建报文、拆解报文...为外部提供Socket交互的接口 AChannel channel = this.Service.ConnectChannel(address); //创建session会话实体 将自身作为session的父物体 并且把TChannel传递进去 Session session = ComponentFactory.CreateWithParent <Session, AChannel>(this, channel); //注意:框架会调用到session的Awake方法,并且将TChannel传递给Awake方法,然后才继续往下执行 //管理该会话实体 this.sessions.Add(session.Id, session); //调用会话实体的Start方法 session.Start(); return(session); }
public async ETTask <UI> InstantiateAsync(string uiName, string hierarchy) { GameObject go = await UnityEngine.AddressableAssets.Addressables.InstantiateAsync(uiName, this.layers[hierarchy].transform, false, true).Task; go.name = uiName; this.hierarchys.Add(uiName, hierarchy); UI ui = ComponentFactory.CreateWithParent <UI, string, GameObject>(this, uiName, go, false); ui.Canvas.worldCamera = this.Camera; ui.Canvas.sortingOrder = this.layers[hierarchy].transform.GetSiblingIndex(); ui.Canvas.enabled = false; this.uis.Add(uiName, ui); return(ui); }
/// <summary> /// 挂载组件 /// </summary> /// <param name="type">组件类型</param> /// <returns></returns> public virtual Component AddComponent(Type type) { if (this.componentDict.ContainsKey(type)) { throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {type.Name}"); } //从工厂生成组件 并制定其父实体 Component component = ComponentFactory.CreateWithParent(type, this); //如歌这个组件是序列化的实体 将其添加到哈希表中 if (component is ISerializeToEntity) { this.components.Add(component); } this.componentDict.Add(type, component); return(component); }
public async ETTask <CoroutineLock> Wait(CoroutineLockType coroutineLockType, long key) { CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType]; if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue)) { queue = ComponentFactory.Create <CoroutineLockQueue>(); coroutineLockQueueType.Add(key, queue); return(ComponentFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key)); } ETTaskCompletionSource <CoroutineLock> tcs = new ETTaskCompletionSource <CoroutineLock>(); queue.Enqueue(tcs); return(await tcs.Task); }
public K AddComponent <K>() where K : Component, new() { Type type = typeof(K); if (this.componentDict.ContainsKey(type)) { throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } K component = ComponentFactory.CreateWithParent <K>(this); if (component is ISerializeToEntity) { this.components.Add(component); } this.componentDict.Add(type, component); return(component); }
public void Notify(CoroutineLockType coroutineLockType, long key) { CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType]; if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue)) { throw new Exception($"first work notify not find queue"); } if (queue.Count == 0) { coroutineLockQueueType.Remove(key); queue.Dispose(); return; } ETTaskCompletionSource <CoroutineLock> tcs = queue.Dequeue(); tcs.SetResult(ComponentFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key)); }
public virtual K AddComponent <K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Component, new() { Type type = typeof(K); if (this.componentDict.ContainsKey(type)) { throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } K component = ComponentFactory.CreateWithParent <K, P1, P2, P3>(this, p1, p2, p3, this.IsFromPool); this.componentDict.Add(type, component); if (component is ISerializeToEntity) { this.components.Add(component); } return(component); }
public async ETTask LoadOneBundleAsync(string assetBundleName) { ABInfo abInfo; if (this.bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; return; } //Log.Debug($"---------------load one bundle {assetBundleName}"); if (!Define.IsAsync) { string[] realPath = null; #if UNITY_EDITOR realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); foreach (string s in realPath) { string assetName = Path.GetFileNameWithoutExtension(s); UnityEngine.Object resource = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s); AddResource(assetBundleName, assetName, resource); if (s.EndsWith(".png")) { UnityEngine.Object[] atlas = AssetDatabase.LoadAllAssetsAtPath(s); foreach (var asset in atlas) { AddResource(assetBundleName, asset.name, asset); } } } abInfo = ComponentFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null); this.bundles[assetBundleName] = abInfo; #endif return; } string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); AssetBundle assetBundle = null; if (!File.Exists(p)) { p = Path.Combine(PathHelper.AppResPath, assetBundleName); } using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = ComponentFactory.Create <AssetsBundleLoaderAsync>()) { assetBundle = await assetsBundleLoaderAsync.LoadAsync(p); } if (assetBundle == null) { throw new Exception($"assets bundle not found: {assetBundleName}"); } if (!assetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 UnityEngine.Object[] assets; using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create <AssetsLoaderAsync, AssetBundle>(assetBundle)) { assets = await assetsLoaderAsync.LoadAllAssetsAsync(); } foreach (UnityEngine.Object asset in assets) { AddResource(assetBundleName, asset.name, asset); } } abInfo = ComponentFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle); this.bundles[assetBundleName] = abInfo; }