示例#1
0
        private void Update()
        {
            this._container.transform.localScale = (this.rotationDirection == RotationDirection.CLOCKWISE) ? new Vector3(1.0f, 1.0f, 1.0f) : new Vector3(-1.0f, 1.0f, 1.0f);

            foreach (KeyValuePair <RhythmSequenceKeyframe, RhythmSequenceKeyframeVisualizer> pair in this._visualizerMap)
            {
                RhythmSequenceKeyframe           keyframe           = pair.Key;
                RhythmSequenceKeyframeVisualizer keyframeVisualizer = pair.Value;

                float timePassed    = this._sequence.GetTimePassed();
                float timeRemaining = keyframe.timePassed - timePassed;

                float angle = 180.0f * Mathf.Clamp(1.0f - timeRemaining, 0.0f, 1.2f);

                Vector3 computedPosition = this._radius * (Quaternion.AngleAxis(angle, -Vector3.forward) * new Vector3(-1.0f, 0.0f, 0.0f));
                keyframeVisualizer.transform.localPosition = computedPosition;

                Color visualColor = Color.red;
                if (Mathf.Abs(timeRemaining) <= GameConstants.Instance.kPerfectTimingThreshold)
                {
                    visualColor = Color.green;
                }
                else if (Mathf.Abs(timeRemaining) <= GameConstants.Instance.kGoodTimingThreshold)
                {
                    visualColor = Color.yellow;
                }
                visualColor = new Color(visualColor.r, visualColor.g, visualColor.b, 0.8f);
                keyframeVisualizer.SetColor(visualColor);

                // keyframeVisualizer.UpdateWithTimeRemaining(timeRemaining);
            }
        }
示例#2
0
        private void HandleTap()
        {
            if (!this._sequencePlaying)
            {
                return;
            }

            float timePassed = Time.time - this._startTime;

            RhythmSequenceKeyframe closestKeyframe = null;
            float smallestTimePassedDifference     = float.MaxValue;

            foreach (RhythmSequenceKeyframe keyframe in this._keyframes)
            {
                if (this.IsKeyframeCompleted(keyframe))
                {
                    continue;
                }

                float timePassedDifference = Mathf.Abs(timePassed - keyframe.timePassed);
                if (timePassedDifference < smallestTimePassedDifference)
                {
                    smallestTimePassedDifference = timePassedDifference;
                    closestKeyframe = keyframe;
                }
            }

            if (closestKeyframe == null)
            {
                Debug.Log("No closest keyframe found.");
                return;
            }

            if (smallestTimePassedDifference <= GameConstants.Instance.kPerfectTimingThreshold)
            {
                this.OnKeyframeHit.Invoke(closestKeyframe, RhythmSequenceKeyframeRating.PERFECT);
            }
            else if (smallestTimePassedDifference <= GameConstants.Instance.kGoodTimingThreshold)
            {
                this.OnKeyframeHit.Invoke(closestKeyframe, RhythmSequenceKeyframeRating.GOOD);
            }
            else
            {
                // miss
                this.OnKeyframeHit.Invoke(closestKeyframe, RhythmSequenceKeyframeRating.MISS);
            }
            this.CompleteKeyframe(closestKeyframe);
        }
示例#3
0
        private void HandleKeyframeHit(RhythmSequenceKeyframe keyframe, RhythmSequenceKeyframeRating rating)
        {
            string prefabName = "";

            switch (rating)
            {
            case RhythmSequenceKeyframeRating.PERFECT:
                prefabName = "PerfectFloatingTextSFX";
                CameraController.Main <CameraController>().Shake(GameConstants.Instance.kAttackShakeMagnitude * 0.6f, GameConstants.Instance.kAttackShakeDuration * 2.0f);
                SoundManager.Instance.PlaySoundFile(2);
                break;

            case RhythmSequenceKeyframeRating.GOOD:
                prefabName = "GoodFloatingTextSFX";
                CameraController.Main <CameraController>().Shake(GameConstants.Instance.kAttackShakeMagnitude * 0.4f, GameConstants.Instance.kAttackShakeDuration * 1.5f);
                SoundManager.Instance.PlaySoundFile(0);
                break;

            case RhythmSequenceKeyframeRating.MISS:
            default:
                prefabName = "MissFloatingTextSFX";
                CameraController.Main <CameraController>().Shake(GameConstants.Instance.kAttackShakeMagnitude * 0.2f, GameConstants.Instance.kAttackShakeDuration);
                SoundManager.Instance.PlaySoundFile(1);
                break;
            }

            GameObject floatingTextSFXObject = Toolbox.GetInstance <ObjectPoolManager>().Instantiate(prefabName);

            floatingTextSFXObject.transform.SetParent(CanvasUtil.MainCanvas.transform, worldPositionStays: false);

            RectTransform rectTransform    = (RectTransform)floatingTextSFXObject.transform;
            Vector2       anchoredPosition = rectTransform.anchoredPosition;

            if (this.transform.position.x > 0.0f)
            {
                anchoredPosition = anchoredPosition.SetX(-anchoredPosition.x);
            }

            rectTransform.anchoredPosition = anchoredPosition + (Vector2)Camera.main.WorldToScreenPoint(this.transform.position);

            FloatingTextSFX floatingTextSFX = floatingTextSFXObject.GetComponent <FloatingTextSFX>();

            floatingTextSFX.SetText(rating.ToString());

            this._visualizerMap[keyframe].FadeAway();
            this._visualizerMap.Remove(keyframe);
        }
示例#4
0
        private void HandleKeyframeHit(RhythmSequenceKeyframe keyframe, RhythmSequenceKeyframeRating rating)
        {
            switch (rating)
            {
            case RhythmSequenceKeyframeRating.PERFECT:
                this._result.perfectHitCount++;
                break;

            case RhythmSequenceKeyframeRating.GOOD:
                this._result.goodHitCount++;
                break;

            case RhythmSequenceKeyframeRating.MISS:
                this._result.missCount++;
                break;
            }
        }
示例#5
0
        private void CompleteKeyframe(RhythmSequenceKeyframe keyframe)
        {
            this._completedKeyframes[keyframe] = true;

            bool allCompleted = true;

            foreach (RhythmSequenceKeyframe currenKeyframe in this._keyframes)
            {
                if (!this.IsKeyframeCompleted(currenKeyframe))
                {
                    allCompleted = false;
                }
            }

            if (allCompleted)
            {
                this.FinishSequence();
            }
        }
示例#6
0
 public bool IsKeyframeCompleted(RhythmSequenceKeyframe keyframe)
 {
     return(this._completedKeyframes.SafeGet(keyframe, false));
 }