static void OnNetBlockOrClose() { try { //Debug.Log("OnNetBlockOrClose"); gConnectCount = 0; WorldStage.mbReConnected = true; //启动断线重连,重新发送登录消息 Game game = Game.Instance; if (game != null) { game.mGameSock.Disconnect(); game.mGameSock.InitUserSock(); ConnectStage.RegistCallback(false); LoginStage.RegistCallback(false); WorldStage.RegistCallback(false); ///第一次连接失败,添加心跳开始持续一分钟连接12次,依然没有连上认为断开 ConnectStage.ConnecToMember(mstrServer, miPort, mstrUser, mstrPsd, mstrValidateString, 2); //Debug.Log("第一次重连"); TimerManager.AddTimerRepeat("OnNetBlockTimer", 5.0f, OnNetBlockTimer); LogSystem.LogWarning("First block connect try"); //SystemWaitPanel.Start(99999999); } } catch (System.Exception ex) { LogSystem.LogError("Game::OnNetBlockOrClose:", ex.ToString()); } }
private Level GenerateAndAddLevel(WorldStage worldStage) { Level currentLevel = this.levelFactory.CreateLevel(worldStage); currentLevel.SetLevelCleared(() => LevelCleared()); currentLevel.transform.SetParent(this.gameObject.transform, false); return(currentLevel); }
public static WorldStage CreateWithStageId(string stage_id) { WorldStage ws = new WorldStage (); string[] s = stage_id.Split ('-'); ws.WorldId = int.Parse (s [0]); ws.StageId = int.Parse (s [1]); return ws; }
public static WorldStage CreateWithGDEStageKey(string stage_key) { WorldStage ws = new WorldStage (); string[] s = stage_key.Split ('_'); ws.WorldId = int.Parse (s [1]); ws.StageId = int.Parse (s [2]); return ws; }
public WorldStage GetNextStage(WorldStage worldStage) { if (!ValidateStage(worldStage)) { return(null); } WorldData worldData = FindWorldData(worldStage.World); int levelId = worldStage.Id + 1; bool isLast = worldData.levelsNames.Length <= levelId + 1; return(new WorldStage(levelId, worldData.name, worldData.levelsNames[levelId], isLast)); }
private bool ValidateStage(WorldStage worldStage) { if (worldStage.IsLast) { return(false); } WorldData worldData = FindWorldData(worldStage.World); if (worldData == null) { return(false); } if (worldData.levelsNames.Length <= worldStage.Id + 1) { return(false); } return(true); }
static void OnNetBlockTimer() { //启动断线重连,重新发送登录消息 Game game = Game.Instance; if (game != null) { game.mGameSock.Disconnect(); game.mGameSock.InitUserSock(); ConnectStage.RegistCallback(false); LoginStage.RegistCallback(false); WorldStage.RegistCallback(false); //Debug.Log("第二次重连"); ConnectStage.ConnecToMember(mstrServer, miPort, mstrUser, mstrPsd, mstrValidateString, 2); gConnectCount++; LogSystem.LogWarning(gConnectCount + ": block connect try"); if (gConnectCount > 4) { mbNeedReConnect = false; TimerManager.Destroy("OnNetBlockTimer"); ///显示网络已经断线 string strHeader = TextManager.Instance.GetString("UI00031"); string strContext = TextManager.Instance.GetString("NetClose"); if (!string.IsNullOrEmpty(strHeader) && !string.IsNullOrEmpty(strContext)) { // if (GUIManager.HasView<SystemPrompt>()) // { // GUIManager.HideView<SystemPrompt>("SystemPrompt"); // } // PromptType pt = PoolManager.PopObject<PromptType>(PoolManager.PoolKey.Object_PromptType); // pt.layer = 5; // pt.title = strHeader; // pt.content = strContext; // pt.style = PromptType.Style.OK; // pt.callback_ok = OnConnectSecondTime; // GUIManager.ShowView<SystemPrompt>(pt); } } } }
public Level CreateLevel(WorldStage worldstage) { string levelPath = string.Format("Game/Worlds/{0}/{1}", worldstage.World, worldstage.Level); TextAsset jsonLevel = Resources.Load(levelPath) as TextAsset; if (jsonLevel == null) { Debug.LogError("Level Resource not Found!" + worldstage.World + "/" + worldstage.Level); return(null); } LevelData levelData = JsonUtility.FromJson <LevelData>(jsonLevel.text); Level level = BuildingResources.Level.Instantiate(new Vector2(0.25f, -0.25f)).GetComponent <Level>(); level.name = string.Format("Level_{0}_{1}", worldstage.World, worldstage.Level); Block[,] blockLayout = new Block[LocalConfig.Rows, LocalConfig.Columns]; GameObject layout = new GameObject("Layout"); layout.transform.SetParent(level.transform, false); int blockCount = 0; // it's easier to operate trough normal array Block[] blocks = levelData.layout.Select(blockData => { Vector2 position = LocalConfig.InitialPosition; position.x += blockData.column * LocalConfig.OffsetColumns; position.y -= blockData.row * LocalConfig.OffsetRows; string blockPath = string.Format("Game/Building/Blocks/{0}", blockData.type); GameObject blockResource = Resources.Load(blockPath) as GameObject; if (blockResource == null) { Debug.LogError("Block Resource not found!:" + blockData.type); return(null); } Block block = Instantiate(blockResource, position, Quaternion.identity).GetComponent <Block>(); string blockId = string.Format("{0}/{1}", blockData.row, blockData.column); block.Initialize(blockId, new Vector2(blockData.row, blockData.column), blockData.type, (id, explosive) => level.OnBlockDestroyed(id, explosive)); block.transform.SetParent(layout.transform, false); //create and set content (if there is any) if (blockData.content != null) { string pickupPath = string.Format("Game/Building/Pickups/{0}", blockData.content); GameObject pickUpResource = Resources.Load(pickupPath) as GameObject; if (pickUpResource == null) { Debug.LogError("Block content Resource not found!" + blockData.content); return(null); } GameObject pickUp = Instantiate(pickUpResource); block.SetItemOnHit(pickUp); } blockLayout[blockData.row, blockData.column] = block; blockCount++; return(block); }).ToArray(); GameObject scenario = CreateSceneario(levelData.wall, levelData.background); scenario.transform.SetParent(level.transform, true); level.Initialize(blockLayout, blocks); return(level); }
/// <summary> /// 初始化游戏世界控制 /// </summary> public void InitGameWord() { ConnectStage.RegistCallback(); LoginStage.RegistCallback(); WorldStage.RegistCallback(); }