Exemple #1
0
        public void ReCaculateSpeed()
        {
            int changeDurationCnt = _durationCfg.Count;

            if (changeDurationCnt > 0)
            {
                NumberArea area = _durationCfg[0];
                if (changeDurationCnt > 1)
                {
                    int idx = Random.Range(0, changeDurationCnt);
                    area = _durationCfg[idx];
                }
                _changeDuration = Random.Range(area.Min, area.Max);
            }
            int changeSpeedCnt = _changeSpeedCfg.Count;

            if (changeSpeedCnt > 0)
            {
                NumberArea area = _changeSpeedCfg[0];
                if (changeSpeedCnt > 1)
                {
                    int idx = Random.Range(0, changeSpeedCnt);

                    area = _changeSpeedCfg[idx];
                }
                float endSpeed = Random.Range(area.Min, area.Max);
                _accSpeed = (endSpeed - _speed) / _changeDuration;
            }
        }
Exemple #2
0
        public void InitData(LuaTable table)
        {
            _initSpeedCfg   = table.Get <List <NumberArea> >("InitSpeed");
            _changeSpeedCfg = table.Get <List <NumberArea> >("ChangeSpeed");
            _durationCfg    = table.Get <List <NumberArea> >("ChangeDuration");

            int initCnt = _initSpeedCfg.Count;

            if (initCnt > 0)
            {
                NumberArea area = _initSpeedCfg[0];
                if (initCnt > 1)
                {
                    int idx = Random.Range(0, initCnt - 1);
                    area = _initSpeedCfg[idx];
                }
                _speed = Random.Range(area.Min, area.Max);
            }
        }
Exemple #3
0
        private void TrickUpdate()
        {
            if (_trickMode == TrickMode.None)
            {
                return;
            }
            float angleZ      = transform.localEulerAngles.z;
            bool  isClockwise = _speed < 0;
            bool  inArea      = _trickMax > 360 ? ((angleZ >= _trickMin && angleZ <= 360) || (angleZ >= 0 && angleZ <= (_trickMax - 360))) :
                                (angleZ >= _trickMin && angleZ <= _trickMax);

            if (_trickMode == TrickMode.Back)
            {
                if (_trickIn)
                {
                    //_speed *= 0.85f;
                }
                else
                {
                    _speed = _speed + _accSpeed * Time.fixedDeltaTime;
                }
                if (inArea)
                {
                    if (_trickIn)
                    {//开始反向
                        float sign = _speed > 0 ? 1 : -1;
                        sign       *= -1;
                        _speed      = 0;
                        _trickSpeed = Random.Range(100, 200) * sign;
                        float duration = Random.Range(0.35f, 0.8f);
                        _accSpeed = (_trickSpeed - _speed) / duration;
                        _trickIn  = false;
                        _tricked  = true;
                        // Debug.Log("Trick Back Back  _speed = " + _speed.ToString());
                    }
                }
                if (_tricked)
                {
                    if (Mathf.Abs(_speed) >= Mathf.Abs(_trickSpeed))
                    {
                        _state = WheelState.Rotate;
                        // Debug.Log("Trick Back End  _speed = " + _speed.ToString());
                        ReCaculateSpeed();
                        _tricked = false;
                        // Debug.Log("Trick B to Normal  _speed = " + _speed.ToString());
                        if (OnTrickOver != null)
                        {
                            OnTrickOver.Invoke();
                        }
                    }
                }
            }
            else
            {   //快速通过
                if (inArea)
                {
                    _speed   = _trickSpeed;
                    _tricked = true;
                }
                else
                {
                    if (_tricked)
                    {
                        Debug.Log("Trick Pass End  _speed = " + _speed.ToString());
                        _state   = WheelState.Rotate;
                        _tricked = false;
                        float sign           = _speed > 0 ? 1 : -1;
                        int   changeSpeedCnt = _changeSpeedCfg.Count;
                        if (changeSpeedCnt > 0)
                        {
                            NumberArea area = _changeSpeedCfg[0];
                            if (changeSpeedCnt > 1)
                            {
                                int idx = Random.Range(0, changeSpeedCnt);

                                area = _changeSpeedCfg[idx];
                            }
                            _speed = sign * Mathf.Abs(Random.Range(area.Min, area.Max));
                        }
                        ReCaculateSpeed();

                        Debug.Log("Trick Pass To Normal  _speed = " + _speed.ToString());
                        if (OnTrickOver != null)
                        {
                            OnTrickOver.Invoke();
                        }
                    }
                }
            }
            transform.Rotate(0, 0, _speed * Time.fixedDeltaTime);
        }