/// <summary> /// Remove an active user. /// </summary> /// <param name="user">An active user.</param> /// <exception cref="ArgumentNullException"><paramref name="user"/> is <c>null</c>.</exception> /// <remarks> /// Removing a user also unassigns all currently assigned devices from the user. On completion of this /// method, <see cref="devices"/> of <paramref name="user"/> will be empty. /// </remarks> public static void Remove(IInputUser user) { if (user == null) { throw new ArgumentNullException("user"); } var index = FindUserIndex(user); if (index == -1) { return; } // Remove devices. var userData = s_AllUserData[index]; if (userData.deviceCount > 0) { ArrayHelpers.EraseSliceWithCapacity(ref s_AllDevices, ref s_AllDeviceCount, userData.deviceStartIndex, userData.deviceCount); } // Remove. var userCount = s_AllUserCount; ArrayHelpers.EraseAtWithCapacity(ref s_AllUsers, ref userCount, index); ArrayHelpers.EraseAtWithCapacity(ref s_AllUserData, ref s_AllUserCount, index); // Send notification. Notify(user, InputUserChange.Removed); }
private static void ClearAssignedInputDevicesInternal(int index) { var deviceCount = s_AllUserData[index].deviceCount; if (deviceCount == 0) { return; } var deviceStartIndex = s_AllUserData[index].deviceStartIndex; ArrayHelpers.EraseSliceWithCapacity(ref s_AllDevices, ref s_AllDeviceCount, deviceCount, deviceStartIndex); s_AllUserData[index].deviceCount = 0; s_AllUserData[index].deviceStartIndex = -1; // Adjust indices of other users. for (var i = 0; i < s_AllUserCount; ++i) { if (s_AllUserData[i].deviceStartIndex <= deviceStartIndex) { continue; } s_AllUserData[i].deviceStartIndex -= deviceCount; } }