In this first part of the lesson, we cover setting up the Unity project and implementing the SDK with domains.
Main Camera^
.AR Session^
by selecting GameObject -> XR -> AR Session.XR Origin^
by selecting GameObject -> XR -> XR Origin (Mobile AR).XR Origin^
, add two components: ^AR Raycast Manager^
and ^AR Plane Manager^
.start-note
We suggest to check which ARFoundation and ARKit/ARCore package versions are installed by Package Manager, as they might not be equal. This is not automatically handled when installing a "Preview" version and mismatch can happen.
end-note
Canvas^
by selecting GameObject -> UI -> Canvas.Button^
element by selecting GameObject -> UI -> Legacy -> Button. Adjust button parameters and text.Image^
element by selecting GameObject -> UI -> Image. Adjust the image parameters and duplicate it so that they cover the top and bottom of the mobile screen, as well as the previously created button.Text^
element by selecting GameObject -> UI -> Legacy -> Text. Add some brief instructions about calibrating using lighthouses.0.2^
so it appears as a 20cm cube in AR. This should be set to inactive so we don't see it until after calibrating into the domain.MonoBehaviour^
script named PersistentARinDomain and attach it to an empty GameObject in the scene.ConjureKit^
and ^Manna^
, as well as the following namespaces: ^UnityEngine.UI^
, ^UnityEngine.XR.ARFoundation^
, and ^UnityEngine.XR.ARSubsystems^
.using Auki.ConjureKit;
using Auki.ConjureKit.Manna;
using Auki.Integration.ARFoundation;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
[SerializeField] private Camera arCamera;
private const string AppKey = "YOUR_APP_KEY";
private const string AppSecret = "YOUR_APP_SECRET";
start-warning
Never share your app secret with anyone.
end-warning
IConjureKit^
and ^Manna^
variables.private IConjureKit _conjureKit;
private Manna _manna;
Start()^
method, initialize ^ConjureKit^
and ^Manna^
with the app key and secret:private void Start()
{
_conjureKit = new ConjureKit(
arCamera.transform,
AppKey,
AppSecret);
_manna = new Manna(_conjureKit);
var textureProviderComp = CameraFrameProvider.GetOrCreateComponent();
textureProviderComp.OnNewFrameReady += frame => _manna.ProcessVideoFrameTexture(frame.Texture, frame.ARProjectionMatrix, frame.ARWorldToCameraMatrix);
_manna.OnLighthouseTracked += OnLighthouseTracked;
_conjureKit.Connect();
}
[SerializeField] private GameObject cube;
[SerializeField] private GameObject calibrateUI;
private bool _calibrated = false;
OnLighthouseTracked()^
method used in ^Start()^
to handle the lighthouse tracking event. This method will be called when a lighthouse QR code is tracked by the camera. It will calibrate into the posemesh domain and hide the calibration UI, showing the cube marker instead.private void OnLighthouseTracked(Lighthouse lighthouse, Pose qrPose, bool isCalibrationGood)
{
// If the QR detection was good enough and the QR code is static (generated from the posemesh console),
// hide the calibration view and show the cube marker
if (isCalibrationGood && lighthouse.Type == Lighthouse.LighthouseType.Static)
{
if(!_calibrated)
{
_calibrated = true;
calibrateUI.SetActive(false);
cube.SetActive(true);
}
}
}
申请 AUKI 代币补助金以启动您的项目,并直接与 Auki Labs 团队合作,将您的创意推向市场。成功申请者可获得价值高达 10 万美元的 AUKI 代币,以及 Auki Labs 团队提供的开发和营销支持。