io.magicave.solid-unity

0.10.8 • Public • Published

dNo Unity SDK

About

Unity package for accessing owned dNo Dice for users in your Unity project. The SDK interfaces with the dNo Cloud API.

The SDK has been tested to work with the following platforms;

  • PC Standalone (Windows & Mac)
  • Android
  • iOS
  • WebGL

Discord

As a game dev working in the dNo community join the dNo Discord. There you can discuss ideas and get support with your integration.

Requirements

These are some dependencies of the package;

  • Unity Addressables - this Unity asset management package has been used load 3d assets of our digital toys.
  • URP (Universal Render Pipeline) - the 3d assets have been built with this pipeline and it's required to render the assets in game.
  • Firebase Authentication - Firebase/Google authentication used to sign in players before we can retrieve owned assets.

Getting started

As stated in the in the Requirements section make sure that the Unity project has been create to work with URP.

The dNo Unity SDK is an UPM (Unity Package Manager) package that is hosted in npmjs.org and as such the Unity Package Manifest needs to be updated with the following;

{
  "dependencies": {
    ...
    "io.magicave.solid-unity": "0.9.2"
  },
  "scopedRegistries": [
    {
      "name": "npmjs",
      "url": "https://registry.npmjs.org/",
      "scopes": [
        "io.magicave"
      ]
    }
  ]
}

Now you are good to open up the Unity project. As mentioned in the Requirements section the SDK uses Unity Addressables. If your project doesn't use Addressables you need to run a default Addressables build to set up the appropriate config.

You are now ready to start interfacing with dNo 🚀.

Samples

In the Package Manager window you'll see that there are two Samples that can be imported for Magicave Solid SDK; WebGL Template and Basic Game Workflow. The latter will demonstrate how to interact with the SDK.

Click Import then there will be four scenes inside Assets/Samples/BasicGameWorkflow/Assets/Scenes that show how to initialise the SDK, sign in a User, inspect owned Dice and eventually see the 3d Dice assets.

The extract below is based on the GameInitialization.cs script found in the Samples but demonstrates how quickly

using System;
using Magicave.Solid.Runtime;
using Magicave.Solid.Runtime.Models;
using UnityEngine;

public class GameInitialization : MonoBehaviour
{
    private async void Start()
    {
        try
        {
            await SolidSdk.Init();
        
            // now ready to start interacting with the SDK

            var magicaveUser = SolidSdk.Auth.User;
            if (magicaveUser.HasAuth(UserAuthState.WalletConnected))
            {
                print($"User {magicaveUser.Uid} has their wallet connect: {magicaveUser.WalletAddress}");
            }

            foreach (IDiceSet ownedDiceSet in SolidSdk.Assets.OwnedDiceSets)
            {
                print($"Owned dice {ownedDiceSet.Uid}");
            }
        }
        catch (Exception e)
        {
            Debug.LogException(e);
            Debug.LogError("Unable to start the Magicave SDK");
        }
        
    }
}

Loading Assets

The 3d Dice assets can be loaded directly from the IDiceSet objects that were being inspected above.

foreach (var assetPair in await ownedDiceSet.GetAssets())
    {
        var go = Instantiate(assetPair.Value as GameObject);
    }

Where each DiceSet has the following dice types; D4, D6, D8, D10, D12, D20, D100

Authentication

For a player to use the Dice sets they own you need to be able to sign them into their account. A Magicave account can be created, or signed into, with email and password. (NB: the connection of a Web3.0 wallet is done on our dNo Web app outside of the Unity SDK).

private async UniTask _SignIn(SignInRequestType requestType)
    {
        try
        {
            var email = emailInputField.text;
            var password = passwordInputField.text;
            
            await SolidSdk.Auth.SignIn(new SignInRequest(email, password, requestType));
            
            signInScreen.SetActive(false);
            
            Refresh();
        }
        catch (Exception e)
        {
            ShowErrorMessage(e.Message).Forget();
        }
    }

Package Sidebar

Install

npm i io.magicave.solid-unity

Weekly Downloads

194

Version

0.10.8

License

MIT

Unpacked Size

422 MB

Total Files

1213

Last publish

Collaborators

  • magicave-ed