Exemple #1
0
    public WordScramblePatch(BombComponent bombComponent) : base(bombComponent)
    {
        componentType    = componentType ?? (componentType = ReflectionHelper.FindType("WordScrambleModule"));
        AnswerField      = AnswerField ?? (AnswerField = componentType.GetField("Answer", BindingFlags.NonPublic | BindingFlags.Instance));
        SolutionField    = SolutionField ?? (SolutionField = componentType.GetField("_solution", BindingFlags.NonPublic | BindingFlags.Instance));
        EnterButtonField = EnterButtonField ?? (EnterButtonField = componentType.GetField("EnterButton", BindingFlags.Public | BindingFlags.Instance));

        component = bombComponent.GetComponent(componentType);
        if (AnswerField == null || SolutionField == null || EnterButtonField == null)
        {
            return;
        }

        if ((string)SolutionField.GetValue(component) == "sapper")
        {
            var enterButton         = (KMSelectable)EnterButtonField.GetValue(component);
            var previousInteraction = enterButton.OnInteract;
            enterButton.OnInteract = () =>
            {
                if ((string)AnswerField.GetValue(component) == "papers")
                {
                    SolutionField.SetValue(component, "papers");
                }

                previousInteraction();

                return(false);
            };
        }
    }
Exemple #2
0
    private void OnTriggerEnter(Collider other)
    {
        // If solution field is touched
        SolutionField solutionField = other.GetComponent <SolutionField>();

        if (solutionField && !solutionField.letters)
        {
            snapToField           = true;
            solutionField.letters = gameObject;
            fieldToSnap           = solutionField;
            currentController?.ReleaseObject();
        }

        if (other.CompareTag("Controller"))
        {
            currentController = other.GetComponent <Controller>();
        }
    }
Exemple #3
0
    private void OnTriggerStay(Collider other)
    {
        if (other.CompareTag("Controller"))
        {
            if (currentController?.objectInHand)
            {
                snapToField = false;
                if (fieldToSnap)
                {
                    fieldToSnap.letters = null;
                    fieldToSnap         = null;
                }

                if (!rb.useGravity)
                {
                    rb.useGravity = true;
                }
            }
        }
    }