public void Setup(InternedString layout, InternedString variants,
                          InputDeviceDescription deviceDescription = default)
        {
            m_LayoutCacheRef = InputControlLayout.CacheRef();

            InstantiateLayout(layout, variants, new InternedString(), null);
            FinalizeControlHierarchy();

            m_Device.m_Description = deviceDescription;
            m_Device.CallFinishSetupRecursive();
        }
Пример #2
0
        // If our layout data is outdated, rescan all the layouts in the system.
        private static void Refresh()
        {
            var manager = InputSystem.s_Manager;

            if (manager.m_LayoutRegistrationVersion == s_LayoutRegistrationVersion)
            {
                return;
            }

            Clear();

            if (!s_LayoutCacheRef.valid)
            {
                // In the editor, we keep a permanent reference on the global layout
                // cache. Means that in the editor, we always have all layouts loaded in full
                // at all times whereas in the player, we load layouts only while we need
                // them and then release them again.
                s_LayoutCacheRef = InputControlLayout.CacheRef();
            }

            var layoutNames = manager.ListControlLayouts().ToArray();

            // Remember which layout maps to which device matchers.
            var layoutMatchers = InputControlLayout.s_Layouts.layoutMatchers;

            foreach (var entry in layoutMatchers)
            {
                s_DeviceMatchers.TryGetValue(entry.layoutName, out var matchers);

                matchers.Append(entry.deviceMatcher);
                s_DeviceMatchers[entry.layoutName] = matchers;
            }

            // Load and store all layouts.
            foreach (var layoutName in layoutNames)
            {
                var layout = InputControlLayout.cache.FindOrLoadLayout(layoutName);
                ScanLayout(layout);

                if (layout.isOverride)
                {
                    continue;
                }

                if (layout.isControlLayout)
                {
                    s_ControlLayouts.Add(layout.name);
                }
                else if (s_DeviceMatchers.ContainsKey(layout.name))
                {
                    s_ProductLayouts.Add(layout.name);
                }
                else
                {
                    s_DeviceLayouts.Add(layout.name);
                }
            }

            // Move all device layouts without a device description but derived from
            // a layout that has one over to the product list.
            foreach (var name in s_DeviceLayouts)
            {
                var layout = InputControlLayout.cache.FindOrLoadLayout(name);

                if (layout.m_BaseLayouts.length > 1)
                {
                    throw new NotImplementedException();
                }

                for (var baseLayoutName = layout.baseLayouts.FirstOrDefault(); !baseLayoutName.IsEmpty();)
                {
                    if (s_ProductLayouts.Contains(baseLayoutName))
                    {
                        // Defer removing from s_DeviceLayouts to keep iteration stable.
                        s_ProductLayouts.Add(name);
                        break;
                    }

                    var baseLayout = InputControlLayout.cache.FindOrLoadLayout(baseLayoutName);
                    if (baseLayout.m_BaseLayouts.length > 1)
                    {
                        throw new NotImplementedException();
                    }
                    baseLayoutName = baseLayout.baseLayouts.FirstOrDefault();
                }
            }

            // Remove every product device layout now.
            s_DeviceLayouts.ExceptWith(s_ProductLayouts);

            s_LayoutRegistrationVersion = manager.m_LayoutRegistrationVersion;
        }