I'm adding a replaying feature to my game. Having this feature, I can capture user's input to the game and feed them back to Unity later on for replaying the game. But the design of VRStandardAssets.Utils.VRInput class prevents me to mimic user inputs.
This class does not provide any public method to make it possible to trigger its events (e.g. OnClick or OnDoubleClick events) programmatically. So I decided to create a derived class from it and write my own public methods to trigger the events. This strategy failed because VRInput's methods are private meaning that I cannot invoke them from a derived class.
It is recommended for this type of classes to provide a protected virtual void On[eventName](subclassOfEventArgs e) method to provide a way for a derived class to handle the event using an override but this class does not have it (why so restrictive?). I guess it's a poor design from Unity. This poor design also makes it hard to write unit/integration tests.
Am I missing something here? Can I still do something to trick other classes to think they are dealing with VRInput class while replaying the game?
VRInputbecause it create multiple instances ofVRInputwhich is unnecessary since there is only one user input. Making it worth being derived from would have been fine if this was a UI control like a UI button event since there can be many of them in the scene. - ProgrammerGameObject obj = GameObject.Find("VRInputObj");. Now get the VRInput component from it:VRInput vrInput = obj.GetComponent<VRInput>();then invoke any of its event:vrInput.OnUp != null) { vrInput.OnUp.Invoke(); }- ProgrammerVRInput. Put it in theVRStandardAssets.Utilsnamespace then drop it in the location the old one is already at. That's it. you can even use this time to add thevirtualmethod you've been talking about. - Programmer