public void OnPreprocessBuild(BuildReport report)
        {
            if (InputSystem.settings == null)
            {
                return;
            }

            var wasDirty = IsPlayerSettingsDirty();

            m_SettingsAddedToPreloadedAssets = null;

            // Add InputSettings object assets, if it's not in there already.
            var preloadedAssets = PlayerSettings.GetPreloadedAssets();

            if (!preloadedAssets.Contains(InputSystem.settings))
            {
                m_SettingsAddedToPreloadedAssets = InputSystem.settings;
                ArrayHelpers.Append(ref preloadedAssets, m_SettingsAddedToPreloadedAssets);
                PlayerSettings.SetPreloadedAssets(preloadedAssets);
            }

            if (!wasDirty)
            {
                ClearPlayerSettingsDirtyFlag();
            }
        }
        /// <summary>
        /// Add an action map to the asset.
        /// </summary>
        /// <param name="asset">Asset to add the map to.</param>
        /// <param name="map">A named action map.</param>
        /// <exception cref="ArgumentNullException"><paramref name="map"/> or <paramref name="asset"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException"><paramref name="map"/> has no name or asset already contains a
        /// map with the same name.</exception>
        /// <seealso cref="InputActionAsset.actionMaps"/>
        public static void AddActionMap(this InputActionAsset asset, InputActionMap map)
        {
            if (asset == null)
            {
                throw new ArgumentNullException(nameof(asset));
            }
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (string.IsNullOrEmpty(map.name))
            {
                throw new InvalidOperationException("Maps added to an input action asset must be named");
            }
            if (map.asset != null)
            {
                throw new InvalidOperationException(
                          $"Cannot add map '{map}' to asset '{asset}' as it has already been added to asset '{map.asset}'");
            }
            ////REVIEW: some of the rules here seem stupid; just replace?
            if (asset.FindActionMap(map.name) != null)
            {
                throw new InvalidOperationException(
                          $"An action map called '{map.name}' already exists in the asset");
            }

            ArrayHelpers.Append(ref asset.m_ActionMaps, map);
            map.m_Asset = asset;
        }
        public IDisposable Subscribe(IObserver <InputRemoting.Message> observer)
        {
            if (observer == null)
            {
                throw new System.ArgumentNullException(nameof(observer));
            }

            var subscriber = new Subscriber {
                owner = this, observer = observer
            };

            ArrayHelpers.Append(ref m_Subscribers, subscriber);

            if (m_ConnectedIds != null)
            {
                foreach (var id in m_ConnectedIds)
                {
                    observer.OnNext(new InputRemoting.Message {
                        type = InputRemoting.MessageType.Connect, participantId = id
                    });
                }
            }

            return(subscriber);
        }
Пример #4
0
        /// <summary>
        /// Add an action map to the asset.
        /// </summary>
        /// <param name="map">A named action map.</param>
        /// <exception cref="ArgumentNullException"><paramref name="map"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException"><paramref name="map"/> has no name or asset already contains a
        /// map with the same name.</exception>
        public void AddActionMap(InputActionMap map)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            if (string.IsNullOrEmpty(map.name))
            {
                throw new InvalidOperationException("Maps added to an input action asset must be named");
            }
            if (map.asset != null)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Cannot add map '{0}' to asset '{1}' as it has already been added to asset '{2}'", map, this,
                                                        map.asset));
            }
            ////REVIEW: some of the rules here seem stupid; just replace?
            if (TryGetActionMap(map.name) != null)
            {
                throw new InvalidOperationException(
                          string.Format("An action map called '{0}' already exists in the asset", map.name));
            }

            ArrayHelpers.Append(ref m_ActionMaps, map);
            map.m_Asset = this;
        }
        private static int AddBindingInternal(InputActionMap map, InputBinding binding)
        {
            Debug.Assert(map != null);

            // Make sure the binding has an ID.
            if (string.IsNullOrEmpty(binding.m_Id))
            {
                binding.GenerateId();
            }

            // Append to bindings in set.
            var bindingIndex = ArrayHelpers.Append(ref map.m_Bindings, binding);

            // Invalidate per-action binding sets so that this gets refreshed if
            // anyone queries it.
            map.ClearPerActionCachedBindingData();

            // If we're looking at a singleton action, make sure m_Bindings is up to date just
            // in case the action gets serialized.
            if (map.m_SingletonAction != null)
            {
                map.m_SingletonAction.m_SingletonActionBindings = map.m_Bindings;
            }

            return(bindingIndex);
        }
            private void AddDeviceEntry(string controlPath, InputControlScheme.DeviceRequirement.Flags flags)
            {
                if (string.IsNullOrEmpty(controlPath))
                {
                    throw new ArgumentNullException(nameof(controlPath));
                }

                var scheme = m_Asset != null ? m_Asset.m_ControlSchemes[m_ControlSchemeIndex] : m_ControlScheme;

                ArrayHelpers.Append(ref scheme.m_DeviceRequirements,
                                    new InputControlScheme.DeviceRequirement
                {
                    m_ControlPath = controlPath,
                    m_Flags       = flags,
                });

                if (m_Asset == null)
                {
                    m_ControlScheme = scheme;
                }
                else
                {
                    m_Asset.m_ControlSchemes[m_ControlSchemeIndex] = scheme;
                }
            }
Пример #7
0
 private void AddModifier(object modifierNameString)
 {
     ArrayHelpers.Append(ref m_Modifiers,
                         new InputTemplate.NameAndParameters {
         name = (string)modifierNameString
     });
     ApplyModifiers();
 }
Пример #8
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var json        = Encoding.UTF8.GetString(msg.data);
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);

                receiver.m_LocalManager.RegisterControlLayout(json);
                ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].layouts, json);
            }
Пример #9
0
 private void AddInteraction(object interactionNameString)
 {
     ArrayHelpers.Append(ref m_Interactions,
                         new InputControlLayout.NameAndParameters {
         name = (string)interactionNameString
     });
     m_InteractionListView.list = m_Interactions;
     ApplyInteractions();
 }
Пример #10
0
        ////REVIEW: given that the PlayerConnection will connect to the editor regardless, we end up
        ////        on this path whether input remoting is enabled or not
        private void OnConnected(int id)
        {
            if (m_ConnectedIds != null && ArrayHelpers.Contains(m_ConnectedIds, id))
                return;

            ArrayHelpers.Append(ref m_ConnectedIds, id);

            SendToSubscribers(InputRemoting.MessageType.Connect, new MessageEventArgs {playerId = id});
        }
        private void OnAddElement(object data)
        {
            var name = (string)data;

            m_ListItems.Add(ObjectNames.NicifyVariableName(name));
            ArrayHelpers.Append(ref m_ParametersForEachListItem,
                new InputControlLayout.NameAndParameters {name = name});
            m_Apply();
        }
Пример #12
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var json        = Encoding.UTF8.GetString(msg.data);
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);
                var @namespace  = receiver.m_Senders[senderIndex].templateNamespace;

                receiver.m_LocalManager.RegisterTemplate(json, @namespace: @namespace);
                ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].templates, json);
            }
Пример #13
0
        public void AddController(ulong handle)
        {
            ArrayHelpers.Append(ref controllers, handle);
            var index = ArrayHelpers.Append(ref controllerData, new ControllerData());

            controllerData[index].analogData           = new Dictionary <SteamHandle <InputAction>, SteamAnalogActionData>();
            controllerData[index].digitalData          = new Dictionary <SteamHandle <InputAction>, SteamDigitalActionData>();
            controllerData[index].actionSetActivations = new List <SteamHandle <InputActionMap> >();
        }
        public static InputAction AddAction(this InputActionMap map, string name, string binding = null,
                                            string interactions = null, string processors = null, string groups = null, string expectedControlLayout = null)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Action must have name", nameof(name));
            }
            if (map.enabled)
            {
                throw new InvalidOperationException(
                          $"Cannot add action '{name}' to map '{map}' while it the map is enabled");
            }
            if (map.TryGetAction(name) != null)
            {
                throw new InvalidOperationException(
                          $"Cannot add action with duplicate name '{name}' to set '{map.name}'");
            }

            // Append action to array.
            var action = new InputAction(name)
            {
                expectedControlLayout = expectedControlLayout
            };

            action.GenerateId();
            ArrayHelpers.Append(ref map.m_Actions, action);
            action.m_ActionMap = map;

            ////TODO: make sure we blast out existing action map state

            // Add binding, if supplied.
            if (!string.IsNullOrEmpty(binding))
            {
                action.AddBinding(binding, interactions: interactions, processors: processors, groups: groups);
            }
            else
            {
                if (!string.IsNullOrEmpty(groups))
                {
                    throw new ArgumentException(
                              $"No binding path was specified for action '{action}' but groups was specified ('{groups}'); cannot apply groups without binding",
                              nameof(groups));
                }

                // If no binding has been supplied but there are interactions and processors, they go on the action itself.
                action.m_Interactions = interactions;
                action.m_Processors   = processors;
            }

            return(action);
        }
Пример #15
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);
                var data        = DeserializeData <Data>(msg.data);

                // Make sure we haven't already seen the device.
                var devices = receiver.m_Senders[senderIndex].devices;

                if (devices != null)
                {
                    foreach (var entry in devices)
                    {
                        if (entry.remoteId == data.deviceId)
                        {
                            Debug.LogError(string.Format(
                                               "Already received device with id {0} (layout '{1}', description '{3}) from remote {2}",
                                               data.deviceId,
                                               data.layout, msg.participantId, data.description));
                            return;
                        }
                    }
                }

                // Create device.
                var layout = string.Format("{0}::{1}", receiver.m_Senders[senderIndex].layoutNamespace,
                                           data.layout);
                InputDevice device;

                try
                {
                    device = receiver.m_LocalManager.AddDevice(layout,
                                                               string.Format("Remote{0}::{1}", msg.participantId, data.name));
                }
                catch (Exception exception)
                {
                    Debug.Log(
                        string.Format(
                            "Could not create remote device '{0}' with layout '{1}' locally (exception: {2})",
                            data.description, data.layout, exception));
                    return;
                }
                device.m_Description = data.description;
                device.m_Flags      |= InputDevice.Flags.Remote;

                // Remember it.
                var record = new RemoteInputDevice
                {
                    remoteId    = data.deviceId,
                    localId     = device.id,
                    description = data.description,
                    layoutName  = layout
                };

                ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].devices, record);
            }
Пример #16
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);
                var data        = DeserializeData <Data>(msg.data);

                // Make sure we haven't already seen the device.
                var devices = receiver.m_Senders[senderIndex].devices;

                if (devices != null)
                {
                    foreach (var entry in devices)
                    {
                        if (entry.remoteId == data.deviceId)
                        {
                            Debug.LogError(string.Format(
                                               "Already received device with id {0} (layout '{1}', description '{3}) from remote {2}",
                                               data.deviceId,
                                               data.layout, msg.participantId, data.description));
                            return;
                        }
                    }
                }

                // Create device.
                InputDevice device;

                try
                {
                    ////REVIEW: this gives remote devices names the same way that local devices receive them; should we make remote status visible in the name?
                    device = receiver.m_LocalManager.AddDevice(data.layout);
                    device.m_ParticipantId = msg.participantId;
                }
                catch (Exception exception)
                {
                    Debug.LogError(
                        $"Could not create remote device '{data.description}' with layout '{data.layout}' locally (exception: {exception})");
                    return;
                }
                device.m_Description  = data.description;
                device.m_DeviceFlags |= InputDevice.DeviceFlags.Remote;

                // Remember it.
                var record = new RemoteInputDevice
                {
                    remoteId    = data.deviceId,
                    localId     = device.id,
                    description = data.description,
                    layoutName  = data.layout
                };

                ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].devices, record);
            }
Пример #17
0
        public IDisposable Subscribe(IObserver<InputRemoting.Message> observer)
        {
            var subscriber = new Subscriber {owner = this, observer = observer};
            ArrayHelpers.Append(ref m_Subscribers, subscriber);

            if (m_ConnectedIds != null)
            {
                foreach (var id in m_ConnectedIds)
                    observer.OnNext(new InputRemoting.Message { type = InputRemoting.MessageType.Connect, participantId = id });
            }

            return subscriber;
        }
Пример #18
0
        private void AddAndSelectControlScheme(InputControlScheme scheme)
        {
            Debug.Assert(!string.IsNullOrEmpty(scheme.name), "Control scheme has no name");
            Debug.Assert(
                ArrayHelpers.IndexOf(m_ControlSchemes,
                                     x => x.name.Equals(scheme.name, StringComparison.InvariantCultureIgnoreCase)) == -1,
                "Duplicate control scheme name");

            var index = ArrayHelpers.Append(ref m_ControlSchemes, scheme);

            onControlSchemesChanged?.Invoke();

            SelectControlScheme(index);
        }
Пример #19
0
        public void AddControlScheme(InputControlScheme controlScheme)
        {
            if (string.IsNullOrEmpty(controlScheme.name))
            {
                throw new ArgumentException("Cannot add control scheme without name to asset " + name);
            }
            if (TryGetControlScheme(controlScheme.name) != null)
            {
                throw new InvalidOperationException(string.Format("Asset '{0}' already contains a control scheme called '{1}'",
                                                                  name, controlScheme.name));
            }

            ArrayHelpers.Append(ref m_ControlSchemes, controlScheme);
        }
Пример #20
0
        public IDisposable Subscribe(IObserver <Message> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }

            var subscriber = new Subscriber {
                owner = this, observer = observer
            };

            ArrayHelpers.Append(ref m_Subscribers, subscriber);

            return(subscriber);
        }
Пример #21
0
        private void OnAddElement(object data)
        {
            var name = (string)data;

            if (m_ListItems.Count == 1 && m_ListItems[0] == "")
            {
                m_ListItems.Clear();
            }

            m_ListItems.Add(name);
            ArrayHelpers.Append(ref m_ParametersForEachListItem,
                                new InputControlLayout.NameAndParameters {
                name = name
            });
            m_Apply();
        }
Пример #22
0
            private void AddDeviceEntry(string devicePath, bool isOptional)
            {
                if (string.IsNullOrEmpty(devicePath))
                {
                    throw new ArgumentNullException("devicePath");
                }

                var scheme = m_Asset.m_ControlSchemes[m_ControlSchemeIndex];

                ArrayHelpers.Append(ref scheme.m_Devices,
                                    new InputControlScheme.DeviceEntry
                {
                    devicePath = devicePath,
                    isOptional = isOptional,
                });
                m_Asset.m_ControlSchemes[m_ControlSchemeIndex] = scheme;
            }
Пример #23
0
        private void AddAndSelectControlScheme(InputControlScheme scheme)
        {
            // Ensure scheme has a name.
            if (string.IsNullOrEmpty(scheme.name))
            {
                scheme.m_Name = "New control scheme";
            }

            // Make sure name is unique.
            scheme.m_Name = MakeUniqueControlSchemeName(scheme.name);

            var index = ArrayHelpers.Append(ref m_ControlSchemes, scheme);

            onControlSchemesChanged?.Invoke();

            SelectControlScheme(index);
        }
Пример #24
0
        public InputDeviceMatcher With(InternedString key, object value)
        {
            // If it's a string, check whether it's a regex.
            if (value is string str)
            {
                var mayBeRegex = !str.All(ch => char.IsLetterOrDigit(ch) || char.IsWhiteSpace(ch));
                if (mayBeRegex)
                {
                    value = new Regex(str, RegexOptions.IgnoreCase);
                }
            }

            // Add to list.
            var result = this;

            ArrayHelpers.Append(ref result.m_Patterns, new KeyValuePair <InternedString, object>(key, value));
            return(result);
        }
        /// <summary>
        /// Add a new control scheme to the asset.
        /// </summary>
        /// <param name="asset">Asset to add the control scheme to.</param>
        /// <param name="controlScheme">Control scheme to add.</param>
        /// <exception cref="ArgumentException"><paramref name="controlScheme"/> has no name.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="asset"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">A control scheme with the same name as <paramref name="controlScheme"/>
        /// already exists in the asset.</exception>
        /// <remarks>
        /// </remarks>
        public static void AddControlScheme(this InputActionAsset asset, InputControlScheme controlScheme)
        {
            if (asset == null)
            {
                throw new ArgumentNullException(nameof(asset));
            }
            if (string.IsNullOrEmpty(controlScheme.name))
            {
                throw new ArgumentException("Cannot add control scheme without name to asset " + asset.name, nameof(controlScheme));
            }
            if (asset.FindControlScheme(controlScheme.name) != null)
            {
                throw new InvalidOperationException(
                          $"Asset '{asset.name}' already contains a control scheme called '{controlScheme.name}'");
            }

            ArrayHelpers.Append(ref asset.m_ControlSchemes, controlScheme);
        }
Пример #26
0
        private InputDeviceMatcher With(InternedString key, object value, bool supportRegex = true)
        {
            // If it's a string, check whether it's a regex.
            if (supportRegex && value is string str)
            {
                var mayBeRegex = !str.All(ch => char.IsLetterOrDigit(ch) || char.IsWhiteSpace(ch)) &&
                                 !double.TryParse(str, out var _); // Avoid '.' in floats forcing the value to be a regex.
                if (mayBeRegex)
                {
                    value = new Regex(str, RegexOptions.IgnoreCase);
                }
            }

            // Add to list.
            var result = this;

            ArrayHelpers.Append(ref result.m_Patterns, new KeyValuePair <InternedString, object>(key, value));
            return(result);
        }
Пример #27
0
        public void AddActionSet(InputActionSet set)
        {
            if (set == null)
            {
                throw new ArgumentNullException("set");
            }
            if (string.IsNullOrEmpty(set.name))
            {
                throw new InvalidOperationException("Sets added to an input action asset must be named");
            }
            ////REVIEW: some of the rules here seem stupid; just replace?
            if (TryGetActionSet(set.name) != null)
            {
                throw new InvalidOperationException(
                          string.Format("An action set called '{0}' already exists in the asset", set.name));
            }

            ArrayHelpers.Append(ref m_ActionSets, set);
        }
Пример #28
0
        private void OnAddElement(object data)
        {
            var name = (string)data;

            ArrayHelpers.Append(ref m_ParametersForEachListItem,
                                new NameAndParameters {
                name = name
            });
            ArrayHelpers.Append(ref m_EditableParametersForEachListItem,
                                new ParameterListView {
                onChange = OnParametersChanged
            });

            var index    = m_EditableParametersForEachListItem.Length - 1;
            var typeName = m_ParametersForEachListItem[index].name;
            var rowType  = m_ListOptions.LookupTypeRegistration(typeName);

            m_EditableParametersForEachListItem[index].Initialize(rowType, m_ParametersForEachListItem[index].parameters);
            m_EditableParametersForEachListItem[index].name = ObjectNames.NicifyVariableName(name);

            m_Apply();
        }
Пример #29
0
        public static InputAction AddAction(this InputActionMap map, string name, string binding = null,
                                            string interactions = null, string groups = null, string expectedControlLayout = null)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Action must have name", "name");
            }
            if (map.enabled)
            {
                throw new InvalidOperationException(
                          string.Format("Cannot add action '{0}' to map '{1}' while it the map is enabled", name, map));
            }
            if (map.TryGetAction(name) != null)
            {
                throw new InvalidOperationException(
                          string.Format("Cannot add action with duplicate name '{0}' to set '{1}'", name, map.name));
            }

            // Append action to array.
            var action = new InputAction(name);

            action.expectedControlLayout = expectedControlLayout;
            ArrayHelpers.Append(ref map.m_Actions, action);
            action.m_ActionMap = map;

            ////TODO: make sure we blast out existing action map state

            // Add binding, if supplied.
            if (!string.IsNullOrEmpty(binding))
            {
                action.AddBinding(binding, interactions: interactions, groups: groups);
            }

            return(action);
        }
Пример #30
0
        ////TODO: with C#7 this should be a ref return
        private int FindOrCreateSenderRecord(int senderId)
        {
            // Try to find existing.
            if (m_Senders != null)
            {
                var senderCount = m_Senders.Length;
                for (var i = 0; i < senderCount; ++i)
                {
                    if (m_Senders[i].senderId == senderId)
                    {
                        return(i);
                    }
                }
            }

            // Create new.
            var sender = new RemoteSender
            {
                senderId = senderId,
            };

            return(ArrayHelpers.Append(ref m_Senders, sender));
        }