ImageTargetBaseBehaviour Class

Inherits: TargetAbstractBehaviour

Description

ImageTargetBaseBehaviour is the component to control ImageTarget in the AR scene.

You should set ImageTargetBaseBehaviour 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 ImageTargetBaseBehaviour (let a tracker track the target inside the ImageTargetBaseBehaviour), you have to first setup the component with a target from image or json and then load the ImageTargetBaseBehaviour into a ImageTrackerBaseBehaviour.

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 ImageTargetBaseBehaviour into a ImageTrackerBehaviour after setup. There are also two methods.

  1. Bind an ImageTrackerBehaviour.

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

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

  2. call ImageTrackerBaseBehaviour.LoadImageTargetBehaviour from ImageTrackerBaseBehaviour.

    It has the same effect of calling Bind, but you have to setup the ImageTargetBaseBehaviour 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.

Public Fields

bool ActiveTargetOnStart
string Name
string Path
Vector2 Size
StorageType Storage
ImageTarget Target

Public Properties

List<ImageTrackerBaseBehaviour> Loaders

Public Functions

void Bind(ImageTrackerBaseBehaviour behaviour)
bool SetupWithImage(string path, StorageType storageType, string targetname, Vector2 size)
bool SetupWithJsonFile(string path, StorageType storageType, string targetname)
bool SetupWithJsonString(string json, StorageType storageType, string targetname)
bool SetupWithTarget(ImageTarget target)
static List<ImageTarget> LoadListFromJsonFile(string path, StorageType storageType)
static List<ImageTarget> LoadListFromJsonString(string json, StorageType storageType)

Public Events

event Action<ImageTargetBaseBehaviour, ImageTrackerBaseBehaviour, bool> TargetLoad
event Action<ImageTargetBaseBehaviour, ImageTrackerBaseBehaviour, 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.

Vector2 Size

The target size. The set operation should be called before MonoBehaviour.Start and only none-{0, 0} value will be used to initialize the target size 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.

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.

ImageTarget Target

The ImageTarget 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<ImageTrackerBaseBehaviour> Loaders

Current loaders (ImageTrackerBaseBehaviour) that loads this component.

void Bind(ImageTrackerBaseBehaviour behaviour)

Binds ImageTrackerBaseBehaviour.

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

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

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

bool SetupWithImage(string path, StorageType storageType, string targetname, Vector2 size)

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

Setup target of image from path with storageType, and set the target name to targetname and set the target size to size .

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 ImageTrackerBaseBehaviour 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 ImageTrackerBaseBehaviour 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 ImageTrackerBaseBehaviour before it can be tracked.

bool SetupWithTarget(ImageTarget target)

Setup the component with a cloud target.

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 ImageTrackerBaseBehaviour before it can be tracked.

static List<ImageTarget> LoadListFromJsonFile(string path, StorageType storageType)

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<ImageTarget> LoadListFromJsonString(string json, StorageType storageType)

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<ImageTargetBaseBehaviour, ImageTrackerBaseBehaviour, bool> TargetLoad

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

ImageTrackerBaseBehaviour.TargetLoad will be triggered at the same time.

event Action<ImageTargetBaseBehaviour, ImageTrackerBaseBehaviour, bool> TargetUnload

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

ImageTrackerBaseBehaviour.TargetUnload will be triggered at the same time.