Ejemplo n.º 1
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);
        }
    }