コード例 #1
0
        public FlowPressure(int keyId, TimeSpan time, TimeSpan beatInterval)
        {
            FlowBeat = RhythmEngineUtility.GetFlowBeat(time, beatInterval);
            Score    = RhythmEngineUtility.GetScore(time, beatInterval);

            KeyId = keyId;
            Time  = time;

            IsSliderEnd = false;
        }
コード例 #2
0
        protected override void OnUpdate()
        {
            Entity cameraEntity   = default;
            float3 cameraPosition = default;

            if (m_CameraQuery.CalculateEntityCount() > 0)
            {
                cameraEntity = m_CameraQuery.GetSingletonEntity();
                var cameraObject = EntityManager.GetComponentObject <UnityEngine.Camera>(cameraEntity);
                cameraPosition = cameraObject.transform.position;
            }

            var player = this.GetFirstSelfGamePlayer();

            if (!EntityManager.TryGetComponentData(player, out GameRhythmInputComponent playerCommand))
            {
                Destroy();
                return;
            }

            var cameraState = this.GetComputedCameraState();

            var isWorldSpace = cameraState.StateData.Target != default;

            if (!EntityManager.HasComponent <UnitDescription>(cameraState.StateData.Target))
            {
                isWorldSpace = false;
            }

            var canvasRect = m_Canvas.pixelRect;

            if (isWorldSpace && cameraEntity != default)
            {
                var translation = EntityManager.GetComponentData <Translation>(cameraState.StateData.Target);
                m_Canvas.renderMode           = RenderMode.WorldSpace;
                m_Canvas.transform.position   = new Vector3(translation.Value.x, translation.Value.y + 25 * 0.05f, cameraPosition.z + 10);
                m_Canvas.transform.localScale = Vector3.one * 0.05f;

                var rectTransform = m_Canvas.GetComponent <RectTransform>();
                rectTransform.sizeDelta = new Vector2(100, 100);

                canvasRect.width  = 90;
                canvasRect.height = 105;
            }
            else
            {
                m_Canvas.transform.position = Vector3.zero;
                m_Canvas.renderMode         = RenderMode.ScreenSpaceCamera;
                m_Canvas.worldCamera        = EntityManager.GetComponentObject <UnityEngine.Camera>(cameraEntity);
            }

            var pixelRange = new float2(canvasRect.width, canvasRect.height);

            Entity engine = default;

            if (cameraState.StateData.Target != default)
            {
                engine = PlayerComponentFinder.GetRelativeChild <RhythmEngineDescription>(EntityManager, m_EngineQuery, cameraState.StateData.Target, player);
            }
            else
            {
                engine = PlayerComponentFinder.FromQueryFindPlayerChild(m_EngineQuery, player);
            }

            if (engine == default)
            {
                Destroy();
                return;
            }

            var process  = EntityManager.GetComponentData <RhythmEngineLocalState>(engine);
            var settings = EntityManager.GetComponentData <RhythmEngineSettings>(engine);

            if (!EntityManager.HasComponent <RhythmEngineIsPlaying>(engine) || RhythmEngineUtility.GetFlowBeat(process.Elapsed, settings.BeatInterval) < 0)
            {
                Destroy();
                return;
            }

            var key = 1;

            foreach (var ac in playerCommand.Actions)
            {
                if (!ac.InterFrame.HasBeenPressed(timeSystem.GetReport(player).Active))
                {
                    key++;
                    continue;
                }

                var keyRange = new float2();
                if (key <= 2)
                {
                    if (key == 1)
                    {
                        keyRange.x = -0.35f;
                    }
                    else
                    {
                        keyRange.x = 0.35f;
                    }

                    keyRange.x += Random.Range(-0.025f, 0.025f);
                    keyRange.y  = Random.Range(-0.1f, 0.1f);
                }
                else
                {
                    if (key == 3)
                    {
                        keyRange.y = -0.375f;
                    }
                    else
                    {
                        keyRange.y = 0.375f;
                    }

                    keyRange.y += Random.Range(-0.025f, 0.025f);
                    keyRange.x  = Random.Range(-0.1f, 0.1f);
                }

                keyRange += 0.5f;

                var width  = pixelRange.x * 0.5f;
                var height = pixelRange.y * 0.5f;
                var keyPos = new float2(math.lerp(-width, width, keyRange.x), math.lerp(-height, height, keyRange.y));

                var beGameObject = DrumBackendPools[key].Dequeue();
                using (new SetTemporaryInjectionWorld(World))
                {
                    beGameObject.name = $"BackendPressure (Key: {key})";
                    beGameObject.SetActive(true);
                    beGameObject.transform.SetParent(m_Canvas.transform, false);
                    beGameObject.transform.localScale = m_Canvas.renderMode == RenderMode.WorldSpace
                                                ? Vector3.one * 0.7f
                                                : 0.008f * math.min(width, height) * Vector3.one;
                    beGameObject.transform.localPosition = new Vector3(keyPos.x, keyPos.y, 0);
                    beGameObject.transform.rotation      = Quaternion.Euler(0, 0, Random.Range(-12.5f, 12.5f));
                }

                var backend = beGameObject.GetComponent <UIDrumPressureBackend>();
                backend.OnReset();
                backend.SetTarget(EntityManager);
                backend.SetPresentationFromPool(DrumPresentationPools[key]);

                var prevRand     = backend.rand;
                var absRealScore = math.abs(RhythmEngineUtility.GetScore(process.Elapsed, settings.BeatInterval));

                backend.play    = true;
                backend.key     = key;
                backend.rand    = DrumVariantCount[key];
                backend.perfect = absRealScore <= FlowPressure.Perfect;
                backend.endTime = Time.ElapsedTime + 1;

                var i = 0;
                while (prevRand == DrumVariantCount[key] && i < 3)
                {
                    DrumVariantCount[key] = Random.Range(0, 2);
                    i++;
                }

                key++;
            }

            Entities.ForEach((UIDrumPressureBackend backend) =>
            {
                var presentation = backend.Presentation;
                if (presentation != null)
                {
                    if (backend.play)
                    {
                        var color = presentation.colors[backend.key - 1];
                        color.a   = 1;
                        foreach (var effectImage in presentation.effectImages)
                        {
                            effectImage.color = color;
                        }

                        presentation.drumImage.sprite = presentation.sprites[backend.key - 1];

                        backend.play = false;

                        presentation.animator.SetBool(StrHashPerfect, backend.perfect);
                        presentation.animator.SetInteger(StrHashKey, backend.key);
                        presentation.animator.SetFloat(StrHashVariant, backend.rand);
                        presentation.animator.SetTrigger(StrHashPlay);
                    }

                    presentation.animator.Update(Time.DeltaTime);
                }

                if (backend.endTime > Time.ElapsedTime)
                {
                    return;
                }

                backend.Return(true, true);
            }).WithStructuralChanges().Run();

            return;
        }