Hi, Excellent, that will help me greatly! I can't promess when I am going to start on this, so please bump every week or so, just to keep me aware of that... I need it. Bye, Jean
More like once a month or so, but here's the bump
I'll give up on it for now. I managed to find a better way to reference actions than strings, but other than that, there's always a thing or two in the way to make it work. They changed something that the old version I made a while back don't respond anymore.
Right now, it's the old problem that virtually all example scripts use hardcoded references, but the action must be flexible.
I found that using the InputActionReference might be the best way for PlayMaker actions:
The reference will remain intact even if the action or the map that contains the action is renamed.
References can be set up graphically in the editor by dropping individual actions from the project browser onto a reference field
But I didn't get very far with this. I can fetch asset, action map and asset from the reference, but when I plug it in (no errors), it still won't do the thing.
public InputActionReference inputAction;
InputAction action;
InputActionAsset asset;
InputActionMap map;
public override void OnEnter()
{
if (inputAction != null)
{
// get the references
asset = inputAction.asset;
action = inputAction.action;
map = action.actionMap;
}
action.performed += ctx => DoIt();
}
void DoIt()
{
Debug.Log("Did it");
}
void OnEnable()
{
map.Enable();
}
void OnDisable()
{
map.Disable();
}
...
They don't return null, also log apparently correctly (e.g. Debug.Log(map.name)), But in hardcoded way, with hardcoded references, it works. E.g.
controls = new Controls();
...
controls.Gameplay.Foo.performed += ctx => DoIt();
Another neat function I found in one of the visualizer scripts:
public InputActionReference actionReference;
public FsmString actionName;
InputAction action;
private void ResolveAction()
{
//// NEAT SNIPPED FROM UNITY
// If we have a reference to an action, try that first.
if (actionReference != null)
action = actionReference.action;
// If we didn't get an action from that but we have an action name,
// just search through the currently enabled actions for one that
// matches by name.
if (action == null && !string.IsNullOrEmpty(actionName.Value))
{
var slashIndex = this.actionName.Value.IndexOf('/');
var mapName = slashIndex != -1 ? this.actionName.Value.Substring(0, slashIndex) : null;
var actionName = slashIndex != -1 ? this.actionName.Value.Substring(slashIndex + 1) : this.actionName;
var enabledActions = InputSystem.ListEnabledActions();
foreach (var action in enabledActions)
{
if (string.Compare(actionName.Value, action.name, StringComparison.InvariantCultureIgnoreCase) != 0)
continue;
if (mapName != null && action.actionMap != null && string.Compare(mapName, action.actionMap.name,
StringComparison.InvariantCultureIgnoreCase) != 0)
continue;
this.action = action;
break;
}
}
if (action == null) Finish();
}
That's what I got.