//(按鈕事件)切換主選單 public void Btn_ChangeMainMenu(bool leftOrRight) { int nextIndex = leftOrRight ? ((menuSelectedIndex + 1) % (menuList.Count)) : (menuSelectedIndex - 1 < 0 ? menuList.Count - 1 : menuSelectedIndex - 1); float leftPoint = -1285; //左方目標x座標 float rightPoint = 1285; //右方目標y座標 tx_switcherTitle.text = menuList[menuSelectedIndex]; if (menuSelectedIndex == 1) { GameSetting_CompletelyImitate(); //移出遊戲設定選單時, 儲存設定值 } tx_switcherTitle_hide.text = menuList[nextIndex]; childMenuScripts[menuSelectedIndex].AnimationCommand(new PositionScript(changeMenuByCurve, new Vector2(leftOrRight ? leftPoint : rightPoint, 0), false), new AnimationBehavior(PlayMode.狀態延續) { disableObject = true }); childMenuScripts[nextIndex].AnimationCommand(new PositionScript(changeMenuByCurve, new Vector2(leftOrRight ? rightPoint : leftPoint, 0), new Vector2(0, 0), false), new AnimationBehavior(PlayMode.狀態延續)); menuSelectedIndex = nextIndex; if (nextIndex == 1) { cg_setting.blocksRaycasts = true; //移進遊戲設定選單時, 設定按鈕為可按 } else { cg_setting.blocksRaycasts = false; //移出遊戲設定選單時, 設定按鈕為不可按 } animScript_mainMenu.PlayAnimation(leftOrRight ? "MainMenuSwitchOver_TurnLeft" : "MainMenuSwitchOver_TurnRight", new AnimationBehavior(PlayMode.狀態延續), false); }
/// <summary> /// Changes the overworld object's current animation to the specified index. /// </summary> /// <param name="animationIndex">The index number of the animation to change to.</param> /// <param name="framesGiven">The amount of frames given for the animation to play fully. (set to -1 for default play speed)</param> /// <param name="isLooping">Whether or not the animation should loop after completion.</param> public void SetAnimation(int animationIndex, float framesGiven, bool isLooping) { StopCoroutine(currentAnimation); currentlyAnimating = false; animationScript.SetAnimationPatternIndex(animationIndex); animationScript.SetFramesGiven(framesGiven); animationScript.SetIsLooping(isLooping); animationQueue.Clear(); animationScript.PlayAnimation(); }
//改變玩家類型(upOrDown true=上,false=下 , senteOrGote true=先手,false=後手) //內部執行方法 private void _ChangePlayerType(bool upOrDown, bool blackOrWhite) { int index = blackOrWhite ? (int)blackPlayer : (int)whitePlayer; int nextIndex = upOrDown ? ((index + 1) % (playerTypeList.Count)) : (index - 1 < 0 ? playerTypeList.Count - 1 : index - 1); if (blackOrWhite) { tx_blackPlayerType.text = playerTypeList[index]; tx_blackPlayerType_hide.text = playerTypeList[nextIndex]; blackPlayer = (PlayerType)nextIndex; } else { tx_whitePlayerType.text = playerTypeList[index]; tx_whitePlayerType_hide.text = playerTypeList[nextIndex]; whitePlayer = (PlayerType)nextIndex; } int buttonCount = blackOrWhite ? blackSelectionButtons.Length : whiteSelectionButtons.Length; Button[] buttons = blackOrWhite ? blackSelectionButtons : whiteSelectionButtons; float animTime = 0.18f; //圖示顯亮or顯暗作動時間 Color32 enableColor = new Color32(255, 255, 255, 255); Color32 disableColor = new Color32(100, 100, 100, 255); for (int i = 0; i < buttonCount; i++) { if ((PlayerType)nextIndex == PlayerType.玩家) { if (blackOrWhite) { animScript_blackAiButtonFrame.AnimationCommand(new ColorScript(animTime, disableColor), new AnimationBehavior(PlayMode.狀態延續)); tx_blackAiType.text = aiTypeList[(int)blackAi]; tx_blackAiType_hide.text = "-"; animScript_changeBlackAi.PlayAnimation("SelectionSwitchOver_TurnUp", new AnimationBehavior(PlayMode.狀態延續), false); } else { animScript_whiteAiButtonFrame.AnimationCommand(new ColorScript(animTime, disableColor), new AnimationBehavior(PlayMode.狀態延續)); tx_whiteAiType.text = aiTypeList[(int)whiteAi]; tx_whiteAiType_hide.text = "-"; animScript_changeWhiteAi.PlayAnimation("SelectionSwitchOver_TurnUp", new AnimationBehavior(PlayMode.狀態延續), false); } buttons[i].interactable = false; } else { if (blackOrWhite) { animScript_blackAiButtonFrame.AnimationCommand(new ColorScript(animTime, enableColor), new AnimationBehavior(PlayMode.狀態延續)); if (tx_blackAiType_hide.text == "-") { tx_blackAiType.text = "-"; tx_blackAiType_hide.text = aiTypeList[(int)blackAi]; animScript_changeBlackAi.PlayAnimation("SelectionSwitchOver_TurnUp", new AnimationBehavior(PlayMode.狀態延續), false); } } else { animScript_whiteAiButtonFrame.AnimationCommand(new ColorScript(animTime, enableColor), new AnimationBehavior(PlayMode.狀態延續)); if (tx_whiteAiType_hide.text == "-") { tx_whiteAiType.text = "-"; tx_whiteAiType_hide.text = aiTypeList[(int)whiteAi]; animScript_changeWhiteAi.PlayAnimation("SelectionSwitchOver_TurnUp", new AnimationBehavior(PlayMode.狀態延續), false); } } buttons[i].interactable = true; } } if (blackOrWhite) { animScript_changeBlackPlayer.PlayAnimation(upOrDown ? "SelectionSwitchOver_TurnUp" : "SelectionSwitchOver_TurnDown", new AnimationBehavior(PlayMode.狀態延續), false); } else { animScript_changeWhitePlayer.PlayAnimation(upOrDown ? "SelectionSwitchOver_TurnUp" : "SelectionSwitchOver_TurnDown", new AnimationBehavior(PlayMode.狀態延續), false); } }
//檢測棋子連線 public bool CheckOneLine(Vector2 pos, int[] offset) { int linkNum = 1; //針對右邊for迴圈,針對棋子的x與y座標做遍歷;限定遍歷範圍;每遍歷一次遞增 for (int i = offset[0], j = offset[1]; (pos.x + i >= 0 && pos.x + i <= size.x) && (pos.y + j >= 0 && pos.y + j <= size.y); i += offset[0], j += offset[1]) { if (grid[(int)pos.x + i, (int)pos.y + j] == (int)turn + 1) { linkNum++; } else { break; } } //針對左邊for迴圈,針對棋子的x與y座標做遍歷;限定遍歷範圍;每遍歷一次遞減 for (int i = -offset[0], j = -offset[1]; (pos[0] + i >= 0 && pos[0] + i <= size.x) && (pos[1] + j >= 0 && pos[1] + j <= size.y); i -= offset[0], j -= offset[1]) { if (grid[(int)pos.x + i, (int)pos.y + j] == (int)turn + 1) { linkNum++; } else { break; } } if (linkNum > 4) //當棋子大於4顆 { //針對連成五子(以上)的棋子, 賦予動畫 for (int k = 0; k < chessLine.Count; k++) { ChessAttribute info = chessLine[k].GetComponent <ChessAttribute>(); if (info.gridPos.x == (int)pos.x && info.gridPos.y == (int)pos.y) { AnimationScript anim = chessLine[k].GetComponent <AnimationScript>(); winnerChessAnim.Add(anim); anim.PlayAnimation("Interlude_SuccessChess", new AnimationBehavior(PlayMode.循環撥放), false); } } for (int i = offset[0], j = offset[1]; (pos.x + i >= 0 && pos.x + i <= size.x) && (pos.y + j >= 0 && pos.y + j <= size.y); i += offset[0], j += offset[1]) { if (grid[(int)pos.x + i, (int)pos.y + j] == (int)turn + 1) { for (int k = 0; k < chessLine.Count; k++) { ChessAttribute info = chessLine[k].GetComponent <ChessAttribute>(); if (info.gridPos.x == (int)pos.x + i && info.gridPos.y == (int)pos.y + j) { AnimationScript anim = chessLine[k].GetComponent <AnimationScript>(); winnerChessAnim.Add(anim); anim.PlayAnimation("Interlude_SuccessChess", new AnimationBehavior(PlayMode.循環撥放), false); } } } else { break; } } for (int i = -offset[0], j = -offset[1]; (pos[0] + i >= 0 && pos[0] + i <= size.x) && (pos[1] + j >= 0 && pos[1] + j <= size.y); i -= offset[0], j -= offset[1]) { if (grid[(int)pos.x + i, (int)pos.y + j] == (int)turn + 1) { for (int k = 0; k < chessLine.Count; k++) { ChessAttribute info = chessLine[k].GetComponent <ChessAttribute>(); if (info.gridPos.x == (int)pos.x + i && info.gridPos.y == (int)pos.y + j) { AnimationScript anim = chessLine[k].GetComponent <AnimationScript>(); winnerChessAnim.Add(anim); anim.PlayAnimation("Interlude_SuccessChess", new AnimationBehavior(PlayMode.循環撥放), false); } } } else { break; } } return(true); } return(false); }