Пример #1
0
        protected override void PrepareValues()
        {
            if (m_LocalTextDb == null)
            {
                m_LocalTextDb = World.GetOrCreateSystem <LocalizationSystem>()
                                .LoadLocal("ingame_interface");
            }

            ComboString = m_LocalTextDb["ComboLabel", "FWorm"];
            FeverString = m_LocalTextDb["FeverLabel", "FWorm"];

            var player = this.GetFirstSelfGamePlayer();

            if (player == default)
            {
                return;
            }

            var cameraState = this.GetComputedCameraState().StateData;

            Entity engine;

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

            if (engine == default)
            {
                return;
            }

            var comboState    = EntityManager.GetComponentData <GameCombo.State>(engine);
            var comboSettings = EntityManager.GetComponentData <GameCombo.Settings>(engine);

            if (EntityManager.TryGetComponentData(engine, out RhythmSummonEnergy energy) &&
                EntityManager.TryGetComponentData(engine, out RhythmSummonEnergyMax energyMax))
            {
                SummonEnergyReal = real(energy.Value, energyMax.MaxValue);
            }

            ComboScoreReal = comboState.Score;
            ComboCount     = comboState.Count;
            IsFever        = comboSettings.CanEnterFever(comboState.Count, comboState.Score);

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

            Pulsation = real((int)(state.Elapsed.Ticks % settings.BeatInterval.Ticks), (int)settings.BeatInterval.Ticks);

            InterpolatedEnergyReal = Mathf.MoveTowards(math.lerp(InterpolatedEnergyReal, SummonEnergyReal, Time.DeltaTime), SummonEnergyReal, Time.DeltaTime * 0.25f);

            var score = Math.Max((int)comboState.Score + Math.Max(comboState.Score >= 1.9 ? 1 + comboState.Count : 0, 0), comboState.Count);

            if (score < 0)
            {
                score = 0;
            }
            if (score != m_PreviousScore)
            {
                m_PreviousScoreInterpol = m_PreviousScore;
                m_PreviousScore         = score;
            }

            m_PreviousScoreInterpol = Mathf.MoveTowards(math.lerp(m_PreviousScoreInterpol, score, Time.DeltaTime * 5), score, Time.DeltaTime);
        }
Пример #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;
        }