By febndy
on Thu, 01/16/2014 - 16:32
Hi, I have some problem with cloud recognition. The model using this script used to be displayed just right, but suddenly it does not display anymore. The application can read a marker, and get the metadata, I have confirmed that by displaying the metadata in the UI text. but the object is not displayed. I used setActive(true) to make the selected object diplayed while the other object is set to setActive(false) at the begining of the script. is there something I miss?
using UnityEngine; using System.Collections; public class SimpleCREventHandler : MonoBehaviour, ICloudRecoEventHandler { #region PRIVATE_MEMBER_VARIABLES //CloudRecoBehaviour reference to avoid lookups private CloudRecoBehaviour mCloudRecoBehaviour; //ImageTracker reference to avoid lookups private ImageTracker mImageTracker; private GameObject pet; private bool isRendered = false; private string markerOwner = ""; private string[] userdata; #endregion // PRIVATE_MEMBER_VARIABLES #region EXPOSED_PUBLIC_VARIABLES public ImageTargetBehaviour ImageTargetTemplate; #endregion #region UNITY_MONOBEHAVIOUR_METHODS // Use this for initialization void Start () { //all pet setActive to false hideAllPets(); //register this event handler at the cloud reco behaviour CloudRecoBehaviour cloudRecoBehaviour = GetComponent<CloudRecoBehaviour>(); if(cloudRecoBehaviour) { cloudRecoBehaviour.RegisterEventHandler(this); } //remember cloudRecoBehaviour for later mCloudRecoBehaviour = cloudRecoBehaviour; } #endregion // UNITY_MONOBEHAVIOUR_METHODS #region ICloudRecoEventHandler_IMPLEMENTATION #region CloudRecognitionRequiredFunction public void OnInitialized() { //get a reference to the Image Tracker and remember it mImageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER); } public void OnInitError(TargetFinder.InitState initError) { } public void OnUpdateError(TargetFinder.UpdateState updateError) { } public void OnStateChanged(bool scanning) { //If still scanning object, hide all pet if(scanning) { hideAllPets(); } } #endregion //CloudRecognitionRequiredFunction private void OnTrackingFound() { } private void OnTrackingLost() { } public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult) { //duplicate the referenced image target GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject; GameObject augmentation = null; markerOwner = targetSearchResult.MetaData; PlayerPrefs.SetString("markerOwner",markerOwner); StartCoroutine(getPlayerData(PlayerPrefs.GetString("markerOwner"))); if(augmentation != null) { augmentation.transform.parent = newImageTarget.transform; } //enable the new result with the same ImageTargetBehaviour ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult,newImageTarget); imageTargetBehaviour.gameObject.transform.Find(PlayerPrefs.GetString("mPetType")).gameObject.SetActive(true); if (imageTargetBehaviour != null) { //stop the target finder mCloudRecoBehaviour.CloudRecoEnabled = false; } } #endregion ICloudRecoEventHandler_IMPLEMENTATION // Update is called once per frame void Update () { //enable back button to exit application if (Input.GetKeyDown ("escape")) { Application.LoadLevel(0); } } private void hideAllPets() { GameObject[] pets = GameObject.FindGameObjectsWithTag("pet"); foreach(GameObject element in pets) { element.SetActive(false); } } public bool isPetRendered() { //isRendered = true; return isRendered; } IEnumerator getPlayerData(string username) { PlayerPrefs.SetString("mPetName",""); PlayerPrefs.SetString("mPetType",""); PlayerPrefs.SetFloat("mPetSize",0); PlayerPrefs.SetFloat("mPetGrowth",0); PlayerPrefs.SetFloat("mPetHunger",0); WWWForm form = new WWWForm(); form.AddField("hash","babingengkang"); form.AddField("username",username); WWW result = new WWW("i got the url right", form); yield return result; if(result.error != null) { print(result.error); } else { string reply = result.text; userdata = reply.Split(";"[0]); PlayerPrefs.SetString("mPetName",userdata[0]); PlayerPrefs.SetString("mPetType",userdata[1]); PlayerPrefs.SetFloat("mPetSize",float.Parse(userdata[2])); PlayerPrefs.SetFloat("mPetGrowth",float.Parse(userdata[3])); PlayerPrefs.SetFloat("mPetHunger",float.Parse(userdata[4])); PlayerPrefs.Save(); isRendered = true; result.Dispose(); } } }
Model not Showing
Hi, I have some problem with cloud recognition. The model using this script used to be displayed just right, but suddenly it does not display anymore. The application can read a marker, and get the metadata, I have confirmed that by displaying the metadata in the UI text.
Model not Showing
but suddenly it does not display anymore
Normally this is a consequence of changing something.
I think the best thing is for you to step through the debugger in Play Mode and diagnose why it is not appearing.
N