Commit 29de0c28 authored by BlackAngle233's avatar BlackAngle233
Browse files

10.19 learned

parent 912976bb
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.Utilities
{
[Serializable]
public struct Vector3Smoothed
{
public Vector3 Current { get; set; }
public Vector3 Goal { get; set; }
public float SmoothTime { get; set; }
public Vector3Smoothed(Vector3 value, float smoothingTime) : this()
{
Current = value;
Goal = value;
SmoothTime = smoothingTime;
}
public void Update(float deltaTime)
{
Current = Vector3.Lerp(Current, Goal, (Math.Abs(SmoothTime) < Mathf.Epsilon) ? 1.0f : deltaTime / SmoothTime);
}
public void SetGoal(Vector3 newGoal)
{
Goal = newGoal;
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace Microsoft.MixedReality.Toolkit.Utilities
{
/// <summary>
/// todo
/// </summary>
public enum VolumeType
{
/// <summary>
/// No Specified type.
/// </summary>
None = 0,
/// <summary>
/// Cubic volume aligned with the coordinate axes.
/// </summary>
AxisAlignedCube,
/// <summary>
/// Cubic volume aligned with the user.
/// </summary>
UserAlignedCube,
/// <summary>
/// Spherical volume.
/// </summary>
Sphere
}
}
\ No newline at end of file
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Boundary
{
/// <summary>
/// The data describing the boundary system event.
/// </summary>
public class BoundaryEventData : GenericBaseEventData
{
/// <summary>
/// Is the floor being visualized by the boundary system.
/// </summary>
public bool IsFloorVisualized { get; private set; }
/// <summary>
/// Is the play area being visualized by the boundary system.
/// </summary>
public bool IsPlayAreaVisualized { get; private set; }
/// <summary>
/// Is the tracked area being visualized by the boundary system.
/// </summary>
public bool IsTrackedAreaVisualized { get; private set; }
/// <summary>
/// Are the boundary walls being visualized by the boundary system.
/// </summary>
public bool AreBoundaryWallsVisualized { get; private set; }
/// <summary>
/// Is the ceiling being visualized by the boundary system.
/// </summary>
/// <remarks>
/// The boundary system defines the ceiling as a plane set at <see cref="Microsoft.MixedReality.Toolkit.Boundary.IMixedRealityBoundarySystem.BoundaryHeight"/> above the floor.
/// </remarks>
public bool IsCeilingVisualized { get; private set; }
/// <summary>
/// Constructor.
/// </summary>
public BoundaryEventData(EventSystem eventSystem) : base(eventSystem) { }
public void Initialize(
IMixedRealityBoundarySystem boundarySystem,
bool isFloorVisualized,
bool isPlayAreaVisualized,
bool isTrackedAreaVisualized,
bool areBoundaryWallsVisualized,
bool isCeilingVisualized)
{
base.BaseInitialize(boundarySystem);
IsFloorVisualized = isFloorVisualized;
IsPlayAreaVisualized = isPlayAreaVisualized;
IsTrackedAreaVisualized = isTrackedAreaVisualized;
AreBoundaryWallsVisualized = areBoundaryWallsVisualized;
IsCeilingVisualized = isCeilingVisualized;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Diagnostics
{
public class DiagnosticsEventData : GenericBaseEventData
{
/// <summary>
/// Constructor
/// </summary>
public DiagnosticsEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Constructor
/// </summary>
/// <param name="diagnosticsSystem">The instance of the Diagnostic System that raised the event.</param>
public void Initialize(
IMixedRealityDiagnosticsSystem diagnosticsSystem)
{
BaseInitialize(diagnosticsSystem);
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using UnityEngine;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit
{
/// <summary>
/// Generic Base Event Data for Sending Events through the Event System.
/// </summary>
public class GenericBaseEventData : BaseEventData
{
/// <summary>
/// The Event Source that the event originates from.
/// </summary>
public IMixedRealityEventSource EventSource { get; private set; }
/// <summary>
/// The UTC time at which the event occurred.
/// </summary>
public DateTime EventTime { get; private set; }
/// <summary>
/// The BaseEventData.selectedObject is explicitly hidden because access to it
/// (either via get or set) throws a NullReferenceException in typical usage within
/// the MRTK. Prefer using the subclasses own fields to access information about
/// the event instead of fields on BaseEventData.
/// </summary>
/// <remarks>
/// BaseEventData is only used because it's part of Unity's EventSystem dispatching,
/// so this code must subclass it in order to leverage EventSystem.ExecuteEvents
/// </remarks>
public new GameObject selectedObject { get; protected set; }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="eventSystem">Usually <see href="https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem-current.html">EventSystems.EventSystem.current</see></param>
public GenericBaseEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
/// <param name="eventSource">The source of the event.</param>
protected void BaseInitialize(IMixedRealityEventSource eventSource)
{
Reset();
EventTime = DateTime.UtcNow;
EventSource = eventSource;
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
/// <summary>
/// Base class of all input events.
/// </summary>
public abstract class BaseInputEventData : BaseEventData
{
/// <summary>
/// The UTC time at which the event occurred.
/// </summary>
public DateTime EventTime { get; private set; }
/// <summary>
/// The source the input event originates from.
/// </summary>
public IMixedRealityInputSource InputSource { get; private set; }
/// <summary>
/// The id of the source the event is from, for instance the hand id.
/// </summary>
public uint SourceId => InputSource.SourceId;
/// <summary>
/// The input action for this event.
/// </summary>
public MixedRealityInputAction MixedRealityInputAction { get; private set; }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="eventSystem">Typically will be <see href="https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem-current.html">EventSystems.EventSystem.current</see></param>
protected BaseInputEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
protected void BaseInitialize(IMixedRealityInputSource inputSource, MixedRealityInputAction inputAction)
{
Reset();
EventTime = DateTime.UtcNow;
InputSource = inputSource;
MixedRealityInputAction = inputAction;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
/// <summary>
/// Describes an Input Event with voice dictation.
/// </summary>
public class DictationEventData : BaseInputEventData
{
/// <summary>
/// String result of the current dictation.
/// </summary>
public string DictationResult { get; private set; }
/// <summary>
/// Audio Clip of the last Dictation recording Session.
/// </summary>
public AudioClip DictationAudioClip { get; private set; }
/// <inheritdoc />
public DictationEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
public void Initialize(IMixedRealityInputSource inputSource, string dictationResult, AudioClip dictationAudioClip = null)
{
BaseInitialize(inputSource, MixedRealityInputAction.None);
DictationResult = dictationResult;
DictationAudioClip = dictationAudioClip;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
/// <summary>
/// Describes an Input Event associated with a specific pointer's focus state change.
/// </summary>
public class FocusEventData : BaseEventData
{
/// <summary>
/// The pointer associated with this event.
/// </summary>
public IMixedRealityPointer Pointer { get; private set; }
/// <summary>
/// The old focused object.
/// </summary>
public GameObject OldFocusedObject { get; private set; }
/// <summary>
/// The new focused object.
/// </summary>
public GameObject NewFocusedObject { get; private set; }
/// <inheritdoc />
public FocusEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
public void Initialize(IMixedRealityPointer pointer)
{
Reset();
Pointer = pointer;
}
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
public void Initialize(IMixedRealityPointer pointer, GameObject oldFocusedObject, GameObject newFocusedObject)
{
Reset();
Pointer = pointer;
OldFocusedObject = oldFocusedObject;
NewFocusedObject = newFocusedObject;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
public class HandTrackingInputEventData : InputEventData<Vector3>
{
/// <summary>
/// Constructor creates a default EventData object.
/// Requires initialization.
/// </summary>
public HandTrackingInputEventData(EventSystem eventSystem) : base(eventSystem) { }
public IMixedRealityController Controller { get; set; }
/// <summary>
/// This function is called to fill the HandTrackingIntputEventData object with information
/// </summary>
/// <param name="inputSource">Reference to the HandTrackingInputSource that created the EventData</param>
/// <param name="controller">Reference to the IMixedRealityController that created the EventData</param>
/// <param name="sourceHandedness">Handedness of the HandTrackingInputSource that created the EventData</param>
/// <param name="touchPoint">Global position of the HandTrackingInputSource that created the EventData</param>
public void Initialize(IMixedRealityInputSource inputSource, IMixedRealityController controller, Handedness sourceHandedness, Vector3 touchPoint)
{
Initialize(inputSource, sourceHandedness, MixedRealityInputAction.None, touchPoint);
Controller = controller;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
/// <summary>
/// Describes an Input Event that has a source id.
/// </summary>
public class InputEventData : BaseInputEventData
{
/// <summary>
/// Handedness of the <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputSource"/>.
/// </summary>
public Handedness Handedness { get; private set; } = Handedness.None;
/// <inheritdoc />
public InputEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
public void Initialize(IMixedRealityInputSource inputSource, Handedness handedness, MixedRealityInputAction inputAction)
{
BaseInitialize(inputSource, inputAction);
Handedness = handedness;
}
}
/// <summary>
/// Describes and input event with a specific type.
/// </summary>
/// <typeparam name="T"></typeparam>
public class InputEventData<T> : InputEventData
{
/// <summary>
/// The input data of the event.
/// </summary>
public T InputData { get; private set; }
/// <inheritdoc />
public InputEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
public void Initialize(IMixedRealityInputSource inputSource, Handedness handedness, MixedRealityInputAction inputAction, T data)
{
Initialize(inputSource, handedness, inputAction);
InputData = data;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
/// <summary>
/// Describes an Input Event that involves a tap, click, or touch.
/// </summary>
public class MixedRealityPointerEventData : InputEventData
{
/// <summary>
/// Pointer for the Input Event
/// </summary>
public IMixedRealityPointer Pointer { get; private set; }
/// <summary>
/// Number of Clicks, Taps, or Presses that triggered the event.
/// </summary>
public int Count { get; private set; }
/// <inheritdoc />
public MixedRealityPointerEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
public void Initialize(IMixedRealityPointer pointer, MixedRealityInputAction inputAction, Handedness handedness = Handedness.None, IMixedRealityInputSource inputSource = null, int count = 0)
{
if (inputSource != null)
{
Initialize(inputSource, handedness, inputAction);
}
else
{
Initialize(pointer.InputSourceParent, handedness, inputAction);
}
Pointer = pointer;
Count = count;
}
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
public void Initialize(IMixedRealityPointer pointer, Handedness handedness, MixedRealityInputAction inputAction, int count = 0)
{
Initialize(pointer.InputSourceParent, handedness, inputAction);
Pointer = pointer;
Count = count;
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
/// <summary>
/// Describes a source change event.
/// </summary>
/// <remarks>Source State events do not have an associated <see cref="MixedRealityInputAction"/>.</remarks>
public class SourcePoseEventData<T> : SourceStateEventData
{
/// <summary>
/// The new position of the input source.
/// </summary>
public T SourceData { get; private set; }
/// <inheritdoc />
public SourcePoseEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Populates the event with data.
/// </summary>
public void Initialize(IMixedRealityInputSource inputSource, IMixedRealityController controller, T data)
{
Initialize(inputSource, controller);
SourceData = data;
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
/// <summary>
/// Describes an source state event that has a source id.
/// </summary>
/// <remarks>Source State events do not have an associated <see cref="MixedRealityInputAction"/>.</remarks>
public class SourceStateEventData : BaseInputEventData
{
public IMixedRealityController Controller { get; private set; }
/// <inheritdoc />
public SourceStateEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Populates the event with data.
/// </summary>
public void Initialize(IMixedRealityInputSource inputSource, IMixedRealityController controller)
{
// NOTE: Source State events do not have an associated Input Action.
BaseInitialize(inputSource, MixedRealityInputAction.None);
Controller = controller;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Utilities;
using System;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Input
{
/// <summary>
/// Describes an input event that involves keyword recognition.
/// </summary>
public class SpeechEventData : BaseInputEventData
{
/// <summary>
/// The time it took for the phrase to be uttered.
/// </summary>
public TimeSpan PhraseDuration { get; private set; }
/// <summary>
/// The moment in UTC time when uttering of the phrase began.
/// </summary>
public DateTime PhraseStartTime { get; private set; }
/// <summary>
/// The text that was recognized.
/// </summary>
public SpeechCommands Command { get; private set; }
/// <summary>
/// A measure of correct recognition certainty.
/// </summary>
public RecognitionConfidenceLevel Confidence { get; private set; }
/// <inheritdoc />
public SpeechEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Populates the event with data.
/// </summary>
public void Initialize(IMixedRealityInputSource inputSource, RecognitionConfidenceLevel confidence, TimeSpan phraseDuration, DateTime phraseStartTime, SpeechCommands command)
{
BaseInitialize(inputSource, command.Action);
Confidence = confidence;
PhraseDuration = phraseDuration;
PhraseStartTime = phraseStartTime;
Command = command;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit
{
/// <summary>
/// Describes placement of objects events.
/// </summary>
public class PlacementEventData : GenericBaseEventData
{
/// <summary>
/// The game object that is being placed.
/// </summary>
public GameObject ObjectBeingPlaced { get; private set; }
/// <inheritdoc />
public PlacementEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Populates the event with data.
/// </summary>
public void Initialize(IMixedRealityEventSource eventSource, GameObject objectBeingPlaced)
{
BaseInitialize(eventSource);
ObjectBeingPlaced = objectBeingPlaced;
}
}
}
# Mixed Reality Toolkit - EventDatum
Data model classes for the inner workings of the Mixed Reality Toolkit and its supported Core systems.
All data models required for system use within the MRTK should be recorded here.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.SpatialAwareness
{
/// <summary>
/// Data for spatial awareness events.
/// </summary>
public class MixedRealitySpatialAwarenessEventData : GenericBaseEventData
{
/// <summary>
/// Identifier of the object associated with this event.
/// </summary>
public int Id { get; private set; }
/// <summary>
/// Constructor.
/// </summary>
public MixedRealitySpatialAwarenessEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Initialize the event data.
/// </summary>
/// <param name="observer">The <see cref="IMixedRealitySpatialAwarenessObserver"/> that raised the event.</param>
/// <param name="id">The identifier of the observed spatial object.</param>
public void Initialize(IMixedRealitySpatialAwarenessObserver observer, int id)
{
BaseInitialize(observer);
Id = id;
}
}
/// <summary>
/// Data for spatial awareness events.
/// </summary>
/// <typeparam name="T">The spatial object data type.</typeparam>
public class MixedRealitySpatialAwarenessEventData<T> : MixedRealitySpatialAwarenessEventData
{
/// <summary>
/// The spatial object to which this event pertains.
/// </summary>
public T SpatialObject { get; private set; }
/// <inheritdoc />
public MixedRealitySpatialAwarenessEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Initialize the event data.
/// </summary>
/// <param name="observer">The <see cref="IMixedRealitySpatialAwarenessObserver"/> that raised the event.</param>
/// <param name="id">The identifier of the observed spatial object.</param>
/// <param name="spatialObject">The observed spatial object.</param>
public void Initialize(IMixedRealitySpatialAwarenessObserver observer, int id, T spatialObject)
{
Initialize(observer, id);
SpatialObject = spatialObject;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine.EventSystems;
namespace Microsoft.MixedReality.Toolkit.Teleport
{
/// <summary>
/// Describes a Teleportation Event.
/// </summary>
public class TeleportEventData : GenericBaseEventData
{
/// <summary>
/// The pointer that raised the event.
/// </summary>
public IMixedRealityPointer Pointer { get; private set; }
/// <summary>
/// The teleport hot spot.
/// </summary>
public IMixedRealityTeleportHotSpot HotSpot { get; private set; }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="eventSystem">Typically will be <see href="https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem-current.html">EventSystem.current</see></param>
public TeleportEventData(EventSystem eventSystem) : base(eventSystem) { }
/// <summary>
/// Used to initialize/reset the event and populate the data.
/// </summary>
public void Initialize(IMixedRealityPointer pointer, IMixedRealityTeleportHotSpot target)
{
BaseInitialize(pointer.InputSourceParent);
Pointer = pointer;
HotSpot = target;
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit
{
/// <summary>
/// Extension methods for Unity's AnimationCurve class
/// </summary>
public static class AnimationCurveExtensions
{
/// <summary>
/// Returns the absolute duration of the curve from first to last key frame
/// </summary>
/// <param name="curve">The animation curve to check duration of.</param>
/// <returns>Returns 0 if the curve is null or has less than 1 frame, otherwise returns time difference between first and last frame.</returns>
public static float Duration(this AnimationCurve curve)
{
if (curve == null || curve.length <= 1)
{
return 0.0f;
}
return Mathf.Abs(curve[curve.length - 1].time - curve[0].time);
}
}
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
namespace Microsoft.MixedReality.Toolkit
{
/// <summary>
/// <see cref="System.Array"/> type method extensions.
/// </summary>
public static class ArrayExtensions
{
/// <summary>
/// Wraps the index around to the beginning of the array if the provided index is longer than the array.
/// </summary>
/// <param name="array">The array to wrap the index around.</param>
/// <param name="index">The index to look for.</param>
public static int WrapIndex(this Array array, int index)
{
int length = array.Length;
return ((index % length) + length) % length;
}
/// <summary>
/// Checks whether the given array is not null and has at least one entry
/// </summary>
public static bool IsValidArray(this Array array)
{
return array != null && array.Length > 0;
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment