Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Dojo sdk integration #156

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cristianFleita
Copy link

@cristianFleita cristianFleita commented Dec 2, 2024

📝 Summary

In this PR I've added the dojo.unity SDK to the project

Type of Change

Mark with an x all the checkboxes that apply (like [x]).

  • 📝 Documentation (updates to README, docs, or comments)
  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 👌 Enhancement (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)

🔄 Changes Made

What's Changed

  • Using dojo 1.0.0 and dojo starter to call the spawn and move actions from that repo
  • All the tx are called from unity and the data is retrieved from Torii

limitations from dojo starter: it's only possible to make 100 movement steps

Technical Notes

Dojo starter setup

  1. Clone the Repository
git clone [email protected]:dojoengine/dojo-starter.git
  1. Checkout Version 1.0.0
    Navigate to the specific commit for version 1.0.0:
git checkout 5137c894abe2b48d55ad21c54a91661f94f22060
  1. Install Dojo 1.0.0
    Use dojoup to install the required version:
dojoup --version 1.0.0
  1. Running Locally

Terminal one:

katana --dev --dev.no-fee

Terminal two

sozo build && sozo migrate

torii --world 0x00e2ea9b5dd9804d13903edf712998943b7d5d606c139dd0f13eeb8f5b84da8d --http.cors_origins "*"

Note: The world address (0x00e2ea9b...) might differ. To verify your world address, run:

sozo inspect

Implementation Details

Dojo World Configuration

The configuration for the dojo world is defined in two ScriptableObjects:

Contracts and Models Generation

Using the command:

sozo build --unity

The bindings for contracts and models are generated. These are added to:

  • Assets/Spawn And Move/Models: Used to retrieve position data from Torii.
  • Assets/Spawn And Move/Contracts: Used for spawning and moving transactions.

SDK setup

  1. Download the Dojo.Unity SDK
    Download the SDK from the official release.

  2. Import the SDK
    Import only the Plugins folder into your Unity project.

Screenshot 2024-12-04 at 17 07 23
  1. Fix macOS Quarantine Restrictions
    Run the following command in your terminal to remove quarantine attributes from the plugin:
cd Assets/Dojo/Plugins/macOS
xattr -d com.apple.quarantine libdojo_c.bundle

Integration in Scene

The SDK has been integrated into the Assets/Scenes/Forest.unity scene:

  • The WorldManager prefab has been added
Screenshot 2024-12-02 at 14 37 25

Two additional MonoBehaviours are included:

  1. Actions: Configures the actions contract address using the bindings.
  2. DojoSpawnAndMoveExecuter: Found at Assets/Scripts/DojoSpawnAndMoveExecuter.cs.

A reference to DojoSpawnAndMoveExecuter has been added to the PlayerController, enabling:

  • Spawning and moving transactions.
  • Retrieving updated position data from Torii.
Screenshot 2024-12-02 at 14 41 56

Key Implementation Details in DojoSpawnAndMoveExecuter

  1. Initialization:
    Performed in Awake.

  2. Exposed Methods for Contracts:

  1. Position Update Event:

An event is emitted whenever the position changes.
The PlayerController consumes this event to respond to position updates.

Evidence

@cristianFleita cristianFleita marked this pull request as ready for review December 2, 2024 18:01
@jimenezz22 jimenezz22 added approved pr ready to merge hold labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved pr ready to merge hold
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants