private void RemoveConnectTimeoutChannels() { using (ListComponent <long> waitRemoveChannels = ListComponent <long> .Create()) { foreach (long channelId in this.waitConnectChannels.Keys) { this.waitConnectChannels.TryGetValue(channelId, out KChannel kChannel); if (kChannel == null) { Log.Error($"RemoveConnectTimeoutChannels not found kchannel: {channelId}"); continue; } // 连接上了要马上删除 if (kChannel.IsConnected) { waitRemoveChannels.List.Add(channelId); } // 10秒连接超时 if (this.TimeNow > kChannel.CreateTime + 10 * 1000) { waitRemoveChannels.List.Add(channelId); } } foreach (long channelId in waitRemoveChannels.List) { this.waitConnectChannels.Remove(channelId); } } }
public override void Destroy(ResourcesLoaderComponent self) { async ETTask UnLoadAsync() { using (ListComponent <string> list = ListComponent <string> .Create()) { list.List.AddRange(self.LoadedResource); self.LoadedResource = null; // 延迟5秒卸载包,因为包卸载是引用技术,5秒之内假如重新有逻辑加载了这个包,那么可以避免一次卸载跟加载 await TimerComponent.Instance.WaitAsync(5000); foreach (string abName in list.List) { using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.ResourcesLoader, abName.GetHashCode(), 0)) { if (ResourcesComponent.Instance == null) { return; } await ResourcesComponent.Instance.UnloadBundleAsync(abName); } } } } UnLoadAsync().Coroutine(); }
//销毁指定窗口所有窗口 public static async ETTask DestroyWindowExceptNames(this UIManagerComponent self, string[] type_names = null) { Dictionary <string, bool> dict_ui_names = new Dictionary <string, bool>(); if (type_names != null) { for (int i = 0; i < type_names.Length; i++) { dict_ui_names[type_names[i]] = true; } } var keys = self.windows.Keys.ToArray(); using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create()) { for (int i = self.windows.Count - 1; i >= 0; i--) { if (!dict_ui_names.ContainsKey(keys[i])) { TaskScheduler.Add(self.DestroyWindow(keys[i])); } } await ETTaskHelper.WaitAll(TaskScheduler); } }
/// <summary> /// 获取所有指定类型单位的碰撞器 /// </summary> /// <param name="self"></param> /// <param name="types"></param> /// <param name="except"></param> /// <returns></returns> public static ListComponent <AOITriggerComponent> GetAllCollider(this AOICell self, List <UnitType> types, AOITriggerComponent except) { var res = ListComponent <AOITriggerComponent> .Create(); if (self.IsDisposed) { return(res); } var isAll = types.Contains(UnitType.ALL); for (int i = self.Triggers.Count - 1; i >= 0; i--) { var item = self.Triggers[i]; if (item.IsDisposed) { self.Triggers.RemoveAt(i); Log.Warning("自动移除不成功"); continue; } if (!item.IsCollider || item == except) { continue; } if (isAll || types.Contains(item.GetParent <AOIUnitComponent>().Type)) { // Log.Info("GetAllUnit key:"+item.Key); res.Add(item); } } return(res); }
public async ETTask Publish <T>(T a) where T : struct { List <object> iEvents; if (!this.allEvents.TryGetValue(typeof(T), out iEvents)) { return; } using (var list = ListComponent <ETTask> .Create()) { foreach (object obj in iEvents) { if (!(obj is AEvent <T> aEvent)) { Log.Error($"event error: {obj.GetType().Name}"); continue; } list.List.Add(aEvent.Handle(a)); } try { await ETTaskHelper.WaitAll(list.List); } catch (Exception e) { Log.Error(e); } } }
public static async ETTask CloseWindowByLayer(this UIManagerComponent self, UILayerNames layer, params string[] except_ui_names) { Dictionary <string, bool> dict_ui_names = null; if (except_ui_names != null && except_ui_names.Length > 0) { dict_ui_names = new Dictionary <string, bool>(); for (int i = 0; i < except_ui_names.Length; i++) { dict_ui_names[except_ui_names[i]] = true; } } using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create()) { foreach (var item in self.windows) { if (item.Value.Layer == layer && (dict_ui_names == null || !dict_ui_names.ContainsKey(item.Key))) { TaskScheduler.Add(self.CloseWindow(item.Key)); } } await ETTaskHelper.WaitAll(TaskScheduler); } }
public static async ETTask Init(this TargetSelectComponent self) { string path = "GameAssets/SkillPreview/Prefabs/TargetSelectManager.prefab"; string targetPath = "GameAssets/SkillPreview/Prefabs/TargetIcon.prefab"; using (ListComponent <ETTask <GameObject> > tasks = ListComponent <ETTask <GameObject> > .Create()) { tasks.Add(GameObjectPoolComponent.Instance.GetGameObjectAsync(targetPath, (obj) => { self.CursorImage = obj.GetComponent <Image>(); self.CursorImage.transform.parent = UIManagerComponent.Instance.GetLayer(UILayerNames.TipLayer).transform; self.CursorImage.transform.localPosition = Vector3.zero; self.CursorImage.rectTransform.anchoredPosition = Input.mousePosition; })); tasks.Add(GameObjectPoolComponent.Instance.GetGameObjectAsync(path, (obj) => { self.RangeCircleObj = obj.transform.Find("RangeCircle").gameObject; self.gameObject = obj; })); await ETTaskHelper.WaitAll(tasks); self.waiter.SetResult(self.gameObject); self.waiter = null; } }
public static bool ChangeSpeed(this MoveComponent self, float speed) { if (self.IsArrived()) { return(false); } if (speed < 0.0001) { return(false); } Unit unit = self.GetParent <Unit>(); using (ListComponent <Vector3> path = ListComponent <Vector3> .Create()) { self.MoveForward(true); path.List.Add(unit.Position); // 第一个是Unit的pos for (int i = self.N; i < self.Targets.Count; ++i) { path.List.Add(self.Targets[i]); } self.MoveToAsync(path.List, speed).Coroutine(); } return(true); }
public static ListComponent <T> Create() { ListComponent <T> listComponent = ObjectPool.Instance.Fetch <ListComponent <T> >(); listComponent.isDispose = false; return(listComponent); }
public override void Awake(PathComponent self) { self.Path = ListComponent <Vector3> .Create(); self.ServerPos = Vector3.zero; self.CancellationTokenSource = null; }
public override void Awake(SkillComponent self) { self.Skills = ListComponent <Skill> .Create(); self.EndSkills = ListComponent <Skill> .Create(); self.InitSkills(); }
/// <summary> /// 获取自身为中心指定圈数的所有格子 /// </summary> /// <param name="self"></param> /// <param name="turnNum">圈数</param> /// <returns></returns> public static ListComponent <AOICell> GetNearbyGrid(this AOICell self, int turnNum) { var scene = self.DomainScene().GetComponent <AOISceneComponent>(); if (scene == null) { return(ListComponent <AOICell> .Create()); } return(scene.GetNearbyGrid(turnNum, self.posx, self.posy)); }
/// <summary> /// 获取周围指定圈数指定类型AOI对象 /// </summary> /// <param name="self"></param> /// <param name="turnNum"></param> /// <param name="type"></param> /// <returns></returns> public static ListComponent <AOIUnitComponent> GetNearbyUnit(this AOIUnitComponent self, int turnNum = 1, UnitType type = UnitType.ALL) { if (turnNum < 0) { turnNum = self.Range; } if (self.Cell != null) { return(self.Cell.GetNearbyUnit(turnNum, type)); } return(ListComponent <AOIUnitComponent> .Create()); }
/// <summary> /// 获取自身为中心指定圈数的所有格子的所有指定类型单位 /// </summary> /// <param name="self"></param> /// <param name="type"></param> /// <returns></returns> public static ListComponent <AOIUnitComponent> GetNearbyUnit(this AOICell self, int turnNum, UnitType type = UnitType.ALL) { var grid = self.GetNearbyGrid(turnNum); if (grid != null) { var res = grid.GetAllUnit(type); grid.Dispose(); return(res); } return(ListComponent <AOIUnitComponent> .Create()); }
/// <summary> /// 获取周围指定圈数指定类型AOI对象 /// </summary> /// <param name="self"></param> /// <param name="turnNum"></param> /// <param name="type"></param> /// <returns></returns> public static ListComponent <AOICell> GetNearbyGrid(this AOIUnitComponent self, int turnNum = 1) { if (turnNum < 0) { turnNum = self.Range; } if (self.Cell != null) { return(self.Cell.GetNearbyGrid(turnNum)); } return(ListComponent <AOICell> .Create()); }
public static async ETTask DestroyAllWindow(this UIManagerComponent self) { var keys = self.windows.Keys.ToArray(); using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create()) { for (int i = self.windows.Count - 1; i >= 0; i--) { TaskScheduler.Add(self.DestroyWindow(self.windows[keys[i]].Name)); } await ETTaskHelper.WaitAll(TaskScheduler); } }
public override void Awake(SceneLoadComponent self) { self.PreLoadTask = ListComponent <ETTask> .Create(); self.Paths = ListComponent <string> .Create(); self.Types = ListComponent <int> .Create(); self.ObjCount = DictionaryComponent <string, int> .Create(); self.Total = 0; self.FinishCount = 0; }
/// <summary> /// 异步加载assetbundle, 加载ab包分两部分,第一部分是从硬盘加载,第二部分加载all assets。两者不能同时并发 /// </summary> public static async ETTask LoadBundleAsync(this ResourcesComponent self, string assetBundleName) { assetBundleName = assetBundleName.BundleNameToLower(); string[] dependencies = self.GetSortedDependencies(assetBundleName); //Log.Debug($"-----------dep load async start {assetBundleName} dep: {dependencies.ToList().ListToString()}"); using (ListComponent <ABInfo> abInfos = ListComponent <ABInfo> .Create()) { async ETTask LoadDependency(string dependency, List <ABInfo> abInfosList) { CoroutineLock coroutineLock = null; try { coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, dependency.GetHashCode()); ABInfo abInfo = await self.LoadOneBundleAsync(dependency); if (abInfo == null || abInfo.RefCount > 1) { return; } abInfosList.Add(abInfo); } finally { coroutineLock?.Dispose(); } } // LoadFromFileAsync部分可以并发加载 using (ListComponent <ETTask> tasks = ListComponent <ETTask> .Create()) { foreach (string dependency in dependencies) { tasks.Add(LoadDependency(dependency, abInfos)); } await ETTaskHelper.WaitAll(tasks); // ab包从硬盘加载完成,可以再并发加载all assets tasks.Clear(); foreach (ABInfo abInfo in abInfos) { tasks.Add(self.LoadOneBundleAllAssets(abInfo)); } await ETTaskHelper.WaitAll(tasks); } } }
/// <summary> /// 销毁隐藏状态的窗口 /// </summary> /// <param name="self"></param> public static async ETTask DestroyUnShowWindow(this UIManagerComponent self) { using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create()) { foreach (var key in self.windows.Keys.ToList()) { if (!self.windows[key].Active) { TaskScheduler.Add(self.DestroyWindow(key)); } } await ETTaskHelper.WaitAll(TaskScheduler); } }
public static void UpdateTriggers(this Skill self) { ListComponent <long> deleteList = ListComponent <long> .Create(); DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>(); // 刷新MonitorList for (int i = 0; i < self.MonitorList.List.Count; i++) { DUnit unit = dUnitComponent.Get(self.MonitorList.List[i]); if (unit == null) { deleteList.List.Add(unit.Id); continue; } if (unit.GetComponent <UnitStateComponent>().UnitState == (int)UnitState.Death) { deleteList.List.Add(unit.Id); } } for (int i = 0; i < deleteList.List.Count; i++) { self.MonitorList.List.Remove(deleteList.List[i]); } deleteList.List.Clear(); // 刷新MonitorList for (int i = 0; i < self.DamageList.List.Count; i++) { DUnit unit = dUnitComponent.Get(self.DamageList.List[i]); if (unit == null) { deleteList.List.Add(unit.Id); continue; } if (unit.GetComponent <UnitStateComponent>().UnitState == (int)UnitState.Death) { deleteList.List.Add(unit.Id); } } for (int i = 0; i < deleteList.List.Count; i++) { self.DamageList.List.Remove(deleteList.List[i]); } deleteList.List.Clear(); }
protected override async ETVoid Run(Session session, M2C_DPathfindingResult message) { DUnit unit = session.Domain.GetComponent <DUnitComponent>().Get(message.Id); Vector3 servierpos = new Vector3(message.X, message.Y, message.Z); using var list = ListComponent <Vector3> .Create(); for (int i = 0; i < message.Xs.Count; ++i) { list.List.Add(new Vector3(message.Xs[i], message.Ys[i], message.Zs[i])); } await DMoveAction.MoveActionImpAsync(unit, list.List.ToArray(), servierpos); }
/// <summary> /// 获取指定位置为中心指定圈数的所有格子 /// </summary> /// <param name="self"></param> /// <param name="turnNum"></param> /// <param name="posx"></param> /// <param name="posy"></param> /// <returns></returns> public static ListComponent <AOICell> GetNearbyGrid(this AOISceneComponent self, int turnNum, int posx, int posy) { ListComponent <AOICell> res = ListComponent <AOICell> .Create(); for (int i = 0; i <= turnNum * 2 + 1; i++) { var x = posx - turnNum + i; for (int j = 0; j <= turnNum * 2 + 1; j++) { var y = posy - turnNum + j; res.Add(self.GetCell(x, y)); } } return(res); }
//预加载一系列资源 public static async ETTask LoadDependency(this GameObjectPoolComponent self, List <string> res) { if (res.Count <= 0) { return; } using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create()) { for (int i = 0; i < res.Count; i++) { TaskScheduler.Add(self.PreLoadGameObjectAsync(res[i], 1)); } await ETTaskHelper.WaitAll(TaskScheduler); } }
protected override async ETVoid Run(Session session, M2C_PathfindingResult message) { Unit unit = session.Domain.GetComponent <UnitComponent>().Get(message.Id); float speed = unit.GetComponent <NumericComponent>().GetAsFloat(NumericType.Speed); using var list = ListComponent <Vector3> .Create(); for (int i = 0; i < message.Xs.Count; ++i) { list.List.Add(new Vector3(message.Xs[i], message.Ys[i], message.Zs[i])); } await unit.GetComponent <MoveComponent>().MoveToAsync(list.List, speed); }
//销毁指定层级外层级所有窗口 public static async ETTask DestroyWindowExceptLayer(this UIManagerComponent self, UILayerNames layer) { var keys = self.windows.Keys.ToArray(); using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create()) { for (int i = self.windows.Count - 1; i >= 0; i--) { if (self.windows[keys[i]].Layer != layer) { TaskScheduler.Add(self.DestroyWindow(keys[i])); } } await ETTaskHelper.WaitAll(TaskScheduler); } }
/// <summary> /// 获取所有指定类型单位 /// </summary> /// <param name="self"></param> /// <param name="types"></param> /// <returns></returns> public static ListComponent <AOIUnitComponent> GetAllUnit(this AOICell self, List <UnitType> types) { var res = ListComponent <AOIUnitComponent> .Create(); var isAll = types.Contains(UnitType.ALL); foreach (var item in self.idUnits) { if (types.Contains(item.Key) || isAll) { // Log.Info("GetAllUnit key:"+item.Key); res.AddRange(item.Value); } } return(res); }
public async ETTask Run(ModeContex contex, string content) { switch (content) { case ConsoleMode.CreateRobot: Log.Console("CreateRobot args error!"); break; default: CreateRobotArgs options = null; Parser.Default.ParseArguments <CreateRobotArgs>(content.Split(' ')) .WithNotParsed(error => throw new Exception($"CreateRobotArgs error!")) .WithParsed(o => { options = o; }); // 获取当前进程的RobotScene using (ListComponent <StartSceneConfig> thisProcessRobotScenes = ListComponent <StartSceneConfig> .Create()) { List <StartSceneConfig> robotSceneConfigs = StartSceneConfigCategory.Instance.Robots; foreach (StartSceneConfig robotSceneConfig in robotSceneConfigs) { if (robotSceneConfig.Process != Game.Options.Process) { continue; } thisProcessRobotScenes.Add(robotSceneConfig); } // 创建机器人 for (int i = 0; i < options.Num; ++i) { int index = i % thisProcessRobotScenes.Count; StartSceneConfig robotSceneConfig = thisProcessRobotScenes[index]; Scene robotScene = Game.Scene.Get(robotSceneConfig.Id); RobotManagerComponent robotManagerComponent = robotScene.GetComponent <RobotManagerComponent>(); Scene robot = await robotManagerComponent.NewRobot(Game.Options.Process * 10000 + i); robot.AddComponent <AIComponent, int>(1); Log.Console($"create robot {robot.Zone}"); await TimerComponent.Instance.WaitAsync(2000); } } break; } contex.Parent.RemoveComponent <ModeContex>(); await ETTask.CompletedTask; }
/// <summary> /// 获取所有指定类型单位 /// </summary> /// <param name="self"></param> /// <param name="type"></param> /// <returns></returns> public static ListComponent <AOIUnitComponent> GetAllUnit(this AOICell self, UnitType type = UnitType.ALL) { var res = ListComponent <AOIUnitComponent> .Create(); if (type == UnitType.ALL) { foreach (var item in self.idUnits) { res.AddRange(item.Value); } } else if (self.idUnits.ContainsKey(type)) { res.AddRange(self.idUnits[type]); } return(res); }
public static Unit Create(Scene currentScene, UnitInfo unitInfo) { UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>(); Unit unit = unitComponent.AddChildWithId <Unit, int>(unitInfo.UnitId, unitInfo.ConfigId); unitComponent.Add(unit); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit.Forward = new Vector3(unitInfo.ForwardX, unitInfo.ForwardY, unitInfo.ForwardZ); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); for (int i = 0; i < unitInfo.Ks.Count; ++i) { numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i]); } unit.AddComponent <MoveComponent>(); if (unitInfo.MoveInfo != null) { if (unitInfo.MoveInfo.X.Count > 0) { using (ListComponent <Vector3> list = ListComponent <Vector3> .Create()) { list.Add(unit.Position); for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i) { list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i])); } unit.MoveToAsync(list).Coroutine(); } } } unit.AddComponent <ObjectWait>(); unit.AddComponent <XunLuoPathComponent>(); Game.EventSystem.Publish(new EventType.AfterUnitCreate() { Unit = unit }); return(unit); }
/// <summary> /// 获取8个顶点,注意用完dispose /// </summary> /// <param name="self"></param> /// <param name="realPos"></param> /// <param name="realRot"></param> /// <returns></returns> public static ListComponent <Vector3> GetAllVertex(this OBBComponent self, Vector3 realPos, Quaternion realRot) { ListComponent <Vector3> res = ListComponent <Vector3> .Create(); for (float i = -0.5f; i < 0.5f; i++) { for (float j = -0.5f; j < 0.5f; j++) { for (float k = -0.5f; k < 0.5f; k++) { Vector3 temp = new Vector3(self.Scale.x * i, self.Scale.y * j, self.Scale.z * k); temp = realPos + realRot * temp; res.Add(temp); } } } return(res); }