示例#1
0
 public void Update()
 {
     if (m_connected)
     {
         bool focus = m_window.Focus;
         foreach (var entry in m_buttons)
         {
             var name   = entry.Key;
             var button = entry.Value;
             var data   = SteamController.GetDigitalActionData(m_handle, m_owner.GetDigitalActionHandle(name));
             ((SimpleButton)button).Update(focus && (data.bActive != 0) && (data.bState != 0));
         }
         foreach (var entry in m_axes)
         {
             var name = entry.Key;
             var axis = entry.Value;
             var data = SteamController.GetAnalogActionData(m_handle, m_owner.GetAnalogActionHandle(name));
             ((SimpleAxis)axis).Value = (focus && data.bActive != 0) ? data.x : 0.0f;
         }
         foreach (var entry in m_joysticks)
         {
             var name     = entry.Key;
             var joystick = entry.Value;
             var data     = SteamController.GetAnalogActionData(m_handle, m_owner.GetAnalogActionHandle(name));
             ((SimpleJoystick)joystick).X = (focus && data.bActive != 0) ? data.x : 0.0f;
             ((SimpleJoystick)joystick).Y = (focus && data.bActive != 0) ? data.y : 0.0f;
         }
     }
 }
 public void Update()
 {
     SteamController.RunFrame();
     DetectControllers();
     for (int i = 0; i < m_controllers.Count; ++i)
     {
         m_controllers[i].Update();
     }
 }
示例#3
0
        public string GetJoystickPromptPath(string id, string actionSetID)
        {
            var origins    = new EControllerActionOrigin[global::Steamworks.Constants.STEAM_CONTROLLER_MAX_ORIGINS];
            int numOrigins = SteamController.GetAnalogActionOrigins(
                m_handle,
                m_owner.GetActionSetHandle((actionSetID != null) ? actionSetID : m_currentActionSet),
                m_owner.GetAnalogActionHandle(id),
                origins
                );

            if (numOrigins > 0)
            {
                return(GetPromptPath(GetBestOrigin(origins, numOrigins)));
            }
            return(null);
        }
        private void DetectControllers()
        {
            // Find all connected controllers
            m_numControllerHandles = SteamController.GetConnectedControllers(m_controllerHandles);

            // Disconnect all old controllers
            for (int j = m_controllers.Count - 1; j >= 0; --j)
            {
                var controller = m_controllers[j];
                int match      = -1;
                for (int i = 0; i < m_numControllerHandles; ++i)
                {
                    var handle = m_controllerHandles[i];
                    if (controller.Handle == handle)
                    {
                        match = i;
                        break;
                    }
                }
                if (match < 0)
                {
                    controller.Disconnect();
                    m_controllers.RemoveAt(j);
                }
            }

            // Add all new controllers
            for (int i = 0; i < m_numControllerHandles; ++i)
            {
                var handle = m_controllerHandles[i];
                SteamworksSteamController match = null;
                foreach (var controller in m_controllers)
                {
                    if (controller.Handle == handle)
                    {
                        match = controller;
                        break;
                    }
                }
                if (match == null)
                {
                    m_controllers.Add(new SteamworksSteamController(this, m_window, handle));
                }
            }
        }
示例#5
0
        public SteamworksSteamController(SteamworksSteamControllerCollection owner, IWindow window, ControllerHandle_t handle)
        {
            m_owner  = owner;
            m_window = window;
            m_handle = handle;

            // Buttons
            m_buttons         = new Dictionary <string, IButton>();
            m_buttonsReadOnly = m_buttons.ToReadOnly();
            foreach (string name in m_owner.DigitalActionNames)
            {
                m_buttons.Add(name, new SimpleButton());
            }

            // Axes
            m_axes         = new Dictionary <string, IAxis>();
            m_axesReadOnly = m_axes.ToReadOnly();
            foreach (string name in m_owner.AnalogTriggerActionNames)
            {
                m_axes.Add(name, new SimpleAxis());
            }

            // Joysticks
            m_joysticks         = new Dictionary <string, IJoystick>();
            m_joysticksReadOnly = m_joysticks.ToReadOnly();
            foreach (string name in m_owner.AnalogActionNames)
            {
                m_joysticks.Add(name, new SimpleJoystick());
            }

            // State
            m_connected = true;
            App.Log("Steam controller connected");

            // Set initial action set
            m_currentActionSet = m_owner.ActionSetNames.First();
            SteamController.ActivateActionSet(m_handle, m_owner.GetActionSetHandle(m_currentActionSet));

            // Get initial state
            Update();
        }
        public SteamworksSteamControllerCollection(SDL2Window window, string[] actionSetNames, string[] digitalActionNames, string[] analogActionNames, string[] analogTriggerActionNames)
        {
            m_window = window;

            m_controllerHandles    = new ControllerHandle_t[Constants.STEAM_CONTROLLER_MAX_COUNT];
            m_numControllerHandles = 0;

            m_controllers = new List <SteamworksSteamController>();
            App.CheckSteamworksResult("SteamController::Init", SteamController.Init());

            m_actionSetHandles = new Dictionary <string, ControllerActionSetHandle_t>();
            for (int i = 0; i < actionSetNames.Length; ++i)
            {
                var name = actionSetNames[i];
                m_actionSetHandles.Add(name, SteamController.GetActionSetHandle(name));
            }

            m_digitalActionHandles = new Dictionary <string, ControllerDigitalActionHandle_t>();
            for (int i = 0; i < digitalActionNames.Length; ++i)
            {
                var name = digitalActionNames[i];
                m_digitalActionHandles.Add(name, SteamController.GetDigitalActionHandle(name));
            }

            m_analogActionHandles = new Dictionary <string, ControllerAnalogActionHandle_t>();
            m_analogActionNames   = analogActionNames;
            for (int i = 0; i < m_analogActionNames.Length; ++i)
            {
                var name = m_analogActionNames[i];
                m_analogActionHandles.Add(name, SteamController.GetAnalogActionHandle(name));
            }
            m_analogTriggerActionNames = analogTriggerActionNames;
            for (int i = 0; i < m_analogTriggerActionNames.Length; ++i)
            {
                var name = m_analogTriggerActionNames[i];
                m_analogActionHandles.Add(name, SteamController.GetAnalogActionHandle(name));
            }

            DetectControllers();
        }
示例#7
0
 public void Rumble(float duration)
 {
     if (m_connected)
     {
         var intervalMicros = 35000;
         var durationMicros = (int)(duration * 1000000f);
         SteamController.TriggerRepeatedHapticPulse(
             m_handle,
             ESteamControllerPad.k_ESteamControllerPad_Left,
             (ushort)(intervalMicros / 2),
             (ushort)(intervalMicros / 2),
             (ushort)(durationMicros / intervalMicros),
             0
             );
         SteamController.TriggerRepeatedHapticPulse(
             m_handle,
             ESteamControllerPad.k_ESteamControllerPad_Right,
             (ushort)(intervalMicros / 2),
             (ushort)(intervalMicros / 2),
             (ushort)(durationMicros / intervalMicros),
             0
             );
     }
 }
 public void Dispose()
 {
     App.CheckSteamworksResult("SteamController::Shutdown", SteamController.Shutdown());
 }