protected virtual void TrySelectOption(int option, int player)
    {
        // Check if he was playing online or not...
        if (!UFE.isConnected)
        {
            // If it's a local game, go to the selected screen immediately...
            this.SelectOption(option, player);
        }
        else
        {
            // If it's an online game, we need to inform the other client about the screen we want to go...
            int localPlayer = UFE.GetLocalPlayer();
            if (localPlayer == player)
            {
                UFEController controller = UFE.GetController(localPlayer);

                // We don't invoke the OnstageSelected() method immediately because we are using the frame-delay
                // algorithm to keep players synchronized, so we can't invoke the OnstageSelected() method
                // until the other player has received the message with our choice.
                controller.GetType().GetMethod(
                    "RequestOptionSelection",
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy,
                    null,
                    new Type[] { typeof(int) },
                    null
                    ).Invoke(controller, new object[] { option });
            }
        }
    }
Ejemplo n.º 2
0
    public void TrySelectStage(int stageIndex)
    {
        // Check if he was playing online or not...
        if (!UFE.isConnected)
        {
            // If it's a local game, update the corresponding stage immediately...
            this.OnStageSelectionAllowed(stageIndex);
        }
        else
        {
            // If it's an online game, we only select the stage if it has been requested by Player 1...
            // But if player 2 wants to come back to character selection screen, we also allow that...
            int localPlayer = UFE.GetLocalPlayer();
            if (localPlayer == 1 || stageIndex < 0)
            {
                UFEController controller = UFE.GetController(localPlayer);

                // We don't invoke the OnstageSelected() method immediately because we are using the frame-delay
                // algorithm to keep players synchronized, so we can't invoke the OnstageSelected() method
                // until the other player has received the message with our choice.
                controller.GetType().GetMethod(
                    "RequestOptionSelection",
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy,
                    null,
                    new Type[] { typeof(int) },
                    null
                    ).Invoke(controller, new object[] { stageIndex });
            }
        }
    }
    public virtual void TrySelectCharacter(int characterIndex, int player)
    {
        // Check if he was playing online or not...
        if (!UFE.isConnected)
        {
            // If it's a local game, update the corresponding character immediately...
            this.OnCharacterSelectionAllowed(characterIndex, player);
        }
        else
        {
            // If it's an online game, find out if the requesting player is the local player
            // because we will only accept requests for the local player...
            int localPlayer = UFE.GetLocalPlayer();
            if (player == localPlayer)
            {
                UFEController controller = UFE.GetController(localPlayer);

                // We don't invoke the OnCharacterSelected() method immediately because we are using the frame-delay
                // algorithm to keep players synchronized, so we can't invoke the OnCharacterSelected() method
                // until the other player has received the message with our choice.
                controller.GetType().GetMethod(
                    "RequestOptionSelection",
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy,
                    null,
                    new Type[] { typeof(int) },
                    null
                    ).Invoke(controller, new object[] { characterIndex });
            }
        }
    }
Ejemplo n.º 4
0
    public static bool SpecialNavigationSystem(
        this UFEScreen screen,
        int player,
        MoveCursorCallback moveCursorCallback = null,
        ActionCallback confirmCallback        = null,
        ActionCallback cancelCallback         = null
        )
    {
        //-------------------------------------------------------------------------------------------------------------
        // Retrieve the controller assigned to specified player
        //-------------------------------------------------------------------------------------------------------------
        AbstractInputController inputController = UFE.GetController(player);

        if (inputController != null && UFE.eventSystem != null && UFE.eventSystem.isActiveAndEnabled)
        {
            return(UFEScreenExtensions.SpecialNavigationSystem(
                       inputController,
                       inputController.GetAxisRaw(inputController.horizontalAxis),
                       inputController.GetAxisRaw(inputController.verticalAxis),
                       inputController.GetButtonDown(inputController.horizontalAxis),
                       inputController.GetButtonDown(inputController.verticalAxis),
                       inputController.GetButtonDown(UFE.config.inputOptions.confirmButton),
                       inputController.GetButtonDown(UFE.config.inputOptions.cancelButton),
                       moveCursorCallback,
                       confirmCallback,
                       cancelCallback
                       ));
        }

        return(false);
    }
Ejemplo n.º 5
0
    protected virtual void SendNetworkPackage()
    {
        int count = this.inputBuffer.Count;

        FrameInput[] buffer = new FrameInput[count];
        for (int i = 0; i < count; ++i)
        {
            float horizontalAxis       = 0f;
            float horizontalAxisRaw    = 0f;
            float verticalAxis         = 0f;
            float verticalAxisRaw      = 0f;
            NetworkButtonPress buttons = NetworkButtonPress.None;

            foreach (KeyValuePair <InputReferences, InputEvents> pair in this.inputBuffer[i])
            {
                InputReferences inputReference = pair.Key;
                InputEvents     inputEvent     = pair.Value;

                if (inputReference.inputType == InputType.HorizontalAxis)
                {
                    horizontalAxis    = inputEvent.axis;
                    horizontalAxisRaw = inputEvent.axisRaw;
                }
                else if (inputReference.inputType == InputType.VerticalAxis)
                {
                    verticalAxis    = inputEvent.axis;
                    verticalAxisRaw = inputEvent.axisRaw;
                }
                else if (inputReference.inputType == InputType.Button && inputEvent.button)
                {
                    buttons |= inputReference.engineRelatedButton.ToNetworkButtonPress();
                }
            }

            buffer[i] = new FrameInput(
                horizontalAxis,
                horizontalAxisRaw,
                verticalAxis,
                verticalAxisRaw,
                buttons,
                this.optionSelections[i] == null ? -2 : this.optionSelections[i].Value
                );
        }


        InputBufferMessage msg = new InputBufferMessage(this.player, this.currentFrame, buffer);

        if (UFE.config.networkOptions.fakeNetwork)
        {
            RemotePlayerController remoteController = UFE.GetController(UFE.GetRemotePlayer()) as RemotePlayerController;
            remoteController.OnMessageReceived(msg.Serialize(), new NetworkMessageInfo());
        }
        else
        {
            UFE.multiplayerAPI.SendNetworkMessage(msg);
        }
    }
Ejemplo n.º 6
0
    public static bool DefaultNavigationSystem(
        this UFEScreen screen,
        int player,
        AudioClip moveCursorSound = null,
        AudioClip confirmSound    = null,
        AudioClip cancelSound     = null,
        Action cancelAction       = null
        )
    {
        //-------------------------------------------------------------------------------------------------------------
        // Retrieve the controller assigned to specified player
        //-------------------------------------------------------------------------------------------------------------
        AbstractInputController inputController = UFE.GetController(player);

        if (inputController != null && UFE.eventSystem != null && UFE.eventSystem.isActiveAndEnabled)
        {
            //---------------------------------------------------------------------------------------------------------
            // First, check if the current Selectable Object is an Input Field, because it's a special case...
            //---------------------------------------------------------------------------------------------------------
            GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;
            InputField inputField        = currentGameObject != null?currentGameObject.GetComponent <InputField>() : null;

            if (inputField != null)
            {
                //-----------------------------------------------------------------------------------------------------
                // If it's an Input Field, check if the user wants to write a text
                // or if he wants to move the caret or exit from the Input Field...
                //-----------------------------------------------------------------------------------------------------
                Vector3 direction =
                    (Input.GetKeyDown(KeyCode.UpArrow) ? Vector3.up : Vector3.zero) +
                    (Input.GetKeyDown(KeyCode.DownArrow) ? Vector3.down : Vector3.zero);

                if (
                    direction != Vector3.zero ||
                    Input.GetKeyDown(KeyCode.Tab) ||
                    Input.GetKeyDown(KeyCode.Return) ||
                    Input.GetKeyDown(KeyCode.KeypadEnter)
                    )
                {
                    Selectable previousSelectable = inputField;
                    Selectable nextSelectable     = null;

                    if (direction != Vector3.zero)
                    {
                        nextSelectable = currentGameObject.FindSelectable(direction, false);
                    }

                    if (nextSelectable == null || previousSelectable == nextSelectable)
                    {
                        nextSelectable = currentGameObject.FindSelectable(Vector3.right, false);

                        if (nextSelectable == null || previousSelectable == nextSelectable)
                        {
                            nextSelectable = currentGameObject.FindSelectable(Vector3.down, false);

                            if (nextSelectable == null || previousSelectable == nextSelectable)
                            {
                                nextSelectable = currentGameObject.FindSelectable(Vector3.left, false);

                                if (nextSelectable == null || previousSelectable == nextSelectable)
                                {
                                    nextSelectable = currentGameObject.FindSelectable(Vector3.up, false);
                                }
                            }
                        }
                    }

                    screen.HighlightOption(nextSelectable);
                }
                else
                {
                    inputField.OnUpdateSelected(new AxisEventData(UFE.eventSystem));
                }
                return(true);
            }
            else
            {
                //-----------------------------------------------------------------------------------------------------
                // Otherwise, invoke the "Special Navigation System" with the default functions
                //-----------------------------------------------------------------------------------------------------
                return(screen.SpecialNavigationSystem(
                           player,
                           new MoveCursorCallback(screen.DefaultMoveCursorAction, moveCursorSound),
                           new ActionCallback(UFE.eventSystem.currentSelectedGameObject.DefaultConfirmAction, confirmSound),
                           new ActionCallback(cancelAction.DefaultCancelAction, cancelSound)
                           ));
            }
        }
        return(false);
    }