An example project to help someone kickstart their exploration into Arcadia.
Uses some small adjustments to make it work, these will hopefully be merged in to the main repos of their respected projects:
- Arcadia:
- Original Project: https://github.com/arcadia-unity/Arcadia
- Fork: https://github.com/Folcon/Arcadia
- tools.cursive-arcadia-repl:
- Clone the project using
git clone --recursive https://github.com/Folcon/arcadia-example-project.git your-game-name
- Use Unity Hub to add your game folder and open it in Unity.
- In Intellij with Cursive, go to File->Open and then open the game folder.
- File->Project Structure, select Modules. You might want to rename
arcadia-example-project
to your game name. - Remove
tools.cursive-arcadia-repl
from modules then add it and select import, then select thetools.cursive-arcadia-repl
folder. Import it as a leiningen project. - Create a new run configuration based on leiningen and name it
Start Arcadia REPL
. Selecttools.cursive-arcadia-repl
as the module and then putrun
into parameters and+dev
into profiles. - Create a new run configuration based on the clojure remote repl and name it
RREPL
. Selecttools.cursive-arcadia-repl
as the module,nrepl
as the connection type and host islocalhost
with port7888
.
- Start Unity and Play the scene.
- Boot run configuration
Start Arcadia REPL
- Boot run configuration
RREPL
- If you're on windows and are using wsl2 then make sure you have your ports open. A script if you need some help =)... Just add the appropriate ports you want open into it.
- Navigate to
Assets/game_src/game/core.clj
- Use SHIFT-ALT-L or
Load File in REPL
, accessible from the repl menu by right-clicking and looking for the REPL option. This should displayLoading Assets/game_src/game/core.clj...
- Bring your cursor to
(create-main)
within the comment block, specifically it should be where the pipe is:(comment ;; Make sure you run this while unity is already running. ;; For programmatic stuff like this you might not want to modify your scene. ;; To be honest it depends on your coding style =)... (create-main)| (hook-main))
- Use SHIFT-ALT-P or
Send '(create-main)' to REPL
, accessible from the repl menu by right-clicking and looking for the REPL option. This should display in your REPL:In Unity you should see a new GameObject called(create-main) => #<Main (UnityEngine.GameObject)>
Main
in your hierarchy. Selecting it will show it's a simple GameObject. - Do it again with
(hook-main)
which should display in your REPL:In Unity you should see the(hook-main) => #'game-src.game.core/log-name
Main
GameObject now has two new components:Arcadia State (Script)
andStart Hook (Script)
, with theStart Hook (Script)
containing a reference to:log-name
pointing to#'game-src.game.core/log-name
, which is indicating which clojure function within what namespace it's pointing to. - Stopping Play within Unity should make the
Main
GameObject disappear, so you'll need to reload and invoke your code in the repl to create it again. - Setup your project to be exported by adding into
Arcadia/configuration.edn
. You'll find:export-namespaces
commented out, so uncomment it and change it to look like below:You can now build your project. I would advise testing this to ensure that it builds, there's nothing worse than making a lot of changes and then realising you can't share your game! Look at the:export-namespaces [game-src.game.core]
Build Your Game
segment for instructions. - Happy Hacking!
- Eval the code below within the
game-src.game.core
ns while not in play mode! This will hook themain
function which is the entry point of your code to theMain Camera
:(arc/hook+ (arc/object-named "Main Camera") :start :main #'main)
- Make sure your
:export-namespaces
is up-to-date, containing at leastgame-src.game.core
. - Delete the
Arcadia/Compiled
andArcadia/Export
in your project. - From the Unity menu, select
Arcadia
->AOT Compile
- From the Unity menu, select
Arcadia
->Prepare for Export
- From the Unity menu, select
File
->Build And Run
- You should now see at least a cube, if not your game in all of its glory!