Beispiel #1
0
            // ToAction doesn't make sense because all bindings combine on the action set and
            // thus need conversion logic that operates on the actions in bulk.

            public static ActionJson FromAction(InputAction action)
            {
                var bindings      = action.bindings;
                var bindingsCount = bindings.Count;
                var bindingsJson  = new BindingJson[bindingsCount];

                for (var i = 0; i < bindingsCount; ++i)
                {
                    bindingsJson[i] = BindingJson.FromBinding(bindings[i]);
                }

                return(new ActionJson
                {
                    name = action.name,
                    bindings = bindingsJson
                });
            }
Beispiel #2
0
            public static MapJson FromMap(InputActionMap map)
            {
                ActionJson[]  jsonActions  = null;
                BindingJson[] jsonBindings = null;

                var actions = map.m_Actions;

                if (actions != null)
                {
                    var actionCount = actions.Length;
                    jsonActions = new ActionJson[actionCount];

                    for (var i = 0; i < actionCount; ++i)
                    {
                        jsonActions[i] = ActionJson.FromAction(actions[i]);
                    }
                }

                var bindings = map.m_Bindings;

                if (bindings != null)
                {
                    var bindingCount = bindings.Length;
                    jsonBindings = new BindingJson[bindingCount];

                    for (var i = 0; i < bindingCount; ++i)
                    {
                        jsonBindings[i] = BindingJson.FromBinding(bindings[i]);
                    }
                }

                return(new MapJson
                {
                    name = map.name,
                    id = map.id.ToString(),
                    actions = jsonActions,
                    bindings = jsonBindings,
                });
            }