Пример #1
0
        private void Start()
        {
            _trail = GetComponentInChildren <TrailRenderer>();
            MessageBroker.Default.Receive <GameStateChangeEvent>().Subscribe(ev =>
            {
                if (_levelCompletedTeweener != null)
                {
                    _levelCompletedTeweener.Kill(true);
                    _levelCompletedTeweener = null;
                }
                if (_levelDisposable != null)
                {
                    _levelDisposable.Dispose();
                }

                if (ev.State == GameState.Transmitting)
                {
                    var move      = GameCore.Instance.Player.transform.position - transform.position;
                    var diff      = Mathf.Abs(move.x) - Mathf.Abs(move.z);
                    var totalDist = Mathf.Abs(move.x) + Mathf.Abs(move.z);
                    var moveAmt   = totalDist / CubesController.Gap;
                    var dur       = GameCore.TransmissionDuration;
                    var seq       = DOTween.Sequence();
                    var unitDur   = dur / moveAmt;
                    if (diff > 0.001f)
                    {
                        var delta = diff * Mathf.Sign(move.x);
                        move.x   -= delta;
                        seq.Append(transform.DOMoveX(delta, unitDur * diff).SetRelative());
                        dur -= unitDur * diff;
                    }
                    else if (diff < -0.001f)
                    {
                        var delta = -diff * Mathf.Sign(move.z);
                        move.z   -= delta;
                        seq.Append(transform.DOMoveZ(delta, unitDur * -diff).SetRelative());
                        dur -= unitDur * -diff;
                    }
                    if (dur > 0.001f)
                    {
                        ZigZag(seq, move, dur);
                    }

                    var lastBoost = GameCore.Instance.Player.Boosts.LastOrDefault();
                    SetColor(lastBoost > 0 ?
                             ZCube.GetCubeColor((ZCubeType)lastBoost) : Color.white);
                }
                else if (ev.State == GameState.LevelCompleted)
                {
                    _levelDisposable = Observable.Timer(TimeSpan.FromSeconds(1f)).Subscribe(l =>
                    {
                        _levelCompletedTeweener = transform.DOMoveY(150, 3f);
                    });
                }
            });
        }
Пример #2
0
        private void Update()
        {
            var boosts = GameCore.Instance.Player.Boosts;

            for (var i = 0; i < Renderers.Length; i++)
            {
                var col = i < boosts.Count ?
                          ZCube.GetCubeColor((ZCubeType)boosts[i]) : new Color(0.33f, 0.33f, 0.33f);
                var rend = Renderers[i];
                rend.material.color = Color.Lerp(rend.material.color, col, Time.deltaTime * 10f);
            }
        }