Ejemplo n.º 1
0
 public void Assign(string name)
 {
     this.enabled = true;
     foreach (ActionMapSlot actionMapSlot in playerInput.actionMaps)
     {
         ActionMapInput actionMapInput = ActionMapInput.Create(actionMapSlot.actionMap);
         actionMapInput.TryInitializeWithDevices(playerInput.handle.GetApplicableDevices());
         actionMapInput.active          = actionMapSlot.active;
         actionMapInput.blockSubsequent = actionMapSlot.blockSubsequent;
         playerInput.handle.maps.Add(actionMapInput);
     }
     controlls  = playerInput.GetActions <ChickenInput_Xbox>();
     this.name += "(" + name + ")";
 }
Ejemplo n.º 2
0
        public ActionMapInput CreateActionMapInput(ActionMap map, InputDevice device)
        {
            // Check for improper use of action maps first
            if (device != null && !IsValidActionMapForDevice(map, device))
            {
                return(null);
            }

            var devices = device == null?GetSystemDevices() : new List <InputDevice>
            {
                device
            };

            var actionMapInput = ActionMapInput.Create(map);

            // It's possible that there are no suitable control schemes for the device that is being initialized,
            // so ActionMapInput can't be marked active
            var successfulInitialization = false;

            if (actionMapInput.TryInitializeWithDevices(devices))
            {
                successfulInitialization = true;
            }
            else
            {
                // For two-handed tools, the single device won't work, so collect the devices from the action map
                devices = InputUtils.CollectInputDevicesFromActionMaps(new List <ActionMap>()
                {
                    map
                });
                if (actionMapInput.TryInitializeWithDevices(devices))
                {
                    successfulInitialization = true;
                }
            }

            if (successfulInitialization)
            {
                actionMapInput.autoReinitialize = false;

                // Resetting AMIs cause all AMIs (active or not) that use the same sources to be reset, which causes
                // problems (e.g. dropping objects because wasJustPressed becomes true when reset)
                actionMapInput.resetOnActiveChanged = false;
                actionMapInput.active = true;
            }

            return(actionMapInput);
        }
    public void Start()
    {
        // Create a global player handle that listen to all relevant devices not already used
        // by other player handles.
        globalHandle        = PlayerHandleManager.GetNewPlayerHandle();
        globalHandle.global = true;
        List <ActionMapSlot> actionMaps = playerPrefab.GetComponent <PlayerInput>().actionMaps;

        foreach (ActionMapSlot actionMapSlot in actionMaps)
        {
            ActionMapInput actionMapInput = ActionMapInput.Create(actionMapSlot.actionMap);
            actionMapInput.TryInitializeWithDevices(globalHandle.GetApplicableDevices());
            actionMapInput.active          = actionMapSlot.active;
            actionMapInput.blockSubsequent = actionMapSlot.blockSubsequent;
            globalHandle.maps.Add(actionMapInput);
        }

        joinAction.Bind(globalHandle);
        leaveAction.Bind(globalHandle);
    }
Ejemplo n.º 4
0
    private ActionMapInput CreateActionMapInput(ActionMap map, InputDevice device)
    {
        // Check for improper use of action maps first
        if (device != null && !IsValidActionMapForDevice(map, device))
        {
            return(null);
        }

        var devices = device == null?m_PlayerHandle.GetApplicableDevices() : new InputDevice[]
        {
            device
        };

        var actionMapInput = ActionMapInput.Create(map);

        // It's possible that there are no suitable control schemes for the device that is being initialized,
        // so ActionMapInput can't be marked active
        if (actionMapInput.TryInitializeWithDevices(devices))
        {
            actionMapInput.autoReinitialize = false;
            actionMapInput.active           = true;
        }
        return(actionMapInput);
    }
    public void Update()
    {
        // Listen to if the join button was pressed on a yet unassigned device.
        if (joinAction.control.wasJustPressed)
        {
            // These are the devices currently active in the global player handle.
            List <InputDevice> devices = globalHandle.GetActions(joinAction.action.actionMap).GetCurrentlyUsedDevices();

            PlayerHandle handle = PlayerHandleManager.GetNewPlayerHandle();
            foreach (var device in devices)
            {
                handle.AssignDevice(device, true);
            }

            foreach (ActionMapSlot actionMapSlot in playerPrefab.actionMaps)
            {
                ActionMapInput map = ActionMapInput.Create(actionMapSlot.actionMap);
                map.TryInitializeWithDevices(handle.GetApplicableDevices());
                map.blockSubsequent = actionMapSlot.blockSubsequent;

                // Activate the ActionMap that is used to join,
                // disregard active state from ActionMapSlots for now (wait until instantiating player).
                if (map.actionMap == joinAction.action.actionMap)
                {
                    map.active = true;
                }

                handle.maps.Add(map);
            }

            players.Add(new PlayerInfo(handle, joinAction, leaveAction));
        }

        int readyCount = 0;

        for (int i = players.Count - 1; i >= 0; i--)
        {
            var player = players[i];
            if (!player.ready)
            {
                if (player.joinControl.wasJustPressed)
                {
                    player.ready = true;
                }
                if (player.leaveControl.wasJustPressed)
                {
                    player.playerHandle.Destroy();
                    players.Remove(player);
                    continue;
                }
            }
            else
            {
                if (player.joinControl.wasJustPressed || player.leaveControl.wasJustPressed)
                {
                    player.ready = false;
                }
            }
            if (player.ready)
            {
                readyCount++;
            }
        }

        if (readyCount >= 1 && (players.Count - readyCount) == 0)
        {
            StartGame();
        }
    }