AR Target Description With Button PlaySound ScriptsCS
AR Target Description With Button PlaySound ScriptsCS
cs
/*==============================================================================
Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
All Rights Reserved.
Confidential and Proprietary - Protected under copyright and other laws.
==============================================================================*/
using UnityEngine;
using UnityEngine.UI;
namespace Vuforia
{
/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
/// </summary>
public class DefaultTrackableEventHandler : MonoBehaviour,
ITrackableEventHandler
{
public Transform TextTargetName;
public Transform ButtonAction;
public Transform TextDescription;
public Transform PanelDescription;
#region PRIVATE_MEMBER_VARIABLES
#endregion // PRIVATE_MEMBER_VARIABLES
#region UNTIY_MONOBEHAVIOUR_METHODS
void Start()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
#endregion // UNTIY_MONOBEHAVIOUR_METHODS
#region PUBLIC_METHODS
/// <summary>
/// Implementation of the ITrackableEventHandler function called when the
/// tracking state changes.
/// </summary>
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
OnTrackingFound();
}
else
{
OnTrackingLost();
}
}
#endregion // PUBLIC_METHODS
#region PRIVATE_METHODS
// Enable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = true;
}
// Enable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = true;
}
// Disable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = false;
}
// Disable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = false;
}
//Evertime the target lost / no target found it will show “???” on the
TextTargetName. Button, Description and Panel will invicible (inactive)
}
#endregion // PRIVATE_METHODS
}
}
targetData.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
namespace Vuforia
{
public class targetData : MonoBehaviour
{
Debug.Log("Active image target:" + name + " -size: " + size.x + ", "
+ size.y);
TextTargetName.GetComponent<Text>().text = name;
ButtonAction.gameObject.SetActive(true);
TextDescription.gameObject.SetActive(true);
PanelDescription.gameObject.SetActive(true);
//If the target name was “zombie” then add listener to ButtonAction
with location of the zombie sound (locate in Resources/sounds folder)
and set text on TextDescription a description of the zombie
if(name == "zombie"){
ButtonAction.GetComponent<Button>().onClick.AddListener(delegate {
playSound("sounds/ZombieLongDeath"); });
TextDescription.GetComponent<Text>().text = "A zombie (Haitian
French: zombi, Haitian Creole: zonbi) is a fictional undead being created through the
reanimation of a human corpse. Zombies are most commonly found in horror and fantasy
genre works.";
}
//If the target name was “unitychan” then add listener to ButtonAction
with location of the unitychan sound (locate in Resources/sounds
folder) and set text on TextDescription a description of the unitychan
/ robot
if (name == "unitychan")
{
ButtonAction.GetComponent<Button>().onClick.AddListener(delegate {
playSound("sounds/HelloBabyGirl"); });
TextDescription.GetComponent<Text>().text = "A robot is a
mechanical or virtual artificial agent, usually an electromechanical machine that is
guided by a computer program or electronic circuitry, and thus a type of an embedded
system.";
}
}
}