In this chapter, we'll cover how to add and initialize ConjureKit to a new Unity project.
start-warning
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-warning
start-note
ARFoundation
versions below 4.2.6 do not support iOS 16.
end-note
AR Session Origin
by selecting GameObject -> XR -> AR Session Origin.ARTrackedImageManager
component to the AR Session Origin GameObject.ReferenceImageLibrary
by selecting Assets -> Create -> XR -> Reference Image Library. and drag it to the “serialized library” field in the ARTrackedImageManager
component.ARTrackedImageManager
component to 1.AR Session
by selecting GameObject -> XR -> AR Session.1. Install the ConjureKit package.
2. Create a new ^MonoBehaviour^
script and attach it to an empty game object in the scene.
3. Import ^ConjureKit^
.
using Auki.Ur;
4. Create a private ^IConjureKit^.
private IConjureKit _conjureKit;
5. Create a public ^Camera^
variable.
public Camera arCamera;
6. Drag the AR Camera
to the ^arCamera^
field on the GameObject you created;
7. Initialize ^ConjureKit^
with the app key and secret from the posemesh console (cf. the Quickstart guide)
start-warning
Never share your app secret with anyone.
end-warning
8. Call ^_conjureKit.Connect()^
to connect to a Relay server with the lowest latency and create a session.
using Auki.ConjureKit;
public class ConjureKitDemo : MonoBehaviour
{
public Camera arCamera;
private IConjureKit _conjureKit;
private void Start()
{
_conjureKit = new ConjureKit(
arCamera.transform,
"YOUR_APP_KEY",
"YOUR_APP_SECRET");
_conjureKit.Connect();
}
}
9. Declare two new ^Text^
fields to display the session ID and session state on screen.
[SerializeField] private Text sessionState;
[SerializeField] private Text sessionID;
10. Register a callback to the ^_conjureKit.OnStateChanged^
event that fires every time our session state changes.
_conjureKit.OnStateChanged += state =>
{
sessionState.text = state.ToString();
};
11. Register callback to ^_conjureKit.OnJoined^
and ^_conjureKit.OnLeft^
which are triggered when we join and leave a session.
_conjureKit.OnJoined += session =>
{
sessionID.text = session.Id;
};
_conjureKit.OnLeft += session =>
{
sessionID.text = "";
};
12. Create two ^Text^
elements and drag and drop them to the fields you declared in step 8.
13. Click Play in Unity Editor. Now you'll see the state of your connection logged in the console and session id and state on the screen.
申请 AUKI 代币补助金以启动您的项目,并直接与 Auki Labs 团队合作,将您的创意推向市场。成功申请者可获得价值高达 10 万美元的 AUKI 代币,以及 Auki Labs 团队提供的开发和营销支持。