Beispiel #1
0
        static bool InteractionHighlight_Update_Pre(InteractionHighlight __instance)
        {
            #region quit
            if (!_highlightsToggle ||
                !__instance.m_renderer.TryAs(out ParticleSystemRenderer renderer) ||
                !renderer.GetComponent <ParticleSystem>().TryAssign(out var particleSystem))
            {
                return(true);
            }
            #endregion

            if (Time.renderedFrameCount % HIGHLIGHT_UPDATE_DURATION != 0 || renderer.enabled == __instance.ShouldShowHighlight())
            {
                return(false);
            }

            // Cache
            ParticleSystem.MainModule main = particleSystem.main;
            float intensity = _highlightsIntensity / 100f;
            Color newColor  = Color.white;

            // Choose color
            if (_highlightsColored)
            {
                newColor = HIGHLIGHT_COLOR_INTERACTION;
                if (__instance.TryAs(out ItemHighlight itemHighlight))
                {
                    newColor = HIGHLIGHT_COLOR_OTHER_ITEM;
                    if (itemHighlight.Item.TryAssign(out var item))
                    {
                        if (item is Equipment)
                        {
                            newColor = HIGHLIGHT_COLOR_EQUIP;
                        }
                        else if (item is ItemContainer)
                        {
                            newColor = HIGHLIGHT_COLOR_INTERACTION;
                        }
                        else if (item.IsIngestible())
                        {
                            newColor = HIGHLIGHT_COLOR_INGESTIBLE;
                        }
                    }
                }
            }

            // Apply intensity
            if (intensity <= 1)
            {
                newColor.a       *= intensity;
                main.maxParticles = intensity.MapFrom01(1, HIGHLIGHT_MAX_PARTICLES).Round();
                particleSystem.transform.localScale = Vector3.one;
            }
            else
            {
                intensity        -= 1;
                main.maxParticles = intensity.MapFrom01(1, 4).Mul(HIGHLIGHT_MAX_PARTICLES).Round();
                particleSystem.transform.localScale = intensity.MapFrom01(1, 1.5f).ToVector3();
            }

            // Apply color
            main.startColor = newColor;

            // Apply distance
            if (particleSystem.GetComponent <DisableParticlesWhenFar>().TryAssign(out var disableParticlesWhenFar))
            {
                disableParticlesWhenFar.m_sqrDist = _highlightsDistance.Value.Pow(2);
            }

            // Finalize
            renderer.enabled = !renderer.enabled;
            return(false);
        }
Beispiel #2
0
    void HandleInteraction(InteractionObject io)
    {
        if (io != currentInteractionObject || (io != null && io.IsDirty))
        {
            if (io == null)
            {
                currentInteractionObject.interactionSystem = null;
            }
            else
            {
                io.interactionSystem = this;
            }

            PopulateOptions(io);
            scrollIndex = 0;

            if (io != null && io.IsDirty)
            {
                io.ClearDirty();
            }
        }

        currentInteractionObject = io;

        if (io == null && lastHighlight != null)
        {
            lastHighlight.StopHighlighting();
            lastHighlight = null;
        }



        if (io == null)
        {
            return;
        }


        List <InteractionOption> ActiveOptions = io.Options.Where(a => a.Validate == null || a.Validate.Invoke()).ToList();

        if (io != null && ActiveOptions.Count > 0)
        {
            scrollIndex  = Mathf.Clamp(scrollIndex, 0f, ActiveOptions.Count - 1);
            scrollIndex += -Input.mouseScrollDelta.y;
            optionIndex  = Mathf.RoundToInt(scrollIndex);
        }



        if (UI_Options.Count >= optionIndex)
        {
            UI_Options[optionIndex].GetComponent <Selectable>().Select();
        }

        if (io.GetComponent <InteractionHighlight>())
        {
            var highlight = io.GetComponent <InteractionHighlight>();

            if (lastHighlight != null && lastHighlight != highlight)
            {
                lastHighlight.StopHighlighting();
            }

            lastHighlight = highlight;
            lastHighlight.Highlight();
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            io.OnInteraction(this, optionIndex);
        }
    }