void StartGame(Player[] players) { WorldBase world = WorldManager.CreateWorld <DemoWorld>(); //TODO 模式选择没用了 world.SyncRule = SyncRule.Status; world.m_RandomSeed = new Random().Next(); //随机一个种子 for (int i = 0; i < players.Length; i++) { ConnectionComponent conn = new ConnectionComponent(); conn.m_session = players[i].session; conn.m_playerID = players[i].playerID; SyncComponent sc = new SyncComponent(); world.CreateEntityImmediately("Player" + players[i].playerID, conn, sc); players[i].session.m_connect = conn; world.eventSystem.DispatchEvent(ServiceEventDefine.c_playerJoin, conn.Entity); Debug.Log("Send Game Start"); //派发游戏开始消息 PlayerMatchMsg_c msg = new PlayerMatchMsg_c(); msg.predictTime = 0; msg.isMatched = true; ProtocolAnalysisService.SendMsg(players[i].session, msg); } world.IsStart = true; }
void InitGrass() { string content = FileTool.ReadStringByFile(Environment.CurrentDirectory + "/Map/GrassData.txt"); string[] contentArray = content.Split('\n'); for (int i = 0; i < contentArray.Length; i++) { if (contentArray[i] != "") { SyncComponent sc = new SyncComponent(); Area aera = deserializer.Deserialize <Area>(contentArray[i]); GrassComponent gc = new GrassComponent(); CollisionComponent cc = new CollisionComponent(); cc.area = aera; cc.isStatic = true; m_world.CreateEntityImmediately("Grass" + i, gc, cc, sc); //Debug.Log("Create Grass"); } } }
public void InitMap() { List <Area> list = new List <Area>(); string content = FileTool.ReadStringByFile(Environment.CurrentDirectory + "/Map/mapData.txt"); string[] contentArray = content.Split('\n'); for (int i = 0; i < contentArray.Length; i++) { if (contentArray[i] != "") { list.Add(deserializer.Deserialize <Area>(contentArray[i])); } } for (int i = 0; i < list.Count; i++) { CollisionComponent cc = new CollisionComponent(); cc.area = list[i]; SyncComponent sc = new SyncComponent(); BlockComponent bc = new BlockComponent(); m_world.CreateEntity(cc, sc, bc); Debug.Log("Create map"); } }
public void PushSyncEnity(SyncComponent connectionComp, EntityBase entity) { for (int i = 0; i < connectionComp.m_waitSyncList.Count; i++) { PushSyncEnity(connectionComp.m_waitSyncList[i].m_session, entity); } connectionComp.m_waitSyncList.Clear(); }
public void PushDestroyEntity(SyncComponent connectionComp, EntityBase entity) { for (int i = 0; i < connectionComp.m_waitSyncList.Count; i++) { connectionComp.m_waitSyncList[i].m_waitDestroyEntity.Add(entity.ID); } connectionComp.m_waitSyncList.Clear(); }
//public override void OnEntityCreate(EntityBase entity) //{ // base.OnEntityCreate(entity); //} public override void OnEntityDestroy(EntityBase entity) { if (entity.GetExistComp <SyncComponent>()) { SyncComponent sc = entity.GetComp <SyncComponent>(); SetAllSync(sc); PushDestroyEntity(sc, entity); } }
public void PushSyncEnity(SyncComponent connectionComp, EntityBase entity) { for (int i = 0; i < connectionComp.m_waitSyncList.Count; i++) { Debug.Log("Push " + connectionComp.m_waitSyncList[i].m_session.SessionID + " entity " + entity.ID); PushSyncEnity(connectionComp.m_waitSyncList[i].m_session, entity); } connectionComp.m_waitSyncList.Clear(); }
//推送所有数据(把所有同步队列的数据推送出去) public void PushAllData() { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { SyncComponent sc = list[i].GetComp <SyncComponent>(); PushSyncEnity(sc, list[i]); } }
public override void OnEntityCompAdd(EntityBase entity, string compName, ComponentBase component) { if (compName == "ConnectionComponent") { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { SyncComponent sc = list[i].GetComp <SyncComponent>(); sc.m_waitSyncList.Add((ConnectionComponent)component); } } }
public override void OnEntityDestroy(EntityBase entity) { Debug.Log("OnEntityDestroy"); if (entity.GetExistComp <SyncComponent>()) { Debug.Log("PushDestroyEntity 1"); SyncComponent sc = entity.GetComp <SyncComponent>(); SetAllSync(sc); PushDestroyEntity(sc, entity); } }
public void SetAllSync(SyncComponent connectionComp) { List <EntityBase> list = GetEntityList(new string[] { "ConnectionComponent" }); for (int i = 0; i < list.Count; i++) { ConnectionComponent comp = list[i].GetComp <ConnectionComponent>(); if (!connectionComp.m_waitSyncList.Contains(comp)) { connectionComp.m_waitSyncList.Add(comp); } } }
void OnPlayerExit(EntityBase entity, params object[] objs) { ConnectionComponent comp = entity.GetComp <ConnectionComponent>(); comp.m_isWaitPushStart = false; SyncComponent sc = entity.GetComp <SyncComponent>(); SetAllSync(sc); //TODO 将来改成推送移除连接组件 //PushDestroyEntity(sc, entity); }
public override void OnEntityCompAdd(EntityBase entity, string compName, ComponentBase component) { Debug.Log("OnEntityCompAdd " + compName); if (compName == "ConnectionComponent") { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { SyncComponent sc = list[i].GetComp <SyncComponent>(); sc.m_waitSyncList.Add((ConnectionComponent)component); } PushStartSyncMsg(entity.GetComp <ConnectionComponent>().m_session); } }
public override void OnEntityCreate(EntityBase entity) { //Debug.Log("OnEntityCreate ID: " + entity.ID + " frame " + m_world.FrameCount); SyncComponent sc = null; //自动创建Sync组件 if (!entity.GetExistComp <SyncComponent>()) { //Debug.Log("自动创建Sync组件 "); sc = entity.AddComp <SyncComponent>(); } else { sc = entity.GetComp <SyncComponent>(); } }
public override void OnEntityCompRemove(EntityBase entity, string compName, ComponentBase component) { if (compName == "ConnectionComponent") { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { SyncComponent sc = list[i].GetComp <SyncComponent>(); ConnectionComponent cc = (ConnectionComponent)component; if (sc.m_waitSyncList.Contains(cc)) { sc.m_waitSyncList.Remove(cc); } } } }
public override void OnEntityCompChange(EntityBase entity, string compName, ComponentBase previousComponent, ComponentBase newComponent) { if (entity.GetExistComp <SyncComponent>()) { List <EntityBase> list = GetEntityList(new string[] { "ConnectionComponent" }); for (int i = 0; i < list.Count; i++) { SyncComponent comp = entity.GetComp <SyncComponent>(); ConnectionComponent connComp = list[i].GetComp <ConnectionComponent>(); if (!comp.m_waitSyncList.Contains(connComp)) { comp.m_waitSyncList.Add(connComp); } } } }
//推送所有数据(把所有同步队列的数据推送出去) public void PushAllData() { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { SyncComponent sc = list[i].GetComp <SyncComponent>(); PushSyncEnity(sc, list[i]); } List <EntityBase> list2 = GetEntityList(new string[] { "ConnectionComponent" }); for (int i = 0; i < list2.Count; i++) { ConnectionComponent cc = list2[i].GetComp <ConnectionComponent>(); PushSyncEnity(cc, list2[i]); } }
protected override void OnNewSessionConnected(SyncSession session) { Debug.Log("SyncService OnNewSessionConnected " + session.SessionID); base.OnNewSessionConnected(session); WaitSyncComponent wsc = new WaitSyncComponent(); ConnectionComponent conn = new ConnectionComponent(); conn.m_session = session; PlayerComponent pc = new PlayerComponent(); CommandComponent cc = new CommandComponent(); SyncComponent syc = new SyncComponent(); syc.m_waitSyncList.Add(conn); ViewComponent vc = new ViewComponent(); AssetComponent ac = new AssetComponent(); MoveComponent mc = new MoveComponent(); ac.m_assetName = "Cube"; EntityBase entity = m_world.CreateEntity(id++); entity.AddComp(conn); entity.AddComp(pc); entity.AddComp(syc); entity.AddComp(vc); entity.AddComp(ac); entity.AddComp(cc); entity.AddComp(mc); entity.AddComp(wsc); session.m_entity = entity; session.m_connect = conn; Debug.Log("new entity " + id); }
public override void OnEntityCreate(EntityBase entity) { Debug.Log("OnEntityCreate ID: " + entity.ID + " frame " + m_world.FrameCount); SyncComponent sc = null; //自动创建Sync组件 if (!entity.GetExistComp <SyncComponent>()) { Debug.Log("自动创建Sync组件 "); sc = entity.AddComp <SyncComponent>(); } else { sc = entity.GetComp <SyncComponent>(); } //if (m_world.SyncRule == SyncRule.Status) //{ // SetAllSync(sc); //} }
public override void OnEntityCreate(EntityBase entity) { Debug.Log("OnEntityCreate "); SyncComponent sc = null; //自动创建Sync组件 if (!entity.GetExistComp <SyncComponent>()) { Debug.Log("自动创建Sync组件 "); sc = entity.AddComp <SyncComponent>(); } else { sc = entity.GetComp <SyncComponent>(); } if (m_world.SyncRule == SyncRule.Status) { SetAllSync(sc); } }
void InitElementCreatePoint() { string content = FileTool.ReadStringByFile(Environment.CurrentDirectory + "/Map/elementCreatePointData.txt"); string[] contentArray = content.Split('\n'); for (int i = 0; i < contentArray.Length; i++) { if (contentArray[i] != "") { SyncComponent sc = new SyncComponent(); ItemCreatePointComponent tmp = deserializer.Deserialize <ItemCreatePointComponent>(contentArray[i]); CollisionComponent cc = new CollisionComponent(); cc.area.position = tmp.pos.ToVector(); cc.area.areaType = AreaType.Circle; cc.area.radius = 1; m_world.CreateEntityImmediately("ElementCreatePoint" + i, tmp, sc, cc); } } }
void OnPlayerJoin(EntityBase entity, params object[] objs) { Debug.Log("ServiceSyncSystem OnPlayerJoin "); ConnectionComponent comp = entity.GetComp <ConnectionComponent>(); SyncComponent syc = entity.GetComp <SyncComponent>(); comp.m_isWaitPushStart = true; List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { //在所有同步对象的同步队列里加入这个新玩家 (把这个世界的数据告诉新玩家) SyncComponent sycTmp = list[i].GetComp <SyncComponent>(); if (!sycTmp.m_waitSyncList.Contains(comp)) { sycTmp.m_waitSyncList.Add(comp); } } //把自己广播给所有人 SetAllSync(syc); }
void OnCompChange(EntityBase entity, params object[] objs) { SyncComponent syc = entity.GetComp <SyncComponent>(); SetAllSync(syc); }