Last active
August 17, 2018 07:22
-
-
Save Shubhra22/05b6de3a65b363192603b44527074c9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*============================================================================== | |
Copyright (c) 2017 PTC Inc. All Rights Reserved. | |
Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc. | |
All Rights Reserved. | |
Confidential and Proprietary - Protected under copyright and other laws. | |
==============================================================================*/ | |
using UnityEngine; | |
using Vuforia; | |
/// <summary> | |
/// A custom handler that implements the ITrackableEventHandler interface. | |
/// | |
/// Changes made to this file could be overwritten when upgrading the Vuforia version. | |
/// When implementing custom event handler behavior, consider inheriting from this class instead. | |
/// </summary> | |
public class DefaultTrackableEventHandler : MonoBehaviour, ITrackableEventHandler | |
{ | |
#region PROTECTED_MEMBER_VARIABLES | |
protected TrackableBehaviour mTrackableBehaviour; | |
[HideInInspector] | |
public bool didclick; | |
#endregion // PROTECTED_MEMBER_VARIABLES | |
#region UNITY_MONOBEHAVIOUR_METHODS | |
protected virtual void Start() | |
{ | |
mTrackableBehaviour = GetComponent<TrackableBehaviour>(); | |
if (mTrackableBehaviour) | |
mTrackableBehaviour.RegisterTrackableEventHandler(this); | |
} | |
protected virtual void OnDestroy() | |
{ | |
if (mTrackableBehaviour) | |
mTrackableBehaviour.UnregisterTrackableEventHandler(this); | |
} | |
#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) | |
{ | |
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found"); | |
OnTrackingFound(); | |
} | |
else if (previousStatus == TrackableBehaviour.Status.TRACKED && | |
newStatus == TrackableBehaviour.Status.NO_POSE) | |
{ | |
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost"); | |
OnTrackingLost(); | |
} | |
else | |
{ | |
// For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND | |
// Vuforia is starting, but tracking has not been lost or found yet | |
// Call OnTrackingLost() to hide the augmentations | |
OnTrackingLost(); | |
} | |
} | |
#endregion // PUBLIC_METHODS | |
#region PROTECTED_METHODS | |
protected virtual void OnTrackingFound() | |
{ | |
var rendererComponents = GetComponentsInChildren<Renderer>(true); | |
var colliderComponents = GetComponentsInChildren<Collider>(true); | |
var canvasComponents = GetComponentsInChildren<Canvas>(true); | |
// Enable rendering: | |
foreach (var component in rendererComponents) | |
component.enabled = true; | |
// Enable colliders: | |
foreach (var component in colliderComponents) | |
component.enabled = true; | |
// Enable canvas': | |
foreach (var component in canvasComponents) | |
component.enabled = true; | |
} | |
protected virtual void OnTrackingLost() | |
{ | |
var rendererComponents = GetComponentsInChildren<Renderer>(true); | |
var colliderComponents = GetComponentsInChildren<Collider>(true); | |
var canvasComponents = GetComponentsInChildren<Canvas>(true); | |
// Disable rendering: | |
foreach (var component in rendererComponents) | |
component.enabled = false; | |
// Disable colliders: | |
foreach (var component in colliderComponents) | |
component.enabled = false; | |
// Disable canvas': | |
foreach (var component in canvasComponents) | |
component.enabled = false; | |
} | |
public void HideorShowOnButtonPress(bool didPress) | |
{ | |
if(didPress) | |
{ | |
OnTrackingFound(); | |
} | |
else if(!didPress) | |
{ | |
OnTrackingLost(); | |
} | |
} | |
#endregion // PROTECTED_METHODS | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Vuforia; | |
public class UDTManager : MonoBehaviour, IUserDefinedTargetEventHandler | |
{ | |
UserDefinedTargetBuildingBehaviour udt_targetBuildingBehaviour; | |
ObjectTracker objectTracker; | |
DataSet dataSet; | |
ImageTargetBuilder.FrameQuality udt_FrameQuality; | |
public ImageTargetBehaviour targetBehaviour; | |
int targetCounter; | |
bool didPress; | |
void Start() | |
{ | |
udt_targetBuildingBehaviour = GetComponent<UserDefinedTargetBuildingBehaviour>(); // get UserDefinedTargetBuildingBehaviour from currrent game object. | |
if(udt_targetBuildingBehaviour) // UserDefinedTargetBuildingBehaviour has been found | |
{ | |
udt_targetBuildingBehaviour.RegisterEventHandler(this); | |
} | |
} | |
// This method updates the framequality | |
public void OnFrameQualityChanged(ImageTargetBuilder.FrameQuality frameQuality) | |
{ | |
udt_FrameQuality = frameQuality; | |
print(udt_FrameQuality); | |
//throw new System.NotImplementedException(); | |
} | |
public void OnInitialized() | |
{ | |
objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); | |
if(objectTracker!=null) // if objectTracker is not null | |
{ | |
dataSet = objectTracker.CreateDataSet(); // creating a new dataset | |
objectTracker.ActivateDataSet(dataSet); | |
} | |
} | |
public void OnNewTrackableSource(TrackableSource trackableSource) | |
{ | |
targetCounter++; | |
objectTracker.DeactivateDataSet(dataSet); | |
dataSet.CreateTrackable(trackableSource, targetBehaviour.gameObject); | |
objectTracker.ActivateDataSet(dataSet); | |
udt_targetBuildingBehaviour.StartScanning(); | |
//throw new System.NotImplementedException(); | |
} | |
public void BuildTarget() | |
{ | |
if(udt_FrameQuality == ImageTargetBuilder.FrameQuality.FRAME_QUALITY_HIGH) | |
{ | |
//print(targetBehaviour.GetComponent<DefaultTrackableEventHandler>().didclick); | |
didPress = !didPress; | |
targetBehaviour.GetComponent<DefaultTrackableEventHandler>().HideorShowOnButtonPress(didPress); | |
// I want to build a new target | |
udt_targetBuildingBehaviour.BuildNewTarget(targetCounter.ToString(),targetBehaviour.GetSize().x); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment