Help us to improve our training by participating in this Questionnaire. Thank you for your time.
Download Unity. Please check your computer type Mac / Windows (32-bit or 64-bit).
Vuforia is an Augmented Reality engine, that come bundle with Unity if selected on installation.
You need to install JDK (Java Development Kit) and SDK(Software Development Kit) on your computer to build an APK to run on your Android device.
1: To install JDK, please go to this website. You have to choose based on your computer operating system. Make sure to tick for licence agreement to be able to install. Please choose version (8u172).
2: To install SDK, please download and install Android Studio from this link.
After installed JDK and SDK, you need to specify the path in the Unity. While Unity app is running, open Unity Preferences, choose ‘External Tools’, scroll down until you find Android section as figure below.
Reference Android environment setup from Unity
This only available for Mac computer only. What you have to do is to install Xcode into your Mac from Mac App Store.
Create C# Script name it as ‘VideoController’ will create a VideoController.cs file. Double click on the file to add the code.
// file: VideoController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
using Vuforia;
public class VideoController : MonoBehaviour, ITrackableEventHandler
{
public VideoPlayer VideoCube;
public AudioSource VideoAudio;
private TrackableBehaviour mTrackableBehaviour;
// Use this for initialization
void Start ()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
// Update is called once per frame
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 ();
}
}
private void OnTrackingFound()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
// Enable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = true;
}
// Enable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = true;
}
VideoCube.Play ();
VideoAudio.Play ();
Debug.Log(mTrackableBehaviour.TrackableName + " found");
}
private void OnTrackingLost()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
// Disable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = false;
}
// Disable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = false;
}
VideoCube.Pause ();
VideoAudio.Pause ();
Debug.Log(mTrackableBehaviour.TrackableName + " lost");
}
}
// File: GameController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
using Vuforia;
public class GameController : MonoBehaviour, ITrackableEventHandler {
public Text myText;
public GameObject buttonA;
private int currentPage;
public GameObject eggs;
public GameObject tadpole;
public GameObject froglet;
public GameObject adult;
private TrackableBehaviour mTrackableBehaviour;
string [] sarray={
"Hello, welcome to Frog Lifecycle app. Please find a marker to proceed. ",
"1. Frog eggs floating in a pond: these clusters of floating eggs are called egg masses.",
"2. Tadpoles hatch from the eggs and live in the pond.",
"3. The tadpoles turn into Froglets. The body shrinks and legs form.",
"4. The Froglet's tail shrinks, the lungs develop and the back legs grow and then we have a Frog." };
// Use this for initialization
void Start () {
currentPage = 0;
myText.text = sarray[currentPage];
buttonA.SetActive(false);
eggs.SetActive(true);
tadpole.SetActive(false);
froglet.SetActive(false);
adult.SetActive(false);
// SET MARKER TRACKABLE
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
// Update is called once per frame
void Update () {
}
// BUTTON
public void onNextPressed(){
if (currentPage >= 4 ) {
currentPage = -1;
}
currentPage = currentPage + 1;
myText.text = sarray[currentPage];
if (currentPage == 0) {
eggs.SetActive(true);
tadpole.SetActive(false);
froglet.SetActive(false);
adult.SetActive(false);
} else if (currentPage == 1){
eggs.SetActive(true);
tadpole.SetActive(false);
froglet.SetActive(false);
adult.SetActive(false);
} else if (currentPage == 2){
eggs.SetActive(true);
tadpole.SetActive(true);
froglet.SetActive(false);
adult.SetActive(false);
} else if (currentPage == 3){
eggs.SetActive(true);
tadpole.SetActive(true);
froglet.SetActive(true);
adult.SetActive(false);
} else if (currentPage == 4){
eggs.SetActive(true);
tadpole.SetActive(true);
froglet.SetActive(true);
adult.SetActive(true);
} else if (currentPage == 5){
eggs.SetActive(true);
tadpole.SetActive(true);
froglet.SetActive(true);
adult.SetActive(true);
}
}
// TRACKABLE
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 ();
}
}
private void OnTrackingFound(){
Debug.Log("" + mTrackableBehaviour.TrackableName + " found");
Debug.Log("on Next FrogLifecycle");
buttonA.SetActive(true);
if ( mTrackableBehaviour.TrackableName == "FrogLifecycle" ) {
Debug.Log("on Next FrogLifecycle");
if (currentPage == 0){
Debug.Log("on Next pressed");
this.onNextPressed();
}
}
}
private void OnTrackingLost(){
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
buttonA.SetActive(false);
}
}