Esempio n. 1
0
        public override async ETTask M2C_OnEntityChangedHandler(ETModel.Session session, M2C_OnEntityChanged message)
        {
            Log.Debug($"M2C_OnEntityChangedHandler {Dumper.DumpAsString(message)}");
            var entityType = EntityDefine.TypeIds.GetKeyByValue((ushort)message.EntityType);

            ETModel.Entity entity = null;
            if (entityType == typeof(Unit))
            {
                entity = UnitComponent.Instance.Get(message.EntityId);
            }
            if (entityType == typeof(Bullet))
            {
                var bullet = BulletComponent.Instance.Get(message.EntityId);
                entity = bullet;
                if (entity is null)
                {
                    return;
                }
                if (bullet.BodyView != null)
                {
                    bullet.BodyView.transform.DOMove(new Vector3(message.X / 100f, message.Y / 100f, message.Z / 100f), 0.2f);
                }
            }
            if (entityType == typeof(Monster))
            {
                var monster = MonsterComponent.Instance.Get(message.EntityId);
                entity = monster;
                if (entity is null)
                {
                    return;
                }
                if (monster.BodyView != null)
                {
                    monster.BodyView.transform.DOMove(new Vector3(message.X / 100f, message.Y / 100f, message.Z / 100f), 0.2f);
                }
            }
            if (entity is null)
            {
                return;
            }
            if (message.ComponentType > 0)
            {
                entity = entity.GetComponent(EntityDefine.GetType(message.ComponentType));
            }

            var propertyCollection = EntityDefine.PropertyCollectionMap[EntityDefine.GetTypeId(entity.GetType())];

            if (propertyCollection.ContainsKey((ushort)message.PropertyId))
            {
                entity.SetPropertyValue((ushort)message.PropertyId, message.PropertyValue.bytes);
            }
            await ETTask.CompletedTask;
        }