Every interface and object that is described in wiki API can be injected using Zenject
framework.
Here is a basic injection example:
class Installer : Installer<Installer> {
public override void InstallBindings() {
Container
.Bind<Script>() //binds the script
.AsSingle() //prevents multiply instances bind
.NonLazy(); //says zenject to bind an instance
//even if it was not used anywhere
}
}
class Script : MonoBehaviour {
[Inject] IReplayPauseController _pauseController;
void Start() {
//here _pauseController is not null cause it was injected
//so you can do whatever you want with it, for example:
_pauseController.Pause(); //pauses the replay
}
}
You can find more info about Zenject
by following this link: https://github.com/modesttree/Zenject
Now we know that everything can be injected, so let's use it! As you've probably seen there are two ways to launch the replay: ReplayerMenuLoader.StartReplay
and ReplayerMenuLoader.StartReplayAsync
. I'll show you both.
The complicated way. You need to create the ReplayLaunchData
manually.
class Script : MonoBehaviour {
[Inject] ReplayerMenuLoader _loader;
//these fields should be filled manually
public IReplay replay;
public IReplayComparator comparator; //you can use ReplayDataHelper.BasicReplayComparator
//but only for BeatLeader replays
void Start() {
var launchData = new ReplayLaunchData(); //create the launch data
var settings = ReplayerSettings.UserSettings; //you can also use
//ReplayerSettings.DefaultSettings
launchData.Init(replay, comparator, settings); //initialize it
_loader.StartReplay(launchData); //run launch method
}
}
The easier one, everything you need to specify is just a replay (but if you won't specify the player it won't load the player profile component).
class Script : MonoBehaviour {
[Inject] ReplayerMenuLoader _loader;
//these fields should be filled manually
public Replay replay;
public Player player; //optional field
void Start() {
_loader.StartReplayAsync(replay, player); //run launch task
}
}