// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
namespace Microsoft.MixedReality.Toolkit.UI
{
///
/// list of Interactable states and basic comparison
///
public class InteractableStates : BaseStateModel
{
///
/// List of valid state types for Interactable
///
public enum InteractableStateEnum
{
///
/// Default state, nothing happening
///
Default = 0,
///
/// Looking at object
///
Focus,
///
/// Looking at object and finger down
///
Pressed,
///
/// Looking at and finger up
///
Targeted,
///
/// Not looking at it and finger is up
///
Interactive,
///
/// Looking at button finger down
///
ObservationTargeted,
///
/// Not looking at it and finger down
///
Observation,
///
/// Button in a disabled state
///
Disabled,
///
/// Button was clicked already
///
Visited,
///
/// Button is toggled state, on/off
///
Toggled,
///
/// Gesture is happening, Move
///
Gesture,
///
/// Gesture has reached its max movement
///
GestureMax,
///
/// There is a collision
///
Collision,
/// ///
/// Voice command happened
///
VoiceCommand,
///
/// Interactable is currently physically touched
///
PhysicalTouch,
///
/// Interactable was grabbed, near interaction grabbable
///
Grab,
///
/// Custom placeholder for anything
///
Custom
}
protected new State[] allStates = new State[17]
{
new State(){ Index = 0, Name = "Default", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 1, Name = "Focus", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 2, Name = "Pressed", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 3, Name = "Targeted", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 4, Name = "Interactive", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 5, Name = "ObservationTargeted", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 6, Name = "Observation", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 7, Name = "Disabled", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 8, Name = "Visited", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 9, Name = "Toggled", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 10, Name = "Gesture", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 11, Name = "GestureMax", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 12, Name = "Collision", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 13, Name = "VoiceCommand", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 14, Name = "PhysicalTouch", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 15, Name = "Grab", ActiveIndex = -1, Bit = 0, Value = 0},
new State(){ Index = 16, Name = "Custom", ActiveIndex = -1, Bit = 0, Value = 0}
};
public InteractableStates()
{
base.allStates = allStates;
SetCurrentState(allStates[0]);
}
public InteractableStates(State defaultState) : base(defaultState)
{
base.allStates = allStates;
}
///
public virtual void SetStateOn(InteractableStateEnum state)
{
SetStateOn((int)state);
}
///
public virtual void SetStateOff(InteractableStateEnum state)
{
SetStateOff((int)state);
}
///
public virtual void SetStateValue(InteractableStateEnum state, int value)
{
SetStateValue((int)state, value);
}
///
public State GetState(InteractableStateEnum state)
{
return GetState((int)state);
}
///
public override State CompareStates()
{
int bit = GetBit();
SetCurrentState(stateList[0]);
for (int i = stateList.Count - 1; i > -1; i--)
{
if (bit >= stateList[i].Bit)
{
SetCurrentState(stateList[i]);
break;
}
}
return CurrentState();
}
///
public override State[] GetStates()
{
return stateList.ToArray();
}
///
/// Returns the default states for InteractableStates.
/// Default states are set on an interactable when it is created and no other list of
/// states is specified.
/// Default States should match "DefaultStates" scriptable object in Interactable
///
public virtual List GetDefaultStates()
{
List result = new List();
result.Add(GetState(InteractableStateEnum.Default));
result.Add(GetState(InteractableStateEnum.Focus));
result.Add(GetState(InteractableStateEnum.Pressed));
result.Add(GetState(InteractableStateEnum.Disabled));
for (int i = 0; i < result.Count; i++)
{
result[i].Bit = 1 << i;
result[i].ActiveIndex = i;
}
return result;
}
}
}