Example #1
0
 //偵測器觸發事件(並將結果儲存至PositionSensorEventArgs.spinResultList中)
 private void SensorTrigger(object sender, PositionSensorEventArgs eventArgs)
 {
     if (!gameObject.activeSelf)
     {
         return;
     }
     StartCoroutine(Cor_SensorTrigger(eventArgs));
 }
Example #2
0
    //偵測器觸發(協程)
    private IEnumerator Cor_SensorTrigger(PositionSensorEventArgs eventArgs)
    {
        rb.simulated = true; //開啟剛體模擬(捕捉Trigger訊號)

        yield return(new WaitUntil(() => isTriggered));

        eventArgs.AddResult(coordinate, pointerElement.elementType); //加入偵測結果
        eventArgs.overNumber--;

        isTriggered  = false;
        rb.simulated = false; //關閉剛體模擬
    }
Example #3
0
    //捲軸旋轉(協程)
    //[param] spinModeList = 旋轉模式 , linkTime = 牽動等待時間 , isTest = 測試與否
    private IEnumerator Cor_BeginSpin(List <SpinMode> spinModeList, float linkTime, bool isTest)
    {
        if (!isTest) //測試的狀況跳過
        {
            if (spinModeList.Count != scrollCount && spinModeList.Count != 1)
            {
                throw new System.Exception("[ERROR]輸入的旋轉模式設定有誤!");
            }

            //旋轉前準備
            if (MoneyManager.Instance.nowMoney < BetController.Instance.nowBetMoney)
            {
                AudioManagerScript.Instance.PlayAudioClip("SE取消");
                Coroutine moneyNotEnough = StartCoroutine(MoneyManager.Instance.Cor_MoneyNotEnough()); //錢不夠提示

                yield return(moneyNotEnough);

                GameController.Instance.SetOperationState(true); //操作狀態設為允許

                yield break;
            }

            leverAnim.Play("lever_spin", 0, 0); //撥放動畫

            AudioManagerScript.Instance.PlayAudioClip("SE拉桿");

            StartCoroutine(MoneyManager.Instance.Cor_SetMoney(MoneyManager.Instance.nowMoney - BetController.Instance.nowBetMoney, false)); //扣除賭金

            StopAllElementAnimation();                                                                                                      //停止所有圖格動畫
        }

        //預估旋轉結果
        List <List <ElementImageType> > spinResult = BuildResultScroll(); //旋轉結果

        List <SensorInfo> blocksResult = new List <SensorInfo>();         //將旋轉結果的圖格列表形式轉換成捲軸偵測器形式

        for (int i = 0; i < posSensorArray.Count; i++)
        {
            SensorInfo _info = new SensorInfo(); //建立偵測器
            _info.coordinate  = posSensorArray[i].coordinate;
            _info.elementType = spinResult[(int)posSensorArray[i].coordinate.x][i % visibleElementCount];

            blocksResult.Add(_info); //加入列表
        }

        //Debug.Log("BlocksResult Test -------------");
        //for (int i = 0; i < blocksResult.Count; i++)
        //{
        //    Debug.Log(string.Format("({0}, {1}) = {2}", blocksResult[i].coordinate.x, blocksResult[i].coordinate.y, blocksResult[i].elementType));
        //}

        List <PrizeLineInfo> prizeLineDistribution = new List <PrizeLineInfo>();                                                    //中獎資訊列表
        int prizeTotal = 0;                                                                                                         //總獎金

        List <LineDrawer> _workingLineList = LotteryLineManager.Instance.GetWorkingLines();                                         //取得有效線段
        List <Vector2>    _drawedPosList   = new List <Vector2>();                                                                  //中獎圖格座標列表

        for (int i = 0; i < _workingLineList.Count; i++)                                                                            //遍歷所有線段是否中獎
        {
            PrizeLineInfo _pInfo = _workingLineList[i].RewardJudgement(blocksResult, PrizeTableManager.Instance.prizeTable.m_data); //判斷該線段中獎資訊, 並將其儲存
            _drawedPosList.AddRange(_pInfo.drawedPosList);                                                                          //加入中獎圖格座標列表

            if (_pInfo.sumPrize > 0)                                                                                                //有中獎時
            {
                prizeTotal += _pInfo.sumPrize;                                                                                      //總獎金累計
            }

            prizeLineDistribution.Add(_pInfo);
        }

        //Debug.Log("總計中獎獎金 = " + prizeTotal);
        //for (int i = 0; i < prizeLineDistribution.Count; i++)
        //{
        //    Debug.Log(string.Format("等級 {0} 合計中獎獎金 = {1}", prizeLineDistribution[i].lineLevel, prizeLineDistribution[i].sumPrize));
        //}

#if UNITY_EDITOR
        if (isTest)                                                                  //測試的狀況
        {
            TestPanelManager.Instance.FeedbackSimulateResult(prizeLineDistribution); //儲存模擬結果

            yield break;
        }
#endif

        _drawedPosList = ListExtensibleScript <Vector2> .RepetitionFilter(_drawedPosList); //篩掉列表中的重複元素

        //捲軸旋轉狀態
        bool[] _stateArr = new bool[scrollCount];
        for (int i = 0; i < _stateArr.Length; i++)
        {
            _stateArr[i] = false;
        }

        ScrollBehavior.s_scrollRollingStates = _stateArr; //初始化旋轉狀態
        GameController.Instance.leverCanSnap = true;      //可手動中斷捲軸

        //捲軸旋轉動畫
        //float _delayTime = 0; //捲軸煞停延遲時間
        for (int i = 0; i < scrollCount; i++) //逐個捲軸執行旋轉動作
        {
            int _index = 0;
            if (spinModeList.Count > 1)
            {
                _index = i;                                                                                                                     //若為統一旋轉模式則List索引固定為0, 若個別指定則索引值隨迴圈變動
            }
            bool  _dir   = spinModeList[_index].direction;                                                                                      //旋轉方向
            float _speed = spinModeList[_index].elementSpeed;                                                                                   //旋轉速度
            float _time  = spinModeList[_index].spinTime;                                                                                       //旋轉時間

            float _sliderSpeed = ((_dir ? _speed : -_speed) / (scrollGroup[i].elementChain.Count - visibleElementCount)) * Time.fixedDeltaTime; //換算速度(圖格速度 ➡ 拉條速度)

            StartCoroutine(scrollGroup[i].Cor_ScrollSpin(_sliderSpeed, _time, spinResult[i], scrollStartingCurve));

            if (i == scrollCount - 1) //最後一個捲軸動作時, 紀錄煞停延遲時間
            {
                //_delayTime = ( (float)( visibleElementCount + 1 ) / ( scrollGroup[i].elementChain.Count - visibleElementCount ) ) / ( Mathf.Abs(_sliderSpeed) * ( 1f / Time.fixedDeltaTime ) );
                //Debug.Log("SliderSpeed(/s) = " + ( ( Mathf.Abs(_sliderSpeed) * ( 1f / Time.fixedDeltaTime ) ) ));
                //Debug.Log("Vc = " + visibleElementCount);
                //Debug.Log("t - Vc = " + ( scrollGroup[i].elementChain.Count - visibleElementCount ));
                //Debug.Log("Vc / (t - Vc) = " + ( (float)visibleElementCount / ( scrollGroup[i].elementChain.Count - visibleElementCount ) ));
                //Debug.Log("DelayTime = " + _delayTime);

                break;
            }

            yield return(new WaitForSeconds(linkTime));
        }

        for (int i = 0; i < scrollCount; i++) //等待所有捲軸旋轉完畢
        {
            yield return(new WaitWhile(() => scrollGroup[i].isRolling));
        }

        yield return(new WaitForSeconds(brakeBufferTime));

        GameController.Instance.leverCanSnap = false; //禁止手動中斷捲軸

        PositionSensorEventArgs eventArgs = new PositionSensorEventArgs(visibleElementCount * scrollCount);
        if (SpinJudged != null)
        {
            SpinJudged.Invoke(this, eventArgs);
        }

        yield return(new WaitUntil(() => (eventArgs.overNumber == 0)));  //等待所有圖格位置偵測器觸發結束

        //for (int i = 0; i < eventArgs.SpinResultList.Count; i++)
        //{
        //    Debug.Log(string.Format("[{0}] ({1}, {2}) : {3}", i, eventArgs.SpinResultList[i].coordinate.x, eventArgs.SpinResultList[i].coordinate.y, eventArgs.SpinResultList[i].elementType));
        //}

        //旋轉結果
        previousSpinResult = eventArgs.SpinResultList;                                                       //記錄拉霸結果

        PlayElementAnimation(ElementAnimationType.中獎, _drawedPosList, true);                                 //中獎圖格特效

        yield return(StartCoroutine(MoneyManager.Instance.Cor_GetPrize(prizeTotal, prizeLineDistribution))); //獲得獎金

        GameController.Instance.SetOperationState(true);                                                     //操作狀態設為允許
    }