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 = EntityFactory.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)) { 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 = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle); this.bundles[assetBundleName] = abInfo; }
public long NewOnceTimer(long tillTime, Action action) { OnceTimer timer = EntityFactory.CreateWithParent <OnceTimer, Action>(this, action); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(timer.Id); }
public virtual Session OnAccept(AChannel channel) { Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel); this.Sessions.Add(session.Id, session); channel.Start(); return(session); }
/// <summary> /// 创建一个新Session /// </summary> public Session Create(string address) { AChannel channel = this.Service.ConnectChannel(address); Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel); this.Sessions.Add(session.Id, session); channel.Start(); return(session); }
/// <summary> /// 创建一个新Session /// </summary> public Session Create(IPEndPoint ipEndPoint) { AChannel channel = this.Service.ConnectChannel(ipEndPoint); Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel); this.Sessions.Add(session.Id, session); channel.Start(); return(session); }
public ETTask WaitAsync(long time) { long tillTime = TimeHelper.Now() + time; ETTaskCompletionSource tcs = new ETTaskCompletionSource(); OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource>(this, tcs); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(tcs.Task); }
/// <summary> /// 创建一个RepeatedTimer /// </summary> /// <param name="time"></param> /// <param name="action"></param> /// <returns></returns> public long NewRepeatedTimer(long time, Action action) { if (time < 30) { throw new Exception($"repeated time < 30"); } long tillTime = TimeHelper.Now() + time; RepeatedTimer timer = EntityFactory.CreateWithParent <RepeatedTimer, long, Action>(this, time, action); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(timer.Id); }
public ETTask WaitTillAsync(long tillTime, ETCancellationToken cancellationToken) { if (TimeHelper.Now() > tillTime) { return(ETTask.CompletedTask); } ETTaskCompletionSource tcs = new ETTaskCompletionSource(); OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource>(this, tcs); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); cancellationToken.Register(() => { this.Remove(timer.Id); }); return(tcs.Task); }
public ETTask <CoroutineLock> Wait(CoroutineLockType coroutineLockType, long key) { CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType]; if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue)) { queue = EntityFactory.Create <CoroutineLockQueue>(this.Domain); coroutineLockQueueType.Add(key, queue); return(ETTask.FromResult(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key))); } ETTaskCompletionSource <CoroutineLock> tcs = new ETTaskCompletionSource <CoroutineLock>(); queue.Enqueue(tcs); return(tcs.Task); }
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(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key)); }