IEnumerator Start() { Time.fixedDeltaTime = Const.FixedDeltaTime; Configuration.ReadFromFileOrCreate("config.json"); if (gameObject.name != "Entity") { throw new ArgumentException("PlayMain is not binding in an Entity"); } Singleton = gameObject; DontDestroyOnLoad(gameObject); StrategyManager = new StrategyManager(); GlobalMatchInfo = MatchInfo.NewDefaultPreset(); // 绑定物体 ObjectManager = new ObjectManager(); ObjectManager.RebindObject(); ObjectManager.RebindMatchInfo(GlobalMatchInfo); Event.Register(Event.EventType0.PlaySceneExited, SceneExited); // 等待当前帧渲染完毕后暂停,确保还原后的场景显示到屏幕上 yield return(new WaitForEndOfFrame()); ObjectManager.Pause(); }
public void StopRound() { PauseRound(); InRound = false; ObjectManager.Pause(); Event.Send(Event.EventType0.RoundStop); }
public void StopMatch() { StartedMatch = false; StopRound(); InPlacement = false; ObjectManager.Pause(); Event.Send(Event.EventType0.MatchStop); }
public void ResumeRound() { if (InRound && PausedRound) { PausedRound = false; ObjectManager.Resume(); Event.Send(Event.EventType0.RoundResume); } }
public void PauseRound() { if (InRound) { PausedRound = true; ObjectManager.Pause(); Event.Send(Event.EventType0.RoundPause); } }
public void StartRound() { if (StartedMatch) { InRound = true; PauseRound(); Event.Send(Event.EventType0.RoundStart); } }
void Info_update() { GameObject obj = GameObject.Find("mainslider"); if (obj == null) { Debug.Log("No Slider Object."); } else { Debug.Log("Slider Object."); } Slider mainslider = (Slider)obj.GetComponent <Slider>(); // 设置进度条开始拍数和结束拍数 GameObject obj1 = GameObject.Find("num"); if (obj1 == null) { Debug.Log("No num Object."); } else { Debug.Log("num Object."); } Text num = (Text)obj1.GetComponent <Text>(); num.text = mainslider.value.ToString() + "/" + mainslider.maxValue.ToString(); int step = (int)mainslider.value; //Debug.Log("step" + step); GameObject obj2 = GameObject.Find("B0_vl"); if (obj1 == null) { Debug.Log("No B0_vl Object."); } else { Debug.Log("B0_vl Object."); } Text B0_vl = (Text)obj2.GetComponent <Text>(); Debug.Log("++"); //B0_vl.text = dr.Index(step).BlueRobot[0].pos.x.ToString(); B0_vl.text = "0"; // MatchInfo Event.Send(Event.EventType1.ReplayInfoUpdate, dr.Index(step)); }
void Start() { InitObjects(); SetBlueScoreText(matchInfo.Score.BlueScore); SetYellowScoreText(matchInfo.Score.BlueScore); OpenMenu(); StartObj.GetComponent <Button>().onClick.AddListener(delegate() { matchMain.LoadStrategy(); matchMain.StartMatch(); matchMain.StartRound(); }); ResumeObj.GetComponent <Button>().onClick.AddListener(delegate { CloseMenu(); matchMain.ResumeRound(); }); ReplayObj.GetComponent <Button>().onClick.AddListener(delegate { // 总拍数作为回放结束拍数 PlayerPrefs.SetInt("step_end", matchInfo.PlayTime); SceneManager.LoadScene("GameScene_Replay"); }); ReplayObj.GetComponent <Button>().enabled = false; ExitObj.GetComponent <Button>().onClick.AddListener(delegate { SceneManager.LoadScene("MainScene"); }); Event.Register(Event.EventType0.RoundStart, delegate() { Popup.Show("Round", "Round start", 1500); }); Event.Register(Event.EventType0.RoundResume, delegate() { Popup.Show("Round", "Round resume", 1500); }); Event.Register(Event.EventType0.RoundPause, delegate() { Popup.Show("Round", "Round pause", 1500); }); Event.Register(Event.EventType0.RoundStop, delegate() { Popup.Show("Round", "Round stop", 1500); }); Event.Register(Event.EventType1.LogUpdate, SetRefereeInfo); }
/// <summary> /// 新比赛开始 /// 重设场景,比分清空,裁判历史数据清空 /// </summary> public void StartMatch() { StartedMatch = false; ObjectManager.SetDefaultPostion(); GlobalMatchInfo.Score = new MatchScore(); GlobalMatchInfo.PlayTime = 0; GlobalMatchInfo.Referee = new Referee(); StrategyManager.CheckReady_ex(); StrategyManager.BeginBlue(GlobalMatchInfo); StrategyManager.BeginYellow(GlobalMatchInfo); StartedMatch = true; Event.Send(Event.EventType0.MatchStart); }
void UpdatePlacementToScene() { PlacementInfo blueInfo = StrategyManager.PlacementBlue(GlobalMatchInfo); PlacementInfo yellowInfo = StrategyManager.PlacementYellow(GlobalMatchInfo); ObjectManager.SetBluePlacement(blueInfo); ObjectManager.SetYellowPlacement(yellowInfo); if (GlobalMatchInfo.WhosBall == 0) // 先摆后摆另考虑 { ObjectManager.SetBallPlacement(blueInfo); } else { ObjectManager.SetBallPlacement(yellowInfo); } Event.Send(Event.EventType1.MatchInfoUpdate, GlobalMatchInfo); }
public void InRoundLoop() { if (PausedRound) { return; } try { // 检查策略 StrategyManager.CheckBlueReady_ex(); StrategyManager.CheckYellowReady_ex(); // 广播信息 Event.Send(Event.EventType1.MatchInfoUpdate, GlobalMatchInfo); // 裁判判断 if (GlobalMatchInfo.Referee.Judge(GlobalMatchInfo)) { InRound = false; InPlacement = true; GlobalMatchInfo.Referee = new Referee(); Event.Send(Event.EventType1.LogUpdate, "Foul : " + GlobalMatchInfo.GameState.ToString() + ". Blue team is" + ((Simuro5v5.Side)GlobalMatchInfo.WhosBall).ToString()); } else { UpdateWheelsToScene(); GlobalMatchInfo.PlayTime++; } } catch (Exception) { StopMatch(); throw; } }
void NewMatch() { if (StrategyManager != null) { StrategyManager.Dispose(); } StrategyManager = new StrategyManager(); GlobalMatchInfo = new MatchInfo(); Event.Register(Event.EventType1.Goal, delegate(object obj) { bool who = (bool)obj; if (who) { GlobalMatchInfo.Score.BlueScore++; } else { GlobalMatchInfo.Score.YellowScore++; } }); //LoadInfo.SaveInfo("StrategyServer/dlltest/debug/dlltest.dll", "StrategyServer/dll2.dll"); }
/// <summary> /// 维护比赛状态,根据裁判的判定结果执行不同的动作。<br/> /// 完整的一拍有三个步骤: /// 时间递增、更新输入(轮速或摆位)---> 物理引擎运行 ---> 触发事件。<br/> /// 这个函数会在每次“物理引擎运行”结束被调用,因此,一是需要处理上一拍的运行结果,二是作下一拍(本拍)的准备。<br/> /// </summary> public void InMatchLoop() { if (ManualPlacing) { throw new InvalidOperationException("manual placing"); } if (!LoadSucceed || !Started || Paused) { return; } // 触发事件,作为上一拍的结束 // 如果现在是阶段的第一拍,上一拍无意义,不用触发事件 if (GlobalMatchInfo.TickPhase != 0) { Event.Send(Event.EventType1.MatchInfoUpdate, GlobalMatchInfo); } else { // 在第一拍做初始化 placementCount = 0; callbackCount = 0; lastPlacementId = 0; placementToIgnore = new Queue <int>(); } /* 之前处理上一拍 */ /* 之后为本拍做准备 */ // 从裁判中获取下一拍的动作。 JudgeResult judgeResult = GlobalMatchInfo.Referee.Judge(GlobalMatchInfo); // 时间加一 GlobalMatchInfo.TickMatch++; GlobalMatchInfo.TickPhase++; switch (judgeResult.ResultType) { // 执行动作,更新输入 case ResultType.GameOver: // 整场比赛结束 // 可能最后一拍正好进球,需要判断 switch (judgeResult.WhoGoal) { case Side.Blue: GlobalMatchInfo.Score.BlueScore++; break; case Side.Yellow: GlobalMatchInfo.Score.YellowScore++; break; } StopMatch(); break; case ResultType.NextPhase: // 阶段结束 // 这之后的物理引擎运行的一拍无意义,不用触发MatchInfoUpdate事件 if (GlobalMatchInfo.MatchPhase == MatchPhase.FirstHalf) { SwitchRole(); } GlobalMatchInfo.MatchPhase = GlobalMatchInfo.MatchPhase.NextPhase(); GlobalMatchInfo.TickPhase = 0; // 时间指定为0,使得下一拍的裁判得知新阶段的开始 OnNextPhase(); // 通知策略 switch (GlobalMatchInfo.MatchPhase) { case MatchPhase.FirstHalf: break; case MatchPhase.SecondHalf: StrategyManager.Blue.OnSecondHalfStart(); StrategyManager.Yellow.OnSecondHalfStart(); break; case MatchPhase.OverTime: StrategyManager.Blue.OnOvertimeStart(); StrategyManager.Yellow.OnOvertimeStart(); break; case MatchPhase.Penalty: StrategyManager.Blue.OnPenaltyShootoutHalfStart(); StrategyManager.Yellow.OnPenaltyShootoutHalfStart(); break; default: throw new ArgumentOutOfRangeException(); } break; case ResultType.NormalMatch: // 正常比赛,输入轮速 UpdateWheelsToScene(); break; default: // 判断是否进球 switch (judgeResult.WhoGoal) { case Side.Blue: GlobalMatchInfo.Score.BlueScore++; break; case Side.Yellow: GlobalMatchInfo.Score.YellowScore++; break; } // 手动摆位 if (manualPlaceEnabled) { BroadcastJudgeResult(judgeResult); BeginManualPlace(); } else { void Callback() { #region Patch to placement int callbackId = callbackCount; callbackCount++; if (callbackId == lastPlacementId) { lastPlacementId = 0; } else { Debug.Assert(placementToIgnore.Peek() == callbackId); placementToIgnore.Dequeue(); return; } #endregion BroadcastJudgeResult(judgeResult); //Debug.Log($"callback placement {callbackId}"); UpdatePlacementToScene(judgeResult); ObjectManager.SetStill(); Event.Send(Event.EventType1.AutoPlacement, GlobalMatchInfo); } #region Patch to placement int placementId = placementCount; placementCount++; if (lastPlacementId == 0) { lastPlacementId = placementId; } else { placementToIgnore.Enqueue(placementId); } #endregion if (GlobalMatchInfo.TickMatch > 1) { //Debug.Log($"Will stop at {GlobalMatchInfo.TickMatch} {placementId}"); PauseForSeconds(2, Callback); } else { Callback(); } } break; } }
public void LoadReplayScene() { GUI_Replay.Recorder = recorder; Event.Send(Event.EventType0.PlaySceneExited); SceneManager.LoadScene("GameScene_Replay"); }
// 以下为在编辑器中绑定的函数 public void LoadMainScene() { Event.Send(Event.EventType0.PlaySceneExited); SceneManager.LoadScene("MainScene"); }
/// <summary> /// 维护比赛状态,根据裁判的判定结果执行不同的动作。<br> /// 完整的一拍有三个步骤: /// 时间递增、更新输入(轮速或摆位)---> 物理引擎运行 ---> 触发事件。<br> /// 这个函数会在每次“物理引擎运行”结束被调用,因此,一是需要处理上一拍的运行结果,二是作下一拍(本拍)的准备。<br> /// </summary> public void InMatchLoop() { if (ManualPlacing) { throw new InvalidOperationException("manual placing"); } if (!LoadSucceed || !Started || Paused) { return; } // 触发事件,作为上一拍的结束 // 如果现在是阶段的第一拍,上一拍无意义,不用触发事件 if (GlobalMatchInfo.TickPhase != 0) { Event.Send(Event.EventType1.MatchInfoUpdate, GlobalMatchInfo); } /* 之前处理上一拍 */ /* 之后为本拍做准备 */ // 从裁判中获取下一拍的动作。 JudgeResult judgeResult = GlobalMatchInfo.Referee.Judge(GlobalMatchInfo); // 时间加一 GlobalMatchInfo.TickMatch++; GlobalMatchInfo.TickPhase++; // 执行动作,更新输入 if (judgeResult.ResultType == ResultType.GameOver) { // 整场比赛结束 Debug.Log("Game Over"); // 判断是否进球 switch (judgeResult.WhoGoal) { case Side.Blue: GlobalMatchInfo.Score.BlueScore++; break; case Side.Yellow: GlobalMatchInfo.Score.YellowScore++; break; } StopMatch(); } else if (judgeResult.ResultType == ResultType.NextPhase) { // 阶段结束 // 这之后的物理引擎运行的一拍无意义,不用触发事件 Debug.Log("next phase"); if (GlobalMatchInfo.MatchPhase == MatchPhase.FirstHalf) { Debug.Log("switch role"); SwitchRole(); } GlobalMatchInfo.MatchPhase = GlobalMatchInfo.MatchPhase.NextPhase(); GlobalMatchInfo.TickPhase = 0; // 时间指定为0,使得下一拍的裁判得知新阶段的开始 OnNextPhase(); } else if (judgeResult.ResultType == ResultType.NormalMatch) { // 正常比赛,输入轮速 UpdateWheelsToScene(); } else { // 摆位,输入摆位信息 Debug.Log("placing..."); // 判断是否进球 switch (judgeResult.WhoGoal) { case Side.Blue: GlobalMatchInfo.Score.BlueScore++; break; case Side.Yellow: GlobalMatchInfo.Score.YellowScore++; break; } StrategyManager.Blue.OnJudgeResult(judgeResult); StrategyManager.Yellow.OnJudgeResult(new JudgeResult { Actor = judgeResult.Actor.ToAnother(), ResultType = judgeResult.ResultType, Reason = judgeResult.Reason }); // 手动摆位 if (manualPlaceEnabled) { Debug.Log("manual placing"); BeginManualPlace(); } else { Debug.Log("auto placing"); void Callback() { UpdatePlacementToScene(judgeResult); ObjectManager.SetStill(); Event.Send(Event.EventType1.AutoPlacement, GlobalMatchInfo); PauseForSeconds(2, () => { }); } // TODO 考虑连续出现摆位的情况 if (GlobalMatchInfo.TickMatch > 1) { PauseForSeconds(2, Callback); } else { Callback(); } } } }