コード例 #1
0
 //创建其他玩家
 private void CreateRemoteUnits(M2C_InViewUnits message)
 {
     foreach (var entityJson in message.InViewEntitys)
     {
         OnEnterView(entityJson).Coroutine();
     }
 }
コード例 #2
0
        //创建本地玩家
        private void CreateLocalUnit(M2C_InViewUnits message)
        {
            var localUnit = MongoHelper.FromBson <Unit>(message.SelfUnit.bytes);

            Unit.LocalUnit = localUnit;
            Log.Debug($"localUnit.Position {localUnit.Position} ");
            Log.Debug($"localUnit.Position {localUnit.Components.Count} ");
            //Log.Debug($"localUnit.Position  {localUnit.GetComponent<TransformComponent>()}");
            var go = UnityEngine.Object.Instantiate(PrefabHelper.GetUnitPrefab("LocalUnit"));

            go.transform.position = localUnit.Position;
            GameObject.DontDestroyOnLoad(go);
            foreach (var item in localUnit.Components.Values)
            {
                Log.Debug($"{item.GetType().Name}");
                ETModel.Game.EventSystem.RegisterSystem(item);
                item.Parent = localUnit;
            }
            //var unit = ETModel.EntityFactory.CreateWithId<Unit>(ETModel.Game.Scene, localUnit.Id);
            ETModel.Game.EventSystem.Awake(localUnit);
            localUnit.Awake(go);
            UnitComponent.Instance.Add(localUnit);
            //go.transform.GetChild(2).parent = null;
            //go.transform.GetChild(1).parent = null;
            localUnit.Position = localUnit.Position;
            Game.Scene.AddComponent <OperaComponent>();
        }
コード例 #3
0
 public virtual async ETTask M2C_InViewUnitsHandler(ETModel.Session session, M2C_InViewUnits message)
 {
 }
コード例 #4
0
 public override async ETTask M2C_InViewUnitsHandler(ETModel.Session session, M2C_InViewUnits message)
 {
     CreateLocalUnit(message);
     CreateRemoteUnits(message);
     await ETTask.CompletedTask;
 }
コード例 #5
0
 public virtual async ETTask M2C_InViewUnitsHandler(Scene scene, M2C_InViewUnits message)
 {
 }
コード例 #6
0
        public override async ETTask G2M_CreateUnitHandler(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            var copyMap = Game.Scene.Children.Values.ToList().Find((x) =>
            {
                if (x is Scene s)
                {
                    return(s.Name == "CopyMap1");
                }
                return(false);
            });

            if (copyMap == null)
            {
                var copyMapConfig = StartConfigComponent.Instance.GetByName("CopyMap1");
                copyMap = await SceneFactory.Create(Game.Scene, copyMapConfig.GetComponent <SceneConfig>().Name, SceneType.Map);
            }

            Unit unit = null;

            if (request.UnitId != 0)
            {
                unit = await DBComponent.Instance.Query <Unit>(request.UnitId);

                unit.Domain = copyMap;
            }
            else
            {
                unit          = EntityFactory.CreateWithId <Unit>(copyMap, IdGenerater.GenerateId());
                unit.PlayerId = request.PlayerId;
                unit.Setup();
                unit.Save().Coroutine();
            }

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <Body2dComponent>().CreateBody(.5f, .5f);
            unit.AddComponent <MailBoxComponent>();
            await unit.AddLocation();

            unit.AddComponent <UnitGateComponent, long>(request.GateSessionId);
            copyMap.GetComponent <UnitComponent>().Add(unit);
            response.UnitId = unit.Id;

            // 广播创建的unit
            var inViewUnitsMsg = new M2C_InViewUnits();
            var enterViewMsg   = new M2C_OnEnterView();

            Unit[] units = copyMap.GetComponent <UnitComponent>().GetAll();
            foreach (Unit u in units)
            {
                var entityInfo = new EntiyInfo();
                entityInfo.BsonBytes       = new Google.Protobuf.ByteString();
                entityInfo.BsonBytes.bytes = MongoHelper.ToBson(u);
                entityInfo.Type            = EntityDefine.GetTypeId <Unit>();
                if (u.Id == unit.Id)
                {
                    enterViewMsg.EnterEntity = entityInfo;
                    inViewUnitsMsg.SelfUnit  = entityInfo.BsonBytes;
                    continue;
                }
                inViewUnitsMsg.InViewEntitys.Add(entityInfo);
            }
            var monsters = copyMap.GetComponent <MonsterComponent>().GetAll();

            foreach (var u in monsters)
            {
                var entityInfo = new EntiyInfo();
                entityInfo.BsonBytes       = new Google.Protobuf.ByteString();
                entityInfo.BsonBytes.bytes = MongoHelper.ToBson(u);
                entityInfo.Type            = EntityDefine.GetTypeId <Monster>();
                inViewUnitsMsg.InViewEntitys.Add(entityInfo);
            }
            MessageHelper.BroadcastToOther(unit, enterViewMsg);
            MessageHelper.Send(unit, inViewUnitsMsg);
            reply();
        }