Esempio n. 1
0
        internal static void Update()
        {
            var currentTime       = System.DateTime.Now;
            var timeSinceLastScan = currentTime - lastScanAttempt;

            // Scan for wands if necessary.
            // TODO: Implement more robust disconnect detection, communicate wand availability events to users, offer user option to swap wands.
            if (timeSinceLastScan.TotalSeconds >= wandScanRate &&
                (!GetWandAvailability(WandTarget.Primary) || !GetWandAvailability(WandTarget.Secondary)))
            {
                ScanForWands();
                lastScanAttempt = currentTime;
            }

            // Query the native plugin for wand states since the previous frame.
            var primaryWandControlsState   = new WandControlsState();
            var secondaryWandControlsState = new WandControlsState();

            var previousPrimaryWandState   = currentWandStates[WandTarget.Primary];
            var previousSecondaryWandState = currentWandStates[WandTarget.Secondary];

            // Get the state of the wand held in the user's dominant hand.
            if (GetWandControlsState(ref primaryWandControlsState, WandTarget.Primary))
            {
                currentWandStates[WandTarget.Primary] = primaryWandControlsState;
            }
            else
            {
                Log.Verbose("Failed to obtain state for the primary wand.");
            }

            // Get the state of the wand held in the user's non-dominant hand.
            if (GetWandControlsState(ref secondaryWandControlsState, WandTarget.Secondary))
            {
                currentWandStates[WandTarget.Secondary] = secondaryWandControlsState;
            }
            else
            {
                Log.Verbose("Failed to obtain state for the secondary wand.");
            }

            previousWandStates[WandTarget.Primary]   = previousPrimaryWandState;
            previousWandStates[WandTarget.Secondary] = previousSecondaryWandState;
        }
Esempio n. 2
0
        internal static bool GetWandControlsState(ref WandControlsState wandButtonsState, Input.WandTarget targetWand = Input.WandTarget.Primary)
        {
            int result = 1;

            try
            {
                UInt32  buttons   = 0;
                float[] stick     = new float[2];
                float   trigger   = 0f;
                Int64   timestamp = 0;

                result = NativePlugin.GetControllerState(targetWand, ref buttons, stick, ref trigger, ref timestamp);

                wandButtonsState = new WandControlsState(timestamp, buttons, new Vector2(stick[0], stick[1]), trigger);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
            }


            return(0 == result);
        }