GnP 1: Setup and SDK implementation

In this first part of the lesson, we'll download an existing single player AR game to use as the starting point and implement the Auki SDK.

Initial project setup

For the purpose of this tutorial, we have created a repository that you can use as a starting point for the project. All features of the gameplay have been implemented in single player mode. The repository commits have been tagged to mark the states of the project according to the sections of this tutorial.

To get started, pull the project from GitHub and check out the "Initial project setup" commit:

git clone git@github.com:aukilabs/ConjureKit-Shooter-Game.git
cd ConjureKit-Shooter-Game
git checkout 07d285316bc8d4626ba444172be70bffa6cb679a

Upon opening the project in Unity, there will be an error message asking you to enter Safe Mode; you can safely ignore this. The cause of the error is the project's dependency on a couple of assets that are available for free in the Unity asset store. In order to fix this, please import these two assets:

Once the above assets are imported (note: don't forget to go through the quick setup process for DOTween), you should be able to play and test the game. If you want to try it in the Editor, you can press Alpha 1 to toggle mouse control, in order to emulate first person control for easier editor testing.

The project can also be built to a device without any additional changes to settings. Please refer to the relevant device-platform deployment documentation. You will see a "Missing Project ID" dialog, but you can click "Yes" to continue.

Auki SDK implementation

In this part, we'll start implementing the Auki SDK (previously called ConjureKit) into the project, and listen to some of the callbacks. The packages we need should already be installed in the project pulled from GitHub, but if you need to, please refer to the Quickstart guide for instructions on how to set up the SDK.

start-note

Please also make sure the Managed Stripping Level is set to Minimal, under Project Settings > Player > Optimization.

end-note

First let's add the necessary packages to ^Main.cs^:

using Auki.ConjureKit;
using Auki.ConjureKit.Manna;
using Auki.ConjureKit.Vikja;
using Auki.Integration.ARFoundation.Manna;
using Auki.Util;

Then we'll declare the fields that will hold references to ConjureKit and its modules:

private IConjureKit _conjureKit;
private Vikja _vikja;
private Manna _manna;
private FrameFeederBase _arCameraFrameFeeder;

These two fields will keep track of the session and its current state:

private State _currentState;
private Session _session;

Next we want to construct/initialize all the ConjureKit modules. We can do that in the ^Start()^ method of ^Main.cs^:

private void Start()
{
    Screen.sleepTimeout = SleepTimeout.NeverSleep;

    _conjureKit = new ConjureKit(arCamera.transform, "YOUR_APP_KEY", "YOUR_APP_SECRET", AukiDebug.LogLevel.ERROR);
    _manna = new Manna(_conjureKit);
    _vikja = new Vikja(_conjureKit);

    _arCameraFrameFeeder = _manna.GetOrCreateFrameFeederComponent();
    _arCameraFrameFeeder.AttachMannaInstance(_manna);

    EventInit();
    _conjureKit.Connect();
}

start-warning

Make sure you replace ^YOUR_APP_KEY^ and ^YOUR_APP_SECRET^ with the values you got during registration.

end-warning

Now let's create ^EventInit()^ in which we'll subscribe all the methods (that we'll declare shortly) to their respective events from ConjureKit:

private void EventInit()
{
    _conjureKit.OnJoined += OnJoined;
    _conjureKit.OnLeft += OnLeft;
    _conjureKit.OnParticipantLeft += OnParticipantLeft;
    _conjureKit.OnEntityDeleted += OnEntityDeleted;
    _conjureKit.OnParticipantEntityCreated += OnParticipantEntityCreated;
    _conjureKit.OnStateChanged += OnStateChange;

    _manna.OnLighthouseTracked += OnLighthouseTracked;
    _manna.OnCalibrationSuccess += OnCalibrationSuccess;
}

start-note

For more information on these callbacks, please refer to ConjureKit core package and OnLighthouseTracked.

end-note

And then we'll declare these methods to listen to the respective events above:

#region ConjureKit Callbacks
private void OnJoined(Session session)
{

}

private void OnLeft(Session lastSession)
{

}

private void OnParticipantLeft(uint participantId)
{

}

private void OnEntityDeleted(uint entityId)
{

}

private void OnParticipantEntityCreated(Entity entity)
{

}

private void OnStateChange(State state)
{

}

private void OnLighthouseTracked(Lighthouse lighthouse, Pose pose, bool closeEnough)
{

}

private void OnCalibrationSuccess(Matrix4x4 calibrationMatrix)
{

}
#endregion

Now that we have prepared all the needed callbacks, let's add a way to update the Session ID and the ConjureKit State in ^UIManager.cs^:

public void SetSessionId(string id)
{
    sessionText.SetText(id);
}

public void UpdateState(string state)
{
    stateText.SetText(state);
}

With the above methods declared, let's call them in the ^OnJoined^ callback:

#region ConjureKit Callbacks
private void OnJoined(Session session)
{
    _myId = session.ParticipantId;
    _session = session;

    uiManager.SetSessionId(_session.Id);
}

and ^OnStateChange^:

private void OnStateChange(State state)
{
    _currentState = state;
    uiManager.UpdateState(_currentState.ToString());
    var sessionReady = _currentState is State.Calibrated or State.JoinedSession;
    _arCameraFrameFeeder.enabled = sessionReady;
}

Now we should be able to see the Session ID and the ConjureKit State upon running the project. By enabling the ^_arCameraFrameFeeder^ when the current state is ^JoinedSession^ or ^Calibrated^, Manna will start scanning once we are connected to a session, and will stop automatically if we are disconnected.

This is the beginning of this lesson

Need a refresher on the essentials?

Check out more lessons, DIY kits and essentials reading material at the developer learning centre homepage.

Want to build on the posemesh and need a helping hand?

Apply for a grant of AUKI tokens to get your project off the ground, and work directly with the Auki Labs team to get your creation to market. Successful applicants may be granted up to 100k USD worth of AUKI tokens, and development and marketing support from the Auki Labs team.