ObjectTargetBaseBehaviour Class

Inherits: TargetAbstractBehaviour

Description

ObjectTargetBaseBehaviour is the component to control ObjectTarget in the AR scene.

You should set ObjectTargetBaseBehaviour to be the parent of 3D contents that associate with the target. The transform between ARCamera and tracked Target is controlled by EasyAR.

To use ObjectTargetBaseBehaviour (let a tracker track the target inside the ObjectTargetBaseBehaviour), you have to first setup the component with a target from obj file or json and then load the ObjectTargetBaseBehaviour into a ObjectTrackerBaseBehaviour.

Generally there are two methods to setup the component. One is to set ActiveTargetOnStart to be true and setup fields (Name, Path, Size and Storage), a load operation will be called at MonoBehaviour.Start . The other method is call SetupWith* manually. You can also reload other targets at any time using SetupWith* methods.

You need to load the ObjectTargetBaseBehaviour into a ObjectTrackerBehaviour after setup. There are also two methods.

  1. Bind an ObjectTrackerBehaviour.

    When SetupWith* methods are called explicitly or implicitly (from MonoBehaviour.Start when ActiveTargetOnStart is true), the ObjectTargetBaseBehaviour will be automatically loaded into the bound ObjectTrackerBaseBehaviour.

    If SetupWith* methods have been called before Bind, the ObjectTargetBaseBehaviour will be loaded into the bound ObjectTrackerBaseBehaviour at the same time of calling Bind.

  2. call ObjectTrackerBaseBehaviour.LoadObjectTargetBehaviour from ObjectTrackerBaseBehaviour.

    It has the same effect of calling Bind, but you have to setup the ObjectTargetBaseBehaviour first using SetupWith* methods.

You will receive TargetAbstractBehaviour.TargetFound / TargetAbstractBehaviour.TargetLost and ARCameraBaseBehaviour.TargetFound / ARCameraBaseBehaviour.TargetLost events when a target is found or lost.

You can get a Frame from ARCameraBaseBehaviour.FrameUpdate event handlers. The Frame contains current camera image and tracked TargetInstance.

Rotation of object under the ObjectTarget should be set to,

X: 90
y: 180
z: 0
../_images/image842.png ../_images/image852.png ../_images/image862.png

Public Fields

bool ActiveTargetOnStart
string Name
string Path
float scale
StorageType Storage
ObjectTarget Target

Public Properties

List<ObjectTrackerBaseBehaviour> Loaders

Public Functions

void Bind(ObjectTrackerBaseBehaviour behaviour)
bool SetupWithObj(string path, StorageType storageType, string targetname, float scale)
bool SetupWithJsonFile(string path, StorageType storageType, string targetname)
bool SetupWithJsonString(string json, StorageType storageType, string targetname)
static List<ObjectTarget> LoadListFromJsonFile(string path, StorageType storageType) (since 2.1.0)
static List<ObjectTarget> LoadListFromJsonString(string json, StorageType storageType) (since 2.1.0)

Public Events

event Action<ObjectTargetBaseBehaviour, ObjectTrackerBaseBehaviour, bool> TargetLoad
event Action<ObjectTargetBaseBehaviour, ObjectTrackerBaseBehaviour, bool> TargetUnload

Overwritten MonoBahaviour Functions

protected virtual void Awake()
protected virtual void OnDestroy()
protected virtual void Start()
protected virtual void Update()

bool ActiveTargetOnStart

Whether to steup the target on a MonoBehaviour.Start call.

string Name

The target name. The set operation should be called before MonoBehaviour.Start if ActiveTargetOnStart is true. The value will be updated when a target is setuped and is loaded into a tracker, at the point of TargetLoad.

string Path

The target path. The set operation should be called before MonoBehaviour.Start if ActiveTargetOnStart is true. The value will be updated when a target is setuped and is loaded into a tracker, at the point of TargetLoad.

float scale

The target scale. The set operation should be called before MonoBehaviour.Start if ActiveTargetOnStart is true.

StorageType Storage

The target storage type. The set operation should be called before MonoBehaviour.Start if ActiveTargetOnStart is true. The value will be updated when a target is setuped and is loaded into a tracker, at the point of TargetLoad.

ObjectTarget Target

The ObjectTarget object. All values of the target will be updated when a target is setuped and is loaded into a tracker, at the point of TargetLoad.

List<ObjectTrackerBaseBehaviour> Loaders

Current loaders (ObjectTrackerBaseBehaviour) that loads this component.

void Bind(ObjectTrackerBaseBehaviour behaviour)

Binds ObjectTrackerBaseBehaviour.

If an ObjectTrackerBaseBehaviour is bind, ObjectTrackerBaseBehaviour.LoadObjectTargetBehaviour will be implicitly called when SetupWith* is called explicitly or implicitly (from MonoBehaviour.Start when ActiveTargetOnStart is true) to load the component into the ObjectTrackerBaseBehaviour.

If SetupWith* methods have been called before Bind, the ObjectTargetBaseBehaviour will be loaded into the bound ObjectTrackerBaseBehaviour at the same time of calling Bind.

Explicitly calling ObjectTrackerBaseBehaviour.LoadObjectTargetBehaviour after SetupWith* methods are called will make the same effect of calling Bind.

bool SetupWithObj(string path, StorageType storageType, string targetname, float scale)

Setup target using an obj file. This method only setup target properties, it will not load the target from storage.

Setup target of obj file from path with storageType, and set the target name to targetname and set the target scale to scale.

storageType should be StorageType.App or StorageType.Assets or StorageType.Absolute indicating the path type.

See StorageType for more descriptions of StorageType.

Target will be unload from its Loaders if it has been loaded into some trackers before setup. You need to reload this component into a ObjectTrackerBaseBehaviour before it can be tracked.

bool SetupWithJsonFile(string path, StorageType storageType, string targetname)

Setup target using json file. This method only setup target properties, it will not load the target from storage.

Setup target using the named target in json file if name is not empty, otherwise setup using the first target in json file.

StorageType should be StorageType.App or StorageType.Assets or StorageType.Absolute indicating the path type. Paths inside json files should be absolute path or relative path to the json file.

See StorageType for more descriptions of StorageType.

Target will be unload from its Loaders if it has been loaded into some trackers before setup. You need to reload this component into a ObjectTrackerBaseBehaviour before it can be tracked.

bool SetupWithJsonString(string json, StorageType storageType, string targetname)

Setup target using json string. This method only setup target properties, it will not load the target from storage.

Setup target using the named target in json string if name is not empty, otherwise setup using the first target in json string.

StorageType should be StorageType.App or StorageType.Assets or StorageType.Absolute indicating the path type. Paths inside json string should be absolute path or relative path to the storageType root.

See StorageType for more descriptions of StorageType.

Target will be unload from its Loaders if it has been loaded into some trackers before setup. You need to reload this component into a ObjectTrackerBaseBehaviour before it can be tracked.

static List<ObjectTarget> LoadListFromJsonFile(string path, StorageType storageType) (since 2.1.0)

Return a list of targets that are specified inside the json file from path with storageType. They will be setup using json file information before return.

See Load and StorageType for more descriptions of storageType and json file.

static List<ObjectTarget> LoadListFromJsonString(string json, StorageType storageType) (since 2.1.0)

Return a list of targets that are specified with json string. They will be setup using json string information before return.

See Load and StorageType for more descriptions of storageType and json file.

event Action<ObjectTargetBaseBehaviour, ObjectTrackerBaseBehaviour, bool> TargetLoad

Target load event. Will be triggered when target is loaded into a tracker.

ObjectTrackerBaseBehaviour.TargetLoad will be triggered at the same time.

event Action<ObjectTargetBaseBehaviour, ObjectTrackerBaseBehaviour, bool> TargetUnload

Target unload event. Will be triggered when target is unloaded from a tracker.

ObjectTrackerBaseBehaviour.TargetUnload will be triggered at the same time.