//- 检测回放事件 // 如果有回放事件则进行回放 // @param gameFrame 当前的游戏帧 // @return none void checkPlayBackEvent(int gameFrame) { if (GameData.g_listPlaybackEvent.Count > 0) { for (int i = 0; i < GameData.g_listPlaybackEvent.Count; i++) { GameData.battleInfo v = GameData.g_listPlaybackEvent[i]; if (gameFrame == v.uGameFrame) { if (v.sckeyEvent == "createSoldier") { createSoldier(); } } } } }
//- 记录战斗信息(回放时使用) // // @return none void recordBattleInfo() { if (false == GameData.g_bRplayMode) { //记录战斗数据 string content = ""; for (int i = 0; i < GameData.g_listUserControlEvent.Count; i++) { GameData.battleInfo v = GameData.g_listUserControlEvent[i]; //出兵 if (v.sckeyEvent == "createSoldier") { content += v.uGameFrame + "," + v.sckeyEvent + "$"; } } UnityTools.playerPrefsSetString("battleRecord", content); GameData.g_listUserControlEvent.Clear(); } }
//- 读取玩家的操作信息 // // @return none void loadUserCtrlInfo() { GameData.g_listPlaybackEvent.Clear(); string content = battleRecord; string[] contents = content.Split('$'); for (int i = 0; i < contents.Length - 1; i++) { string[] battleInfo = contents[i].Split(','); GameData.battleInfo info = new GameData.battleInfo(); info.uGameFrame = int.Parse(battleInfo[0]); info.sckeyEvent = battleInfo[1]; GameData.g_listPlaybackEvent.Add(info); } }
/// <summary> /// 停止战斗 /// </summary> /// <returns></returns> public void stopBattle() { UnityTools.Log("end logic frame: " + GameData.g_uGameLogicFrame); UnityTools.Log("s_fixTestCount: " + TowerStandState.s_fixTestCount); UnityTools.Log("s_scTestContent: " + TowerStandState.s_scTestContent); m_bFireWar = false; s_uGameLogicFrame = GameData.g_uGameLogicFrame; //记录关键事件 if (!GameData.g_bRplayMode) { GameData.battleInfo info = new GameData.battleInfo(); info.uGameFrame = GameData.g_uGameLogicFrame; info.sckeyEvent = "stopBattle"; GameData.g_listUserControlEvent.Add(info); } gameEnd(); }
/// <summary> /// 创建士兵 /// </summary> /// <returns></returns> public void createSoldier() { m_bFireWar = true; var soldier = GameData.g_soldierFactory.createSoldier(); soldier.m_fixv3LogicPosition = new FixVector3((Fix64)0, (Fix64)1, (Fix64)(-4.0f)); soldier.updateRenderPosition(0); float moveSpeed = 3 + GameData.g_srand.Range(0, 3); soldier.moveTo(soldier.m_fixv3LogicPosition, new FixVector3(soldier.m_fixv3LogicPosition.x, soldier.m_fixv3LogicPosition.y, (Fix64)8), (Fix64)moveSpeed); //记录关键事件 if (!GameData.g_bRplayMode) { GameData.battleInfo info = new GameData.battleInfo(); info.uGameFrame = GameData.g_uGameLogicFrame; info.sckeyEvent = "createSoldier"; GameData.g_listUserControlEvent.Add(info); } }