/// <summary> /// メインループ /// メインループを外だしにすっか /// </summary> /// <returns></returns> IEnumerator MainLoop() { var core = new Mobile(); var pressed = new List<ButtonWithReelIndex>(); var betCoins = 0; // マシンからのコールバック群 Action<int> Payout = (coinCount) => { // sorottaは役が揃った=1 揃わなかった=0 var sorotta = coinCount > 0 ? "1" : "0"; // 押し順をFSMにストア var msg = String.Join("", pressed.Select(pr => (pr.Button + 1).ToString()).ToArray()); msg += sorotta; var fsmStr = SlotMachineStateFsm.FsmVariables.FindFsmString("PressOrder"); fsmStr.Value = msg; SlotMachineStateFsm.SendEvent("Payout"); }; Action<int> ReelStart = (yaku) => { SlotMachineStateFsm.FsmVariables.FindFsmInt("Yaku").Value = yaku; Yaku y = (Yaku)yaku; Debug.Log("クライアント成立役:" + y.ToString()); pressed.Clear(); betCoins = 0; }; Action<int, int> ButtonStop = (button, reelIndex) => { //Debug.Log("ButtonStop:" + button + "," + reelIndex); var p = new ButtonWithReelIndex() { Button = button, ReelIndex = reelIndex }; var table = new[] { new { index = 0, fsmInt = SlotMachineStateFsm.FsmVariables.FindFsmInt("ReelIndex0") }, new { index = 1, fsmInt = SlotMachineStateFsm.FsmVariables.FindFsmInt("ReelIndex1") }, new { index = 2, fsmInt = SlotMachineStateFsm.FsmVariables.FindFsmInt("ReelIndex2") }, }; // ボタン押下リール位置をFSMにストア var fsmInt = table.Where(e => e.index == button).First().fsmInt; fsmInt.Value = reelIndex; // すでにボタンが押下してあるなら登録しない if ( pressed.Any(prs=>prs.Button==button)) { return; } pressed.Add(p); if( pressed.Count == 3) { // 3ボタン押した SlotMachineStateFsm.SendEvent("AllButtonPushed"); } }; Action<int> KeyTrigger = (key) => { //Debug.Log("Key:" + key); }; Action Bet = () => { betCoins++; SlotMachineStateFsm.FsmVariables.FindFsmInt("BetCount").Value = betCoins; if (betCoins >= 3) { //Debug.Log("Bet:" + betCoins); } }; var callbacks = new CallbackToController() { Payout = Payout, ReelStart = ReelStart, ButtonStop = ButtonStop, KeyTrigger = KeyTrigger, Bet = Bet }; while (true) { try { core.exec(callbacks); } catch (Exception e) { Debug.Log(e); } if (IsAllReelStopped() && Is4thReelStopped()) { slotMachineState.PlayEnd(); SlotMachineStateFsm.SendEvent("AllReelsStopped"); } yield return new WaitForSeconds(0.02f); } }