In order to handle notifications from the SLAM engine in your code, you can subscribe to the event KatanaCamera.OnSlamTracking in one of your C# scripts, e.g.:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Katana;
public class Gui: MonoBehaviour {
public KatanaCamera katanaCamera; // must reference a valid Katana Camera in your scene
void Start() {
katanaCamera.OnSlamTracking += MyOnSlamTracking;
}
void MyOnSlamTracking(int state) {
switch (state) {
case 1: //Initializing
// do something (e.g. hide object in scene)
break;
case 2: // Exception Thrown State
break;
case 3: // Tracking
// do something (e.g. show object in scene)
break;
case 4: // Relocalizing
// do something (e.g. hide object in scene)
break;
default:
break;
}
}
}
using System.Collections.Generic;
using UnityEngine;
using Katana;
public class Gui: MonoBehaviour {
public KatanaCamera katanaCamera; // must reference a valid Katana Camera in your scene
void Start() {
katanaCamera.OnSlamTracking += MyOnSlamTracking;
}
void MyOnSlamTracking(int state) {
switch (state) {
case 1: //Initializing
// do something (e.g. hide object in scene)
break;
case 2: // Exception Thrown State
break;
case 3: // Tracking
// do something (e.g. show object in scene)
break;
case 4: // Relocalizing
// do something (e.g. hide object in scene)
break;
default:
break;
}
}
}
You can then use this information to update your UI for instance.
Comments
2 comments
This code gives errors I cant use it!
Hey Francisco,
Can you copy and paste the error that you're seeing so we can better debug it?
Did you make sure to reference the KatanaCamera GameObject inside the Unity Editor Scene? We found this is a common step that people forget to do.
Also, we took some other developers' advice and fleshed out the code so you can see where to put some controller logic. In this example script you can put logic inside the case statements under // do something here.
Some common things that people do include showing the tracking state on screen, and hiding/showing a referenced 3D model in the scene depending on tracking state.
Cheers!
Alvin
Please sign in to leave a comment.