// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.UI
{
///
/// ThemeEngine that controls Animator state based on state changes
/// Targets first Animator component returned on initialized GameObject
///
public class InteractableAnimatorTheme : InteractableThemeBase
{
private int lastIndex = -1;
private Animator controller;
public InteractableAnimatorTheme()
{
Types = new Type[] { typeof(Transform) };
Name = "AnimatorTheme";
}
///
public override ThemeDefinition GetDefaultThemeDefinition()
{
return new ThemeDefinition()
{
ThemeType = GetType(),
StateProperties = new List()
{
new ThemeStateProperty()
{
Name = "Animator Trigger",
Type = ThemePropertyTypes.AnimatorTrigger,
Values = new List(),
Default = new ThemePropertyValue() { String = "Default" }
},
},
CustomProperties = new List(),
};
}
///
public override void Init(GameObject host, ThemeDefinition settings)
{
controller = host.GetComponent();
base.Init(host, settings);
}
///
public override ThemePropertyValue GetProperty(ThemeStateProperty property)
{
ThemePropertyValue start = new ThemePropertyValue();
start.String = lastIndex != -1 ? property.Values[lastIndex].String : string.Empty;
return start;
}
///
public override void SetValue(ThemeStateProperty property, int index, float percentage)
{
if (lastIndex != index)
{
SetValue(property, property.Values[index]);
lastIndex = index;
}
}
///
protected override void SetValue(ThemeStateProperty property, ThemePropertyValue value)
{
if (controller != null && !string.IsNullOrEmpty(value.String))
{
controller.SetTrigger(value.String);
}
}
}
}