Hello,
I am trying to have a ScriptableObject have a LocalizedString variable with Local Variables that change dynamically at runtime (it won’t work while only editing). Most of the examples that I have seen are simple variables or serialized fields, but the variable I need here is only defined while the game is running, and I have not been able to figure it out so any help will be greatly appreciated!
My use case is for tutorial objects. These will be ScriptableObjects with the LocalizedString message that then will be passed to an object with TextMeshPro. The tutorial messages are smart strings that will resolve in either text or sprites based on the current player controller. I have the logic in place to get the glyphs because I have a system for prompts already working.
Example: “Use {upMovement}, {downMovement}, {leftMovement}, and {rightMovement} to move around”
Ideally, I can define that upMovement is rewiredAction 3 with Pole Positive in the scriptable object, for example. And when the tutorial is shown, it replaces to “Use W, S, A, and D to move around” (and that will depend if the player is using gamepad or if they changed the keybindings).
I have done smart string replacements before but all have been done at runtime without using the inspector. That is another option I’m looking into right now if I cannot figure this one out, to just explicitly state every smart string variable that uses Input and convert that in the code for these tutorials.
(In addition to this, I will need to convert the icon into a text sprite in TextMeshPro but that’s outside of the scope of this question)
This is the last thing I tried, but I never get the debug.log hits so I’m not sure when does Localization tries to grab the value:
[Serializable]
public class InputGlyphVariable : IVariable
{
[ActionIdProperty(typeof(RewiredConsts.Action))]
[SerializeField] int rewiredAction;
[SerializeField] Pole pole;
public object GetSourceValue(ISelectorInfo selectorInfo)
{
GlyphHandler glyphHandler = GlyphHandler.CreateAndAddPlayer(ReInput.players.GetPlayer(0));
SpriteOrText spriteOrText = glyphHandler.GetGlyph(rewiredAction, pole);
if (spriteOrText.TypeOfGlyph is SpriteOrText.GlyphType.Text)
{
Debug.Log($"Text: {spriteOrText.GlyphText}");
return spriteOrText.GlyphText;
}
else
{
Debug.Log($"Icon: {spriteOrText.GlyphIcon.name}");
return spriteOrText.GlyphIcon.name;
}
}
}
Another thing to notice is that in the tests that I have done it tends to complain that it cannot find the right info while I’m in Editor mode, I’m assuming this is expected because this info is only available at runtime. Is there a way to avoid this other than just do null checks?