Log in or register to post comments

Activate bool Animator when target detected

December 18, 2018 - 3:21am #1

Hi everyone !



I have a little problem, I have create a little Dialogue with this video :

 

https://www.youtube.com/watch?v=_nRzoTzeyxU

 

So now I would like to make appear my dialogue when my target is detected. Firstly I would like to put my "Culling mode" of my UI on "Cull Completely" but it's not working.

So Secondly my idea was to use a bool on my animator for control my animation. When my bool is activate so my animation is lunch. So I would like to activate my bool only when my tarder is detected but it's not working to. Here my code (Sorry if my english is bad, I am French (Yes, this is an easy excuse :p))

If someone can help me that will be great, thanks a lot !!

 

/*==============================================================================

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.

/// </summary>

public class EnableAnimation : MonoBehaviour, ITrackableEventHandler

{

#region PRIVATE_MEMBER_VARIABLES

protected TrackableBehaviour mTrackableBehaviour;

public Animator animator;

#endregion // PRIVATE_MEMBER_VARIABLES

#region UNTIY_MONOBEHAVIOUR_METHODS

protected virtual 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)

  {

   Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

   OnTrackingFound();

   animator.SetBool ("IsOpen", true);

  }

  else if (previousStatus == TrackableBehaviour.Status.TRACKED &&

   newStatus == TrackableBehaviour.Status.NOT_FOUND)

  {

   Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");

   OnTrackingLost();

   animator.SetBool ("IsOpen", true);

  }

  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();

   animator.SetBool ("IsOpen", false);

  }

}

#endregion // PUBLIC_METHODS

#region PRIVATE_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;

  //animator.SetBool ("IsOpen", false);

}

#endregion // PRIVATE_METHODS

}

Activate bool Animator when target detected

December 18, 2018 - 7:04am #2

So I find the answer, I just had to put the script on my Model Target and disactivate the Default Tracktable Event Handler script !

Log in or register to post comments