// Copyright (c) Microsoft Corporation. // Licensed under the MIT License using System; using System.Collections.Generic; using UnityEngine; namespace Microsoft.MixedReality.Toolkit.Experimental.StateVisualizer { /// /// The base class for state animatable properties. Based on the values defined in the animatable property, keyframes for a target game object are set in the animation clip linked to /// the animatable properties. /// [Serializable] public class StateAnimatableProperty : IStateAnimatableProperty { [SerializeField, HideInInspector] [Tooltip("The name of state animatable property.")] private string animatablePropertyName; /// /// The name of state animatable property. /// public string AnimatablePropertyName { get => animatablePropertyName; set => animatablePropertyName = value; } [SerializeField, HideInInspector] [Tooltip("The name of the interaction state associated with this state animatable property.")] private string stateName; /// /// The name of the interaction state associated with this state animatable property. /// public string StateName { get => stateName; set => stateName = value; } [SerializeField, HideInInspector] [Tooltip("The target game object to animate.")] private GameObject target; /// /// The target game object to animate. /// public GameObject Target { get => target; set => target = value; } [SerializeField] [Tooltip("The duration of the animation in seconds.")] private float animationDuration = 0.5f; /// /// The duration of the animation in seconds. /// public float AnimationDuration { get => animationDuration; set => animationDuration = value; } /// /// Sets the keyframes in an animation clip based on the values of the animatable properties. /// /// The animation clip to add keyframes to public virtual void SetKeyFrames(AnimationClip animationClip) { } /// /// Removes the keyframes in an animation clip. /// /// The animation clip for keyframe removal public virtual void RemoveKeyFrames(AnimationClip animationClip) { } // Find the path of the given target game object in its hierarchy protected string GetTargetPath(GameObject target) { List objectPath = new List(); Transform startTransform = target.transform; Transform initialTransform = target.transform; // If the current object is a root and does not have a parent if (startTransform.parent != null) { while (startTransform.parent != initialTransform) { if (startTransform.GetComponent() != null) { // Exit when we reach the root break; } objectPath.Add(startTransform.name); startTransform = startTransform.parent; } } string path = ""; for (int i = objectPath.Count - 1; i >= 0; i--) { path += objectPath[i]; if (i != 0) { path += "/"; } } return path; } } }