/// <summary> Converts a controllerID (AI or Network) to a PlayerID </summary> public static EPlayerID GetPlayerIDFrom(EControllerID controllerID) { EPlayerID result = EPlayerID.NONE; switch (controllerID) { /* AI */ case EControllerID.AI_1: result = EPlayerID.PLAYER_1; break; case EControllerID.AI_2: result = EPlayerID.PLAYER_2; break; case EControllerID.AI_3: result = EPlayerID.PLAYER_3; break; case EControllerID.AI_4: result = EPlayerID.PLAYER_4; break; } return(result); }
protected void InvokeButtonReleased(EControllerID controllerID, EInputButton inputButton) { if (ButtonReleased != null) { ButtonReleased.Invoke(controllerID, inputButton); } }
public void LeavePlayer(EPlayerID playerID) { if ((IS_KEY_CONTAINED(partyStatusMap, playerID)) && (IS_TRUE(partyStatusMap[playerID].HasJoined))) { // Destroy Player if (ActivePlayers.ContainsKey(playerID)) { DestroyPlayer(playerID); } // Reset controller to Spectator EControllerID controllerID = partyStatusMap[playerID].ControllerID; if (IS_KEY_CONTAINED(ControllersMap, controllerID)) { ControllersMap[controllerID] = EPlayerID.SPECTATOR; } // Reset entry of playerID in party status partyStatusMap[playerID] = new PlayerJoinStatus(EControllerID.NONE); // Trigger global event BEventsCollection.PLAYERS_PlayerLeft.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID)); // Are the rest of the joined players ready? CheckIfAllPlayersAreReady(); } }
private void On_INPUT_ControllerDisconnected(BEHandle <EControllerID> eventHandle) { EControllerID controllerID = eventHandle.Arg1; if (IS_KEY_CONTAINED(ControllersMap, controllerID)) { EPlayerID playerID = ControllersMap[controllerID]; // Was a joined controller? if (playerID != EPlayerID.SPECTATOR && IS_KEY_CONTAINED(partyStatusMap, playerID)) { partyStatusMap[playerID].Flush(); } // Destroy Player if (ActivePlayers.ContainsKey(playerID)) { DestroyPlayer(playerID); } ControllersMap.Remove(controllerID); BEventsCollection.PLAYERS_PlayerLeft.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID)); } }
protected void InvokeAxisUpdated(EControllerID controllerID, EInputAxis inputAxis, float x, float y) { if (AxisUpdated != null) { AxisUpdated.Invoke(controllerID, inputAxis, x, y); } }
/// <summary> /// Called from a NCPlayerListener when spawned to connect to the next available ControllerID /// </summary> /// <param name="playerInput"> New NCPlayerListener </param> /// <returns> Assigned ControllerID </returns> public EControllerID OnNewNCJoined(MirrorPlayerNCListener playerNCListener) { IS_NOT_NULL(playerNCListener); // Assign a ControllerID EControllerID controllerID = GetNextFreeNetworkControllerID(); if (controllerID != EControllerID.NONE) { // Connect controller on Input Manager if (InputManager.Instance.ConnectController(controllerID) == true) { LogConsole("Adding new Player NC Listener : " + playerNCListener.gameObject.name); connectedNetworkControllers.Add(controllerID, playerNCListener); // Bind Input events playerNCListener.ButtonPressed += PlayerNCListener_OnButtonPressed; playerNCListener.ButtonReleased += PlayerNCListener_OnButtonReleased; playerNCListener.JoystickMoved += PlayerNCListener_OnJoystickMoved; } else { return(EControllerID.NONE); } } else { LogConsoleWarning("No free Controller ID found for new connected Net Controller : " + playerNCListener.IpAdress); } return(controllerID); }
/// <summary> /// Called from a PlayerInputListener when spawned to connect to the next available ControllerID /// </summary> /// <param name="playerInput"> New player input listener </param> /// <returns> Assigned ControllerID </returns> public EControllerID OnNewDeviceJoined(PlayerInputListener playerInputListener) { IS_NOT_NULL(playerInputListener); // Assign a ControllerID EControllerID controllerID = GetNextFreeDeviceControllerID(); if (controllerID != EControllerID.NONE) { // Connect controller on Input Manager if (InputManager.Instance.ConnectController(controllerID) == true) { connectedDeviceControllers.Add(controllerID, playerInputListener); // Bind Input events playerInputListener.ButtonPressed += On_PlayerInputListener_ButtonPressed; playerInputListener.ButtonReleased += On_PlayerInputListener_ButtonReleased; } else { return(EControllerID.NONE); } } else { LogConsoleWarning("No free Controller ID found for new connected device : " + playerInputListener.DeviceName); } return(controllerID); }
public EPlayerID GetAssignedPlayerID(EControllerID controllerID) { if (IS_KEY_CONTAINED(ControllersMap, controllerID)) { return(ControllersMap[controllerID]); } return(EPlayerID.NONE); }
private void On_INPUT_ControllerConnected(BEHandle <EControllerID> eventHandle) { EControllerID controllerID = eventHandle.Arg1; // Add connected controller as a spectator if (IS_KEY_NOT_CONTAINED(ControllersMap, controllerID)) { ControllersMap.Add(controllerID, EPlayerID.SPECTATOR); BEventsCollection.PLAYERS_PlayerJoined.Invoke(new BEHandle <EPlayerID, EControllerID>(EPlayerID.SPECTATOR, controllerID)); } }
private void On_InputSource_ButtonReleased(EControllerID controllerID, EInputButton inputButton) { if (IS_VALUE_CONTAINED(connectedControllers, controllerID)) { EPlayerID playerID = PlayerManager.Instance.GetAssignedPlayerID(controllerID); if (inputButton != EInputButton.NONE) { BEventsCollection.INPUT_ButtonReleased.Invoke(new BEHandle <EControllerID, EInputButton>(controllerID, inputButton), BEventReplicationType.LOCAL, MotherOfManagers.Instance.DebugButtonEvents); } } }
private void On_NETWORK_NewNetworkIDConnected(BEHandle <ENetworkID> handle) { if (BEventManager.Instance.LocalNetworkID == ENetworkID.HOST) { EControllerID newControllerID = BUtils.GetControllerIDFrom(handle.Arg1); if (IS_NOT_NONE(newControllerID) && InputManager.Instance.IsControllerConnected(newControllerID) == false) { StartCoroutine(JoinConnectedPlayerCoroutine(handle, newControllerID)); } } }
private void On_InputSource_JoystickMoved(EControllerID controllerID, EInputAxis inputAxis, float x, float y) { if (IS_VALUE_CONTAINED(connectedControllers, controllerID)) { EPlayerID playerID = PlayerManager.Instance.GetAssignedPlayerID(controllerID); if (inputAxis != EInputAxis.NONE) { BEventsCollection.INPUT_AxisUpdated.Invoke(new BEHandle <EControllerID, EInputAxis, float, float>(controllerID, inputAxis, x, y), BEventReplicationType.LOCAL, MotherOfManagers.Instance.DebugJoystickEvents); } } }
public void PlayerNCListener_OnButtonPressed(EControllerID controllerID, EInputButton inputButton) { LogConsole("ButtonPressed"); if (IS_KEY_CONTAINED(connectedNetworkControllers, controllerID)) { if (IS_NOT_NONE(inputButton)) { InvokeButtonPressed(controllerID, inputButton); } } }
public static ENetworkID GetNetworkIDFrom(EControllerID controllerID) { switch (controllerID) { case EControllerID.NET_HOST: return(ENetworkID.HOST); case EControllerID.NET_CLIENT_1: return(ENetworkID.CLIENT_1); case EControllerID.NET_CLIENT_2: return(ENetworkID.CLIENT_2); case EControllerID.NET_CLIENT_3: return(ENetworkID.CLIENT_3); case EControllerID.NET_CLIENT_4: return(ENetworkID.CLIENT_4); case EControllerID.NET_CLIENT_5: return(ENetworkID.CLIENT_5); case EControllerID.NET_CLIENT_6: return(ENetworkID.CLIENT_6); case EControllerID.NET_CLIENT_7: return(ENetworkID.CLIENT_7); case EControllerID.NET_CLIENT_8: return(ENetworkID.CLIENT_8); case EControllerID.NET_CLIENT_9: return(ENetworkID.CLIENT_9); case EControllerID.NET_CLIENT_10: return(ENetworkID.CLIENT_10); case EControllerID.NET_CLIENT_11: return(ENetworkID.CLIENT_11); case EControllerID.NET_CLIENT_12: return(ENetworkID.CLIENT_12); case EControllerID.NET_CLIENT_13: return(ENetworkID.CLIENT_13); default: return(ENetworkID.NONE); } }
public void PlayerNCListener_OnJoystickMoved(EControllerID controllerID, EInputAxis inputAxis, float x, float y) { if (IS_KEY_CONTAINED(connectedNetworkControllers, controllerID)) { if (IS_NOT_NONE(inputAxis)) { InvokeAxisUpdated(controllerID, inputAxis, x, y); } // Debug debugX = x; debugY = y; } }
// TODO public void OnDeviceHasLeft(EControllerID controllerID, PlayerInputListener playerInputListener) { //IS_VALID(playerInputListener); //if ((connectedControllers.ContainsKey(controllerID) // && (connectedControllers[controllerID] == playerInputListener)) //{ //} //else //{ // LogConsoleWarning("An invalid device has left : " + playerInputListener.DeviceName); //} }
private void Cmd_OnRequestControllerID(NetworkIdentity networkIdentity) { Debug.Log("Cmd_OnRequestControllerID : " + networkIdentity.connectionToClient.ToString()); NetControllerInputSource netControllerInputSource = InputManager.Instance.GetInputSource <NetControllerInputSource>(); if (netControllerInputSource) { EControllerID newControllerID = netControllerInputSource.OnNewNCJoined(this); Debug.Log("Assigned controller ID : " + newControllerID); Target_OnAssignedControllerID(networkIdentity.connectionToClient, newControllerID); } }
private EControllerID GetNextFreeDeviceControllerID() { EControllerID controllerID = EControllerID.NONE; foreach (EControllerID controllerIDitr in BConsts.DEVICE_CONTROLLERS) { if (connectedDeviceControllers.ContainsKey(controllerIDitr) == false) { controllerID = controllerIDitr; break; } } return(controllerID); }
private EControllerID GetNextFreeNetworkControllerID() { LogConsoleError("Depricated code!!"); EControllerID controllerID = EControllerID.NONE; //foreach (EControllerID controllerIDitr in BConsts.NETWORK_CONTROLLERS) //{ // if (connectedNetworkControllers.ContainsKey(controllerIDitr) == false) // { // controllerID = controllerIDitr; // break; // } //} return(controllerID); }
private EPlayerID JoinNextAIPlayer(EControllerID controllerID) { foreach (var pair in partyStatusMap) { EPlayerID playerID = pair.Key; PlayerJoinStatus playerJoinStatus = pair.Value; if (playerJoinStatus.HasJoined == false) { JoinPlayer(playerID, controllerID); return(playerID); } } return(EPlayerID.NONE); }
protected override void Start() { base.Start(); if (IS_NOT_NULL(myPlayerInput)) { // Inform Device Input Source that a new Player Input has joined and become a ControllerID DeviceInputSource deviceInputSource = InputManager.Instance.GetInputSource <DeviceInputSource>(); if (IS_NOT_NULL(deviceInputSource)) { myControllerID = deviceInputSource.OnNewDeviceJoined(this); IS_NOT_NONE(myControllerID); } } }
public bool DisconnectController(EControllerID controllerID) { if (connectedControllers.Contains(controllerID) == false) { LogConsoleError("Trying to disconnect a controller that is not connected."); return(false); } connectedControllers.Remove(controllerID); // Invoke event BEHandle <EControllerID> controllerDisconnected = new BEHandle <EControllerID>(controllerID); BEventsCollection.INPUT_ControllerDisconnected.Invoke(controllerDisconnected); return(true); }
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) { position = EditorGUI.PrefixLabel (position, label); EditorGUI.indentLevel = 0; Rect menu = position; menu.width = EditorGUIUtility.singleLineHeight; position.width -= menu.width; menu.x += position.width; property.isExpanded = 0 < EditorGUI.Popup(menu, property.isExpanded ? 1:0, inspectorOptions); if (!property.isExpanded) property.intValue = (int)(KeyCode)EditorGUI.EnumPopup (position, (KeyCode)property.intValue); else{ bool valid = true; EXboxButton button = (EXboxButton) 0; EControllerID id = (EControllerID) 0; id = EControllerID.any; int bneh = property.intValue; if (bneh < (int)KeyCode.JoystickButton0 || bneh > (int)KeyCode.Joystick8Button9) valid = false; else { bneh -= (int)KeyCode.JoystickButton0; while (bneh > 19) { bneh -= 20; id++; } button = (EXboxButton)(bneh + (int)KeyCode.JoystickButton0); } position.width *= 2 /3f; button = (EXboxButton)EditorGUI.EnumPopup (position, button); if (!valid) EditorGUI.LabelField (position, " <not a controller button>"); position.x += position.width; position.width *= 1 /2f; id = (EControllerID)EditorGUI.EnumPopup (position, id); property.intValue = (int)button + (valid ? (int)id*20 : 0); } }//
public bool JoinPlayer(EPlayerID playerID, EControllerID controllerID) { if (IS_KEY_CONTAINED(partyStatusMap, playerID) && IS_KEY_CONTAINED(ControllersMap, controllerID) && IS_NOT_TRUE(partyStatusMap[playerID].HasJoined)) { partyStatusMap[playerID].ControllerID = controllerID; partyStatusMap[playerID].HasJoined = true; // Update assigned PlayerID in the controller map (instead of Spectator) ControllersMap[controllerID] = playerID; BEventsCollection.PLAYERS_PlayerJoined.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID)); return(true); } return(false); }
//[SerializeField] //private BText ownPlayerIDText; #endregion #region Private Variables #endregion #region Life Cycle protected override void Update() { base.Update(); if (joinedPlayersText) { string joinedPlayers = ""; foreach (EPlayerID playerID in PlayerManager.Instance.GetJoinedPlayers()) { EControllerID controllerID = PlayerManager.Instance.GetAssignedControllerID(playerID); joinedPlayers += playerID + " : " + controllerID + "\n"; } joinedPlayersText.SetText(joinedPlayers); } //if (ownPlayerIDText) //{ // ownPlayerIDText.SetText(PlayerManager.Instance.player) //} }
private void On_PLAYERS_PlayerSpawned(BEHandle <EPlayerID, IPlayer> bHandle) { // Add an AIPlayerController on the spawned player if he's an AI EPlayerID playerID = bHandle.Arg1; EControllerID controllerID = PlayerManager.Instance.GetAssignedControllerID(playerID); if ((controllerID.ContainedIn(BConsts.AI_CONTROLLERS)) && (IS_KEY_CONTAINED(PlayerManager.Instance.ActivePlayers, playerID)) && (IS_NOT_NULL(PlayerManager.Instance.ActivePlayers[playerID]))) { AbstractPlayer player = PlayerManager.Instance.ActivePlayers[playerID]; AbstractAIPlayerController aIPlayerController = player.gameObject.AddComponent <AbstractAIPlayerController>(); aIPlayerController.AxisUpdated += On_AIPlayerController_JoystickMoved; aIPlayerController.ButtonPressed += On_AIPlayerController_ButtonPressed; aIPlayerController.ButtonReleased += On_AIPlayerController_ButtonReleased; aIPlayerController.WillGetDestroyed += On_AIPlayerController_WillGetDestroyed; aIPlayerController.InitializeAIController(this); activeAIControllers.Add(aIPlayerController); } }
private void Cmd_OnButtonReleased(EControllerID controllerID, EInputButton inputButton) { Debug.Log("Cmd_OnButtonReleased : " + inputButton + " - " + controllerID); // temporary solution NetControllerInputSource netControllerInputSource = InputManager.Instance.GetInputSource <NetControllerInputSource>(); if (netControllerInputSource) { Debug.Log("Calling ButtonReleased: " + inputButton + " - " + controllerID); netControllerInputSource.PlayerNCListener_OnButtonReleased(controllerID, inputButton); } // TODO: Fix //if (ButtonReleased != null) //{ // ButtonReleased.Invoke(controllerID, inputButton); //} }
private void Cmd_OnJoystickMoved(EControllerID controllerID, EInputAxis joystickType, float x, float y) { Debug.Log("Cmd_OnJoystickMoved : " + joystickType + " - " + controllerID); // temporary solution NetControllerInputSource netControllerInputSource = InputManager.Instance.GetInputSource <NetControllerInputSource>(); if (netControllerInputSource) { netControllerInputSource.PlayerNCListener_OnJoystickMoved(controllerID, joystickType, x, y); } // TODO : Fix //if (JoystickMoved != null) //{ // Debug.Log("JoystickMoved"); // JoystickMoved.Invoke(controllerID, joystickType, x, y); //} }
private void On_NETWORK_NetworkIDDisconnected(BEHandle <ENetworkID> handle) { if (BEventManager.Instance.LocalNetworkID == ENetworkID.HOST) { EControllerID controllerID = BUtils.GetControllerIDFrom(handle.Arg1); if (IS_NOT_NONE(controllerID) && IS_TRUE(InputManager.Instance.IsControllerConnected(controllerID)) && IS_KEY_CONTAINED(partyMap, controllerID)) { EPlayerID playerID = partyMap[controllerID]; if (IS_NOT_NONE(playerID)) { partyMap.Remove(controllerID); // Disconnect Controller (-> Remove from party) InputManager.Instance.DisconnectController(controllerID); BEventsCollection.NETWORK_PlayerLeft.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID), BEventReplicationType.TO_ALL_OTHERS, true); } } } }
public bool ConnectController(EControllerID controllerID) { if (controllerID == EControllerID.NONE) { LogConsoleError("Trying to connect a controller that is NONE."); return(false); } if (connectedControllers.Contains(controllerID)) { LogConsoleError("Trying to connect a controller that is already connected."); return(false); } connectedControllers.Add(controllerID); // Invoke event BEHandle <EControllerID> controllerConnected = new BEHandle <EControllerID>(controllerID); BEventsCollection.INPUT_ControllerConnected.Invoke(controllerConnected); return(true); }