Skip to content

Latest commit

 

History

History
83 lines (79 loc) · 2.36 KB

QuickSnippets.md

File metadata and controls

83 lines (79 loc) · 2.36 KB

Quick Snippets

Some code fragments showing how to do common actions.

Change a scene:
Framework.PushCommand(new ChangeSceneCmd(<SceneName>));
Change an option value:
Framework.App.Options.FullScreen = false;
Apply options and write the configuration to disk:
Framework.PushCommand(new ApplyOptionsCmd());
Implement a custom command:
class MyCustomCommand<T> : Command
{
    public T Data;
    public MyCustomCommand(T data) {
       Data = data;
    }
}
Push your custom command:
// execute on next Framework's Process()
// With injections
Framework.Dispatch(new MyCustomCommand<int>(42));
// Without injections
Framework.PushCommand(new MyCustomCommand<int>(42));

// delay execution for 3 frames
// With injections
Framework.Dispatch(new MyCustomCommand<int>(42), 3);
// Without injections
Framework.PushCommand(new MyCustomCommand<int>(42), 3);

// delay execution for 5 seconds
// With injections 
Framework.Dispatch(new MyCustomCommand<int>(42), 5.0f);
// Without injections
Framework.PushCommand(new MyCustomCommand<int>(42), 5.0f);
Implement a custom command listener:
// First bind it
CmdBinder.AddBinding<MyCustomCommand<int>>(OnCustomCommand);
// now implement a listener callback
void OnCustomCommand(Command c)
{
   var cmd = c as MyCustomCommand<int>;
   // cmd.Data = 42 here and you can use it as you wish...
}
Unregister a command listener:
CmdBinder.RemoveBinding<MyCustomCommand<int>>(OnCustomCommand);
Pass a data model from one scene to another:
As singleton:
Framework.Globals.PushObjectAsSingleton(new CustomDataModel());
As transient:
Framework.Globals.PushObjectAsTransient("myCustomData", new CustomDataModel());
Resolve a data model from the globals:
As singleton:
var myCustomData = Framework.Globals.ResolveSingleton<CustomDataModel>() as CustomDataModel;
As transient:
var myCustomData = Framework.Globals.ResolveTransient<CustomDataModel>("myCustomData") as CustomDataModel;
Access to SceneView can be done in the standard way you access any Unity component:
var sceneView = GameObject.Find("SceneView").GetComponent<SceneView>() as SceneView;