public static async ETTask <ETModel.Entity> OnEnterView(EntiyInfo entityInfo) { try { Log.Debug($"{EntityDefine.GetType(entityInfo.Type).Name}"); if (entityInfo.Type == EntityDefine.GetTypeId <Unit>()) { var remoteUnit = MongoHelper.FromBson <Unit>(entityInfo.BsonBytes.bytes); foreach (var item in remoteUnit.Components) { Log.Debug($"remoteUnit {item.GetType().Name}"); } //remoteUnit.Domain = ETModel.Game.Scene; //Unit unit = UnitFactory.Create(ETModel.Game.Scene, remoteUnit.Id); var go = UnityEngine.Object.Instantiate(PrefabHelper.GetUnitPrefab("RemoteUnit")); go.transform.position = remoteUnit.Position; GameObject.DontDestroyOnLoad(go); //var unit = EntityFactory.CreateWithId<Unit>(domain, id); ETModel.Game.EventSystem.RegisterSystem(remoteUnit); ETModel.Game.EventSystem.Awake(remoteUnit); remoteUnit.Awake(go); UnitComponent.Instance.Add(remoteUnit); remoteUnit.Position = remoteUnit.Position; //remoteUnit.Dispose(); return(remoteUnit); } if (entityInfo.Type == EntityDefine.GetTypeId <Bullet>()) { var remoteBullet = MongoHelper.FromBson <Bullet>(entityInfo.BsonBytes.bytes); //Log.Debug($"{remoteBullet}"); //var bullet = ETModel.EntityFactory.CreateWithId<Bullet>(ETModel.Game.Scene, remoteBullet.Id); Log.Debug($"{remoteBullet.Components.Count}"); ETModel.Game.EventSystem.RegisterSystem(remoteBullet); ETModel.Game.EventSystem.Awake(remoteBullet); BulletComponent.Instance.Add(remoteBullet); //remoteBullet.Dispose(); return(remoteBullet); } if (entityInfo.Type == EntityDefine.GetTypeId <Monster>()) { var remote = MongoHelper.FromBson <Monster>(entityInfo.BsonBytes.bytes); Log.Debug($"HealthComponent HP{remote.GetComponent<HealthComponent>().HP}"); remote.Awake(); remote.Domain = ETModel.Game.Scene; remote.BodyView = GameObject.Instantiate(PrefabHelper.GetUnitPrefab("Monster")); GameObject.DontDestroyOnLoad(remote.BodyView); //var monster = MonsterFactory.Create(ETModel.Game.Scene, remote.Id); MonsterComponent.Instance.Add(remote); //remote.Position = remote.Position; //remote.Dispose(); return(remote); } } catch (System.Exception e) { Log.Error(e); } return(null); }
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; }