ARMOD Events

What is ARMOD Events?

ARMOD Events is a script (class) that is also the entry point for the interactive logic of any AR experience; it is usually created by PackageTools when creating a project.
They are executed only in the classes filled in the Programmalbe configuration entry. An ARExperience has only one entry.

OnLoad

OnLoad method called when the ARExperience package is loaded. OnLoad method is generally used to load resources and prepare resources.
C#
Example Code
1
private const string CONST_CANVAS = "Canvas";
2
private const string CONST_PROJECT_NAME = "PortalExample";
3
public static readonly API API = new API();
4
private GameObject canvas;
5
private GameObject tipsUI;
6
private GameObject augmentedRealityVirtualObject;
7
private Transform augmentedRealityVisualizerTransform;
8
private Transform mainCameraTrans;
9
10
//Please delete the function if it is not used
11
public void OnLoad()
12
{
13
//Loading the UGUI
14
API.LoadGameObject(CONST_PROJECT_NAME, CONST_CANVAS,
15
_canvas =>
16
{
17
canvas = API.InstanceGameObject(_canvas, "", null);
18
tipsUI = API.FindGameObjectByName("Tips");
19
tipsUI.SetActive(true);
20
});
21
22
//Get MainCamera(ARCamera)
23
mainCameraTrans = GameObject.FindWithTag("MainCamera").transform;
24
25
//Loding AR virutal object
26
API.LoadGameObject(CONST_PROJECT_NAME, CONST_PROJECT_NAME, _augmentedRealityVirutalObject =>
27
{
28
augmentedRealityVirtualObject = API.InstanceGameObject(_augmentedRealityVirutalObject, "", null);
29
augmentedRealityVisualizerTransform = augmentedRealityVirtualObject.transform;
30
augmentedRealityVirtualObject.SetActive(false);
31
});
32
}
Copied!

OnUpdate

OnUpdate method running every frame when ARExperience package is loaded. OnUpdate is the same as Update in Unity.OnUpdate is executed after OnLoad
Since OnUpdate is running every frame it is quite performance intensive.
C#
Example Code
1
private bool placed;
2
private Vector3 position;
3
private Quaternion rotation;
4
5
private const string CONST_CANVAS = "Canvas";
6
private const string CONST_PROJECT_NAME = "PortalExample";
7
public static readonly API API = new API();
8
private GameObject canvas;
9
private GameObject tipsUI;
10
private GameObject augmentedRealityVirtualObject;
11
private Transform augmentedRealityVisualizerTransform;
12
private Transform mainCameraTrans;
13
14
//Please delete the function if it is not used
15
public void OnLoad()
16
{
17
//Loading the UGUI
18
API.LoadGameObject(CONST_PROJECT_NAME, CONST_CANVAS,
19
_canvas =>
20
{
21
canvas = API.InstanceGameObject(_canvas, "", null);
22
tipsUI = API.FindGameObjectByName("Tips");
23
tipsUI.SetActive(true);
24
});
25
26
//Get MainCamera(ARCamera)
27
mainCameraTrans = GameObject.FindWithTag("MainCamera").transform;
28
29
//Loding AR virutal object
30
API.LoadGameObject(CONST_PROJECT_NAME, CONST_PROJECT_NAME, _augmentedRealityVirutalObject =>
31
{
32
augmentedRealityVirtualObject = API.InstanceGameObject(_augmentedRealityVirutalObject, "", null);
33
augmentedRealityVisualizerTransform = augmentedRealityVirtualObject.transform;
34
augmentedRealityVirtualObject.SetActive(false);
35
});
36
}
37
38
//Please delete the function if it is not used
39
public void OnUpdate()
40
{
41
if (placed) return;
42
if (!Input.GetMouseButtonDown(0)) return;
43
tipsAlphaAnimation.StartFade(0);
44
AnchorNotificationData tmp_AnchorData = new AnchorNotificationData
45
{
46
Offset = mainCameraTrans.forward * 2.5f,
47
Position = Input.mousePosition,
48
StickType = AnchorNotificationData.StickTypeEnum.ByScreen,
49
TrackableType = AnchorNotificationData.TrackableTypeEnum.All,
50
ControllerTargetNode = augmentedRealityVirtualObject,
51
ActionName = "AnchorPlace",
52
NotificationAct = () =>
53
{
54
API.FindGameObjectByName("PortalMesh").AddComponent<PortalInteractor>();
55
API.FindGameObjectByName(CONST_PROJECT_NAME).GetComponentInChildren<Animator>().SetTrigger("Open");
56
augmentedRealityVirtualObject.SetActive(true);
57
placed = true;
58
}
59
};
60
API.StickObject(tmp_AnchorData);
61
}
Copied!

OnEvent

OnEvent is a AR algorithm callback method. All feedback from the AR algorithm will be notified to the method. e.g. It will be executed when the image tracking status changes.
1
//Please delete the function if it is not used
2
public void OnEvent(BaseNotificationData _data)
3
{
4
if (placed) return;
5
if (focusGroup == null) return;
6
if (focusFinding == null) return;
7
if (focusFound == null) return;
8
if (placeButtonGameObject == null) return;
9
10
if (_data is FocusResultNotificationData _FocusResult)
11
{
12
switch (_FocusResult.FocusState)
13
{
14
case FindingType.Finding:
15
focusGroup.SetActive(true);
16
focusFound.SetActive(false);
17
focusFinding.SetActive(true);
18
placeButtonGameObject.SetActive(false);
19
break;
20
case FindingType.Found:
21
focusGroup.SetActive(true);
22
focusFound.SetActive(true);
23
focusFinding.SetActive(false);
24
placeButtonGameObject.SetActive(true);
25
break;
26
case FindingType.Limit:
27
focusGroup.SetActive(false);
28
break;
29
}
30
31
worldPosition = _FocusResult.FocusPos;
32
worldRotation = _FocusResult.FocusRot;
33
34
//Move Focus Group
35
focusGroupTrans.position = worldPosition;
36
focusGroupTrans.rotation = worldRotation;
37
}
38
}
Copied!

BaseNotificationData

As its name suggests, it is the base class of all Notification Data.
Param
Type
Description
NotificationAct
Action
Callback
ActionName
String
Current notification name
BaseData
String
Additional data, generally not used

MarkerNotificationData

Subclass of BaseNotificationData. When using image tracking, the OnEvent function will receive this type of data.
TrackingState
Description
None
The image is not being tracked. Note that this may be the initial state when the image is first detected.
Limited
The image is being tracked, but not as effectively. The situations in which an image is considered Limited instead of Tracking depend on the underlying AR framework. Examples that could cause Limited tracking include:
  • Obscuring the image so that it is not visible to the camera.
  • The image is not tracked as a moving image. This can happen, for example, if the maxNumberOfMovingImages is exceeded.
Tracking
The underlying AR SDK reports that it is actively tracking the image.
Param
Type
Description
MarkerName
String
Current tracking or lost image's name
MarkerState
MarkerTrackingState
Current tracking state
BaseData
String
Additional data, generally not used
MarkerTrackable
Transform
To track the transform of the image, you can set the parent of our AR virtual object to it.

AnchorNotificationData

Subclass of BaseNotificationData. When you are call the StickObject method will be need pass this data to ARMOD SDK.
Param
Type
Description
StickType
StickTypeEnum
Interactor type
TrackableType
TrackableTypeEnum
You should set trackabletype when stick type is ByTackableTYpe
Position
Vector3
Anchor position(local position)
Rotation
Quaternion
Anchor rotation(local rotation)
Offset
Vector
Anchor offset position(local position)

ImmersalNotificationData

Subclass of BaseNotificationData. When using image tracking, the OnEvent function will receive this type of data.
Param
Type
Description
MapId
int
Current map id
LocalizerPose
LocalizerPose
You should set trackabletype when stick type is ByTackableTYpe

FaceMeshNotificationData

Subclass of BaseNotificationData. When using image tracking, the OnEvent function will receive this type of data.
Param
Type
Description
TrackingId
String
Current map id
FaceGameObject
GameObject
You should set trackabletype when stick type is ByTackableTYpe
FaceTrackingState
FaceTrackingState
Current face tracking state
vertices
NativeArray<Vector3>
face mesh vertices
indices
NativeArray<int>
face mesh indices
normals
NativeArray<Vector3>
face mesh normals
uvs
NaativeArray<Vector2>
face mesh uvs

OpenBuiltInNotificationData

Subclass of BaseNotificationData. When you are call the OpenBuiltInBrowser method will be need pass this data to ARMOD SDK.
Param
Type
Description
Url
String
URL of the webpage you want to open
Data
String
Additional data

FocusResultNotificationData

Subclass of BaseNotificationData. When using image tracking, the OnEvent function will receive this type of data.
Param
Type
Description
FocusPos
Vector3
Focus's position
FocusRot
Vector3
Focus's rotation
FocusState
FindingType
Current tracking status

ARAlgorithmNotificationData

Subclass of BaseNotificationData. When you are call the ChangeARAlgorithmLife method will be need pass this data to ARMOD SDK.
Param
Type
Description
ARAlgorithmType
ARAlgorithmType
AR algorithm type
ARAlgorithmOperator
ARAlgorithmOperator
AR life cycle operation types
Mixed
bool
Enable hybrid algorithm

TryAcquireAppInfoNotificationData

Subclass of BaseNotificationData. When you are call the TryAcquireAppInfo method will be need pass this data to ARMOD SDK.
Param
Type
Description
GetInfoType
String
Opcode to get app info

ReleaseARExperienceMemory

ReleaseARExperienceMemory method called when Exit AR. It is typically used to manage the objects created by calls to the Unity APIs.
C#
Example Code
1
public void ReleaseARExperienceMemory()
2
{
3
Destory(new GameObject("Unity API's Created"),5)
4
}
Copied!
Last modified 6mo ago