TextRecoBehaviour.cs TrackableEventHandler.cs

170 Resources.UnloadAssetmPotraitTextureIPhone; Resources.UnloadAssetmPotraitTextureIPhone5; Resources.UnloadAssetmPotraitTextureIPad; } public void UpdateUI bool tf { if tf return ; if QCARRuntimeUtilities.IsPlayMode { GUI.DrawTexture new Rect0, 0, Screen.width, Screen.height, mWindowsPlayModeTexture; } else { if UNITY_IPHONE if iPhone.generation == iPhoneGeneration.iPhone5 { GUI.DrawTexturenew Rect0, 0, Screen.width, Screen.height, mPotraitTextureIPhone5; } else if iPhone.generation == iPhoneGeneration.iPhone { GUI.DrawTexturenew Rect0, 0, Screen.width, Screen.height, mPotraitTextureIPhone, ScaleMode.ScaleAndCrop; } else { GUI.DrawTexturenew Rect0, 0, Screen.width, Screen.height, mPotraitTextureIPad, ScaleMode.ScaleAndCrop; } else GUI.DrawTexture new Rect0, 0, Screen.width, Screen.height, mAndroidPotrait, ScaleMode.ScaleAndCrop; endif } } endregion ISampleAppUIView implementation }

35. TextRecoBehaviour.cs

using System.Collections.Generic; using System.Linq; using UnityEngine; public class TextRecoBehaviour : TextRecoAbstractBehaviour { } 171

36. TrackableEventHandler.cs

using UnityEngine; public class TrackableEventHandler : MonoBehaviour, ITrackableEventHandler { region PRIVATE_MEMBER_VARIABLES private TrackableBehaviour mTrackableBehaviour; private bool mHasBeenFound = false ; private bool mLostTracking; private float mSecondsSinceLost; endregion PRIVATE_MEMBER_VARIABLES region UNITY_MONOBEHAVIOUR_METHODS void Start { mTrackableBehaviour = GetComponentTrackableBehaviour; if mTrackableBehaviour { mTrackableBehaviour.RegisterTrackableEventHandler this ; } OnTrackingLost; } void Update { Pause the video if tracking is lost for more than two seconds if mHasBeenFound mLostTracking { if mSecondsSinceLost 2.0f { VideoPlaybackBehaviour video = GetComponentInChildrenVideoPlaybackBehaviour; if video = null video.CurrentState == VideoPlayerHelper.MediaState.PLAYING { video.VideoPlayer.Pause; } mLostTracking = false ; } mSecondsSinceLost += Time.deltaTime; } } 172 endregion UNITY_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 private void OnTrackingFound { Renderer[] rendererComponents = GetComponentsInChildrenRenderer; Collider[] colliderComponents = GetComponentsInChildrenCollider; Enable rendering: foreach Renderer component in rendererComponents { component.enabled = true ; } Enable colliders: foreach Collider component in colliderComponents { component.enabled = true ; } 173 Debug.Log Trackable + mTrackableBehaviour.TrackableName + found ; Optionally play the video automatically when the target is found VideoPlaybackBehaviour video = GetComponentInChildrenVideoPlaybackBehaviour; if video = null video.AutoPlay { if video.VideoPlayer.IsPlayableOnTexture { VideoPlayerHelper.MediaState state = video.VideoPlayer.GetStatus; if state == VideoPlayerHelper.MediaState.PAUSED || state == VideoPlayerHelper.MediaState.READY || state == VideoPlayerHelper.MediaState.STOPPED { Pause other videos before playing this one PauseOtherVideosvideo; Play this video on texture where it left off video.VideoPlayer.Play false , video.VideoPlayer.GetCurrentPosition; } else if state == VideoPlayerHelper.MediaState.REACHED_END { Pause other videos before playing this one PauseOtherVideosvideo; Play this video from the beginning video.VideoPlayer.Play false , 0; } } } mHasBeenFound = true ; mLostTracking = false ; } private void OnTrackingLost { Renderer[] rendererComponents = GetComponentsInChildrenRenderer; Collider[] colliderComponents = GetComponentsInChildrenCollider; Disable rendering: 174 foreach Renderer component in rendererComponents { component.enabled = false ; } Disable colliders: foreach Collider component in colliderComponents { component.enabled = false ; } Debug.Log Trackable + mTrackableBehaviour.TrackableName + lost ; mLostTracking = true ; mSecondsSinceLost = 0; } Pause all videos except this one private void PauseOtherVideosVideoPlaybackBehaviour currentVideo { VideoPlaybackBehaviour[] videos = VideoPlaybackBehaviour[] FindObjectsOfType typeof VideoPlaybackBehaviour; foreach VideoPlaybackBehaviour video in videos { if video = currentVideo { if video.CurrentState == VideoPlayerHelper.MediaState.PLAYING { video.VideoPlayer.Pause; } } } } endregion PRIVATE_METHODS }

37. TurnOffBehaviour.cs