UnityHawk lets you run emulated games within a Unity project, using BizHawk.
Made as a tool for the development of plunderludics.
Only works on Windows currently. Works best with Unity 2022.2 or later.
Under development, may have bugs; issues, feature requests or contributions are welcome.
Add these two lines under dependencies in your manifest.json:
"org.plunderludics.unityhawk": "https://github.com/plunderludics/unity-hawk.git?path=/Packages/org.plunderludics.UnityHawk",
"com.codewriter.triinspector": "https://github.com/codewriter-packages/Tri-Inspector.git"
Or, install using openupm-cli:
openupm add org.plunderludics.unityhawk
UnityHawk should then appear in the Package Manager window. From the Package Manager window you can import the sample called Demo for a simple example of how to use this package.
You will probably also need to install the BizHawk prerequisites, which can be installed via this installer.
- Add an
Emulatorcomponent to an object with an attachedRenderer. - Add the rom and savestate files you want to use somewhere in your Unity
Assets/directory (plus config or lua files if needed). - Drag those assets onto the corresponding slots on the
Emulatorcomponent. - If using a platform that requires firmware, put the firmware inside
StreamingAssets/Firmware/. - Hit play
- Enable 'Pass Input From Unity' to send input from Unity to Bizhawk. If this isn't enabled Bizhawk will get input directly from the operating system.
- You can specify the component used to handle input under 'Input Provider'. If unspecified it will default to a
BasicInputProviderwith default controls according to the platform. If you want to configure controls, add your ownBasicInputProvidercomponent. - Alternatively you can create your own component that inherits from
InputProvider. InputProvideralso provides anAddInputEventmethod which can be used to programmatically add inputs.
- You can specify the component used to handle input under 'Input Provider'. If unspecified it will default to a
- Enable 'Show Bizhawk Gui' (under 'Development') to show the native Bizhawk window; useful for doing plunderludics development (finding save states, tweaking config & scripts, etc) without having to leave Unity
- Enable 'Capture Emulator Audio' to route emulator audio to an AudioSource, allowing you to use Unity's positional audio system or add audio effects
- (Might produce minor latency or distortion)
- The live emulator graphics can be grabbed in code via the
Emulator.Textureproperty. - The
Emulatorcomponent provides an interface to basic Bizhawk API methods. See the API documentation for more info.- Basic emulator controls:
Pause(),Unpause(),FrameAdvance(),LoadState(Savestate s),SaveState(string path),LoadRom(Rom r),SetVolume(float v),SetSpeedPercent(int p). Use theBasicApiToolcomponent to use these methods directly from the Editor. - For interacting with console memory:
WatchUnsigned(long address, int size, bool isBigEndian, string domain, Action<uint> callback)(+ similar methods for Signed and Float types),WriteUnsigned(long address, uint value, int size, bool isBigEndian, string domain = null)(+ similar methods for Signed and Float types),Freeze(long address, int size, string domain = null), andUnfreeze(long address, int size, string domain = null). Use theMemoryApiToolcomponent to use these methods directly from the Editor.
- Basic emulator controls:
- Within a BizHawk Lua script, you can use the
unityhawk.callmethod(methodName, argString)method to send and receive information from Unity. The method must be registered on the Unity side usingEmulator.RegisterLuaCallback. SeeRegisterMethodExample.luaandRegisterMethodExamplein theDemosample for a brief example.
- Building (for Windows) should just work; the input files you choose (roms, firmware) will be copied into the build, as well as the necessary Bizhawk dependencies. (Building multiple scenes might work but is untested.)
The Emulator component spawns EmuHawk.exe as a child process which shares graphics and audio with Unity via shared memory.
UnityHawk uses a modified fork of BizHawk which is here: https://github.com/plunderludics/bizhawk/tree/unity-hawk
The included demo scene contains this shader, this model of a TV, and a rom of Elite for the NES.
UnityHawk is inspired by Multibowl, the Bizhawk Ring Shuffler and a lot of other things.
If you want help setting up the tool, or you are interested in contributing, or have any other questions, feel free to join our discord: https://discord.gg/ATJSh8W8dp.