Example #1
0
        private void RemoveConnectTimeoutChannels()
        {
            using (MonoListComponent <long> waitRemoveChannels = MonoListComponent <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);
                }
            }
        }
Example #2
0
        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 (MonoListComponent <Vector3> path = MonoListComponent <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);
        }
Example #3
0
        public static async ETTask LoadAsync(this ConfigComponent self)
        {
            self.AllConfig.Clear();
            HashSet <Type> types = Game.EventSystem.GetTypes(typeof(ConfigAttribute));

            Dictionary <string, byte[]> configBytes = new Dictionary <string, byte[]>();

            self.ConfigLoader.GetAllConfigBytes(configBytes);


            async ETTask Load(Type configType, Dictionary <string, byte[]> configBytes)
            {
                await ETTask.CompletedTask;

                self.LoadOneInThread(configType, configBytes);
            }

            MonoListComponent <ETTask> tasks = MonoListComponent <ETTask> .Create();

            foreach (var item in types)
            {
                tasks.List.Add(Load(item, configBytes));                //好像这么写还是同步加载
            }

            await ETTaskHelper.WaitAll(tasks.List);

            tasks.Dispose();
        }
Example #4
0
        public static MonoListComponent <T> Create()
        {
            var listT = new MonoListComponent <T>();

            listT.isDispose = false;
            return(listT);
        }
Example #5
0
        public async ETTask Publish <T>(T a) where T : struct
        {
            List <object> iEvents;

            if (!this.allEvents.TryGetValue(typeof(T), out iEvents))
            {
                return;
            }

#if SERVER
            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);
                }
            }
#else
            using (var list = MonoListComponent <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);
                }
            }
#endif
        }
Example #6
0
        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 = MonoListComponent <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);
            }
        }