public static async ETTask <RobotCase> New(this RobotCaseComponent self) { await ETTask.CompletedTask; RobotCase robotCase = EntityFactory.CreateWithParent <RobotCase>(self); return(robotCase); }
public async ETTask <bool> WaitAsync(long time, ETCancellationToken cancellationToken) { long tillTime = TimeHelper.Now() + time; if (TimeHelper.Now() > tillTime) { return(true); } ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>(); OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource <bool> >(this, tcs); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); long instanceId = timer.InstanceId; cancellationToken.Register(() => { if (instanceId != timer.InstanceId) { return; } timer.Run(false); this.Remove(timer.Id); }); return(await tcs.Task); }
public async ETTask <bool> WaitTillAsync(long tillTime, ETCancellationToken cancellationToken = null) { if (TimeHelper.ServerNow() >= tillTime) { return(true); } ETTask <bool> tcs = ETTask <bool> .Create(true); TimerAction timer = EntityFactory.CreateWithParent <TimerAction, TimerClass, long, object>(this, TimerClass.OnceWaitTimer, 0, tcs, true); this.AddTimer(tillTime, timer); long timerId = timer.Id; void CancelAction() { if (this.Remove(timerId)) { tcs.SetResult(false); } } bool ret; try { cancellationToken?.Add(CancelAction); ret = await tcs; } finally { cancellationToken?.Remove(CancelAction); } return(ret); }
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 virtual Session OnAccept(AChannel channel) { Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel); this.Sessions.Add(session.Id, session); channel.Start(); return(session); }
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); }
/// <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); }
/// <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); }
public async ETTask <bool> WaitAsync(long time) { long tillTime = TimeHelper.Now() + time; ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>(); OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource <bool> >(this, tcs); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(await tcs.Task); }
public override async ETTask <UI> OnCreate(UIComponent uiComponent) { ResourcesComponent.Instance.LoadBundle(UIType.UILobby.StringToAB()); GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset(UIType.UILobby.StringToAB(), UIType.UILobby); GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject); UI ui = EntityFactory.CreateWithParent <UI, string, GameObject>(uiComponent, UIType.UILobby, gameObject); ui.AddComponent <UILobbyComponent>(); return(ui); }
public long NewOnceTimer(long tillTime, Action action) { if (tillTime < TimeHelper.ServerNow()) { Log.Error($"new once time too small: {tillTime}"); } TimerAction timer = EntityFactory.CreateWithParent <TimerAction, TimerClass, long, object>(this, TimerClass.OnceTimer, 0, action, true); this.AddTimer(tillTime, timer); return(timer.Id); }
public static async ETTask <UI> InstantiateFromBundle(UIComponent uiComponent, string uiBundle) { await ResourcesComponent.Instance.LoadBundleAsync(uiBundle.StringToAB()); GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset(uiBundle.StringToAB(), uiBundle); GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject); UI ui = EntityFactory.CreateWithParent <UI, string, GameObject>(uiComponent, uiBundle, gameObject); return(ui); }
/// <summary> /// 创建一个RepeatedTimer /// </summary> private long NewRepeatedTimerInner(long time, Action action) { #if NOT_CLIENT if (time < 100) { throw new Exception($"repeated timer < 100, timerType: time: {time}"); } #endif long tillTime = TimeHelper.ServerNow() + time; TimerAction timer = EntityFactory.CreateWithParent <TimerAction, TimerClass, long, object>(this, TimerClass.RepeatedTimer, time, action, true); this.AddTimer(tillTime, timer); return(timer.Id); }
/// <summary> /// 创建一个RepeatedTimer /// </summary> /// <param name="time"></param> /// <param name="action"></param> /// <returns></returns> public long NewRepeatedTimer(long time, Action <bool> action) { if (time < 30) { throw new Exception($"repeated time < 30"); } long tillTime = TimeHelper.Now() + time; RepeatedTimer timer = EntityFactory.CreateWithParent <RepeatedTimer, long, Action <bool> >(this, time, action); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(timer.Id); }
public override async ETTask <UI> OnCreate(UIComponent uiComponent) { await ETTask.CompletedTask; ResourcesComponent.Instance.LoadBundle(UIType.UILogin.StringToAB()); UnityEngine.Object bundleGameObject = ResourcesComponent.Instance.GetAsset(UIType.UILogin.StringToAB(), UIType.UILogin); GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject) as GameObject; UI ui = EntityFactory.CreateWithParent <UI, string, GameObject>(uiComponent, UIType.UILogin, gameObject); ui.AddComponent <UILoginComponent>(); return(ui); }
public async 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(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key)); } ETTaskCompletionSource <CoroutineLock> tcs = new ETTaskCompletionSource <CoroutineLock>(); queue.Enqueue(tcs); return(await tcs.Task); }
public override async ETTask <UI> OnCreate(UIComponent uiComponent) { try { GameObject bundleGameObject = ((GameObject)Resources.Load("KV")).Get <GameObject>(UIType.UILoading); GameObject go = UnityEngine.Object.Instantiate(bundleGameObject); go.layer = LayerMask.NameToLayer(LayerNames.UI); UI ui = EntityFactory.CreateWithParent <UI, string, GameObject>(uiComponent, UIType.UILoading, go); ui.AddComponent <UILoadingComponent>(); return(ui); } catch (Exception e) { Log.Error(e); return(null); } }
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)); }
public static Skill Create(Entity parent, int configid) { Skill skill = EntityFactory.CreateWithParent <Skill, int>(parent, configid); return(skill); }
private async ETTask LoadOneBundleAsync(string assetBundleName, bool isScene) { assetBundleName = assetBundleName.BundleNameToLower(); ABInfo abInfo; if (this.bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); return; } string p = ""; AssetBundle assetBundle = null; if (!Define.IsAsync) { #if UNITY_EDITOR if (isScene) { p = Path.Combine(Application.dataPath, "../../AssetBundles/Windows_Scene/", assetBundleName); if (File.Exists(p)) // 如果场景有预先打包 { using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = EntityFactory.CreateWithParent <AssetsBundleLoaderAsync>(this)) { assetBundle = await assetsBundleLoaderAsync.LoadAsync(p); } if (assetBundle == null) { // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功 Log.Warning($"Scene bundle not found: {assetBundleName}"); return; } abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle); this.bundles[assetBundleName] = abInfo; } } else { string[] 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 (realPath.Length > 0) { abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null); this.bundles[assetBundleName] = abInfo; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); } else { Log.Error("Bundle not exist! BundleName: " + assetBundleName); } } // 编辑器模式也不能同步加载 await TimerComponent.Instance.WaitAsync(20); #endif return; } p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); if (!File.Exists(p)) { p = Path.Combine(PathHelper.AppResPath, assetBundleName); } if (!File.Exists(p)) { Log.Error("Async load bundle not exist! BundleName : " + p); return; } using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = EntityFactory.CreateWithParent <AssetsBundleLoaderAsync>(this)) { assetBundle = await assetsBundleLoaderAsync.LoadAsync(p); } if (assetBundle == null) { // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功 Log.Warning($"assets bundle not found: {assetBundleName}"); return; } if (!assetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 UnityEngine.Object[] assets; using (AssetsLoaderAsync assetsLoaderAsync = EntityFactory.CreateWithParent <AssetsLoaderAsync, AssetBundle>(this, assetBundle)) { assets = await assetsLoaderAsync.LoadAllAssetsAsync(); } foreach (UnityEngine.Object asset in assets) { AddResource(assetBundleName, asset.name, asset); } } abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle); this.bundles[assetBundleName] = abInfo; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); }
private async ETTask <ABInfo> LoadOneBundleAsync(string assetBundleName) { assetBundleName = assetBundleName.BundleNameToLower(); ABInfo abInfo; if (this.bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); return(null); } string p = ""; AssetBundle assetBundle = null; if (!Define.IsAsync) { #if UNITY_EDITOR string[] 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 (realPath.Length > 0) { abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null); this.bundles[assetBundleName] = abInfo; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); } else { Log.Error("Bundle not exist! BundleName: " + assetBundleName); } // 编辑器模式也不能同步加载 await TimerComponent.Instance.WaitAsync(100); #endif return(abInfo); } p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); if (!File.Exists(p)) { p = Path.Combine(PathHelper.AppResPath, assetBundleName); } Log.Debug("Async load bundle BundleName : " + p); // if (!File.Exists(p)) // { // Log.Error("Async load bundle not exist! BundleName : " + p); // return null; // } assetBundle = await AssetBundleHelper.UnityLoadBundleAsync(p); if (assetBundle == null) { // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功 Log.Warning($"assets bundle not found: {assetBundleName}"); return(null); } abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle); this.bundles[assetBundleName] = abInfo; return(abInfo); //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); }
private void LoadOneBundle(string assetBundleName) { assetBundleName = assetBundleName.BundleNameToLower(); ABInfo abInfo; if (this.bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); return; } if (!Define.IsAsync) { #if UNITY_EDITOR string[] realPath = null; 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 (realPath.Length > 0) { abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null); this.bundles[assetBundleName] = abInfo; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); } else { Log.Error($"assets bundle not found: {assetBundleName}"); } #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) { // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功 Log.Warning($"assets bundle not found: {assetBundleName}"); return; } if (!assetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 var 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; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); }
public static Trigger Create(Entity parent, TriggerType type) { Trigger trigger = EntityFactory.CreateWithParent <Trigger, TriggerType>(parent, type); return(trigger); }