private void Initialize()
    {
        gamepad = GetComponent <Fyo.SocketGamepad>();

        // Find the controller we want to manage
        Player player = ReInput.players.GetPlayer(playerId);                                    // get the player

        controller = player.controllers.GetControllerWithTag <CustomController>(controllerTag); // get the controller

        if (controller == null)
        {
            Debug.LogError("A matching controller was not found for tag \"" + controllerTag + "\"");
        }

        // Callback Update Method:
        // Set callbacks to retrieve current element values.
        // This is a different way of updating the element values in the controller.
        // You set an update function for axes and buttons and these functions will be called
        // to retrieve the current source element values on every update loop in which input is updated.
        if (controller != null)
        {
            controller.SetAxisUpdateCallback(GetAxisValueCallback);
            controller.SetButtonUpdateCallback(GetButtonValueCallback);
        }

        initialized = true;
    }
예제 #2
0
        /// <summary>
        /// Adds a SocketGamepad for local testing (input communication only, through use of SocketGamepadLocalInputAdapter)
        /// </summary>
        /// <param name="gamepad">SocketGamepad virtual object</param>
        public void AddExistingGamepad(SocketGamepad gamepad)
        {
            if (gamepad != null)
            {
                if (!Gamepads.Contains(gamepad))
                {
                    Gamepads.Add(gamepad);

                    if (gamepad.Controller != DefaultController)
                    {
                        JSONObject msg = JSONObject.CreateStringObject(DefaultController);
                        socket.Emit("SGRedirectMsg", msg);
                    }

                    OnGamepadPluggedIn(gamepad);
                }
                else
                {
                    Debug.LogError("Tried to add duplicate SGID:" + gamepad.SGID);
                }
            }
            else
            {
                Debug.LogError("Null gamepad passed to AddExistingGamepad()");
            }
        }
예제 #3
0
 public SGUpdateMsg(SocketGamepad gamepad) : base()
 {
     Setup();
     SGID        = gamepad.SGID;
     MessageType = "input";
     Data        = gamepad.InputData;
     Serialize();
 }
예제 #4
0
        protected void HandleGamepadTimingOut(SocketIOEvent e)
        {
            SGUpdateMsg gamepadTimingOut = new SGUpdateMsg(e.data);

            Debug.Log("Gamepad " + gamepadTimingOut.SGID + " Timing out");
            SocketGamepad gamepad = GetGamepad(gamepadTimingOut.SGID);

            OnGamepadTimingOut(gamepad);
        }
예제 #5
0
        protected void HandleGamepadReconnect(SocketIOEvent e)
        {
            SGHandshakeMsg gamepadHandshake = new SGHandshakeMsg(e.data);

            Debug.Log("Gamepad " + gamepadHandshake.SGID + " Reconnected " + gamepadHandshake.Controller);
            SocketGamepad gamepad = CreateOrReconnectGamepad(gamepadHandshake.SGID);

            gamepad.Controller = gamepadHandshake.Controller;
            //OnGamepadReconnect(gamepad) handled in CreateOrReconnectGamepad
        }
예제 #6
0
        protected void HandleGamepadDisconnected(SocketIOEvent e)
        {
            Debug.Log("Gamepad Disconnect Received: " + e.data + "");
            SGDisconnectMsg DisconnectMsg = new SGDisconnectMsg(e.data);

            Debug.Log("Controller " + DisconnectMsg.SGID + " Disconnected.");

            SocketGamepad gamepad = Gamepads.Find(g => g.SGID == DisconnectMsg.SGID);

            if (gamepad != null)
            {
                Debug.Log("Removing Gamepad " + DisconnectMsg.SGID.ToString());
                RemoveGamepad(gamepad);
            }
        }
예제 #7
0
        /// <summary>
        /// Handles a new Gamepad being "plugged in" to the Socket Gamepad Manager
        /// </summary>
        /// <param name="e"></param>
        protected void HandleGamepadHandshake(SocketIOEvent e)
        {
            //Upon Handshake, create the Gamepad
            SGHandshakeMsg gamepadHandshake = new SGHandshakeMsg(e.data);
            SocketGamepad  gamepad          = CreateOrReconnectGamepad(gamepadHandshake.SGID);

            gamepad.Controller = gamepadHandshake.Controller;

            if (gamepad != null)
            {
                Debug.Log("Gamepad Handshake: " + e.data);
            }
            else
            {
                Debug.LogError("Gamepad Handshake failed: " + e.data);
            }
        }
예제 #8
0
 /// <summary>
 /// Removes a SocketGamepad, used as an "unplug"
 /// </summary>
 /// <param name="gamepad"></param>
 public void RemoveGamepad(SocketGamepad gamepad)
 {
     if (gamepad != null)
     {
         OnGamepadUnplugged(gamepad);
         if (ActiveGamepads.ContainsKey(gamepad))
         {
             ActiveGamepads.Remove(gamepad);
         }
         Gamepads.Remove(gamepad);
         DestroyImmediate(gamepad);
     }
     else
     {
         Debug.LogError("Null gamepad passed to RemoveGamepad()");
     }
 }
예제 #9
0
        /// <summary>
        /// Creates a virtual object to represent a connected SocketGamepad
        /// </summary>
        /// <param name="SGID">SocketGamepad Identifier as it relates to the SocketGamepadManager</param>
        /// <returns></returns>
        public SocketGamepad CreateOrReconnectGamepad(int SGID)
        {
            SocketGamepad gamepad = null;

            if (Gamepads.Count > 0)
            {
                for (int g = 0; g < Gamepads.Count; g++)
                {
                    //TODO: Handle Same Gamepad different device id?
                    if (Gamepads[g].SGID == SGID)
                    {
                        gamepad = Gamepads[g];
                    }
                }
            }

            if (gamepad == null)
            {
                gamepad         = gameObject.AddComponent <SocketGamepad>();
                gamepad.SGID    = SGID;
                gamepad.LocalId = Gamepads.Count;

                Gamepads.Add(gamepad);

                if (gamepad.Controller != DefaultController)
                {
                    JSONObject msg = JSONObject.CreateStringObject(DefaultController);
                    socket.Emit("SGRedirectMsg", msg);
                }

                OnGamepadPluggedIn(gamepad);
            }
            else
            {
                OnGamepadReconnect(gamepad);
            }

            return(gamepad);
        }
예제 #10
0
        //Change Input array to Dictionary of named delegates instead of an array of 20 floats
        protected void HandleGamepadUpdate(SocketIOEvent e)
        {
            SGUpdateMsg UpdateMsg = new SGUpdateMsg(e.data);

            //Debug.Log("Gamepad Update Received for " + UpdateMsg.SGID.ToString());
            if (UpdateMsg.SGID > -1)
            {
                SocketGamepad gamepad = GetGamepad(UpdateMsg.SGID);
                if (gamepad == null)
                {
                    Debug.Log("Controller " + UpdateMsg.SGID + " sending Updates without handshake!");
                }
                else
                {
                    gamepad.InputData = UpdateMsg.Data;
                    OnUpdateGamepad(gamepad);
                }
            }
            else
            {
                //Hack Attempt?
                Debug.LogError("STOP IT, I'M NOT A DOCTOR!!");
            }
        }
예제 #11
0
 /// <summary>
 /// Called after a gamepad is removed from the system
 /// </summary>
 /// <param name="gamepad">Virtual SocketGamepad object which was unplugged</param>
 protected abstract void OnGamepadUnplugged(SocketGamepad gamepad);
예제 #12
0
 /// <summary>
 /// Triggered when a SocketGamepad Reconnects
 /// </summary>
 /// <param name="gamepad"></param>
 protected abstract void OnGamepadReconnect(SocketGamepad gamepad);
예제 #13
0
 /// <summary>
 /// Triggered when a SocketGamepad begins Timing out on the Fyo server
 /// </summary>
 /// <param name="gamepad"></param>
 protected abstract void OnGamepadTimingOut(SocketGamepad gamepad);
예제 #14
0
 /// <summary>
 /// Processes a SocketGamepad Update from the Socket Gamepad Manager
 /// </summary>
 protected abstract void OnUpdateGamepad(SocketGamepad gamepad);
예제 #15
0
 /// <summary>
 /// Called after a gamepad is registered with the system, passed the a virtual representation of a browser based controller functions.
 /// This is when the developer could use the ActiveGamepads Dictionary to associate active player objects with plugged-in gamepads
 /// </summary>
 /// <param name="gamepad">Virtual SocketGamepad that was plugged in</param>
 protected abstract void OnGamepadPluggedIn(SocketGamepad gamepad);
예제 #16
0
 public bool HasGamepad(SocketGamepad gamepad)
 {
     return(Gamepads.Contains(gamepad));
 }