-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathTransformConstraint.cs
More file actions
138 lines (116 loc) · 4.61 KB
/
TransformConstraint.cs
File metadata and controls
138 lines (116 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) Mixed Reality Toolkit Contributors
// Licensed under the BSD 3-Clause
using Unity.XR.CoreUtils.GUI;
using UnityEngine;
namespace MixedReality.Toolkit.SpatialManipulation
{
/// <summary>
/// Base class for all constraints that be applied to <see cref="ObjectManipulator"/>
/// or <see cref="BoundsControl"/> components.
/// </summary>
/// <remarks>
/// The constraint system might be reworked in the future. In such a case, these existing components will be deprecated.
/// </remarks>
public abstract class TransformConstraint : MonoBehaviour
{
#region Properties
[SerializeField, FlagsProperty]
[Tooltip("What type of manipulation this constraint applies to. Defaults to One Handed and Two Handed.")]
private ManipulationHandFlags handType = ManipulationHandFlags.OneHanded | ManipulationHandFlags.TwoHanded;
/// <summary>
/// Whether this constraint applies to one hand manipulation, two hand manipulation or both
/// </summary>
public ManipulationHandFlags HandType
{
get => handType;
set => handType = value;
}
[SerializeField, FlagsProperty]
[Tooltip("What type of manipulation this constraint applies to. Defaults to Near and Far.")]
private ManipulationProximityFlags proximityType = ManipulationProximityFlags.Near | ManipulationProximityFlags.Far;
/// <summary>
/// Whether this constraint applies to near manipulation, far manipulation or both
/// </summary>
public ManipulationProximityFlags ProximityType
{
get => proximityType;
set => proximityType = value;
}
[SerializeField]
[Tooltip("Execution order priority of this constraint. Lower numbers will be executed before higher numbers.")]
private int executionOrder = 0;
/// <summary>
/// Execution order priority of this constraint. Lower numbers will be executed before higher numbers.
/// </summary>
public int ExecutionPriority
{
get => executionOrder;
set
{
executionOrder = value;
// Notify all ConstraintManagers to re-sort these priorities.
foreach (var mgr in gameObject.GetComponents<ConstraintManager>())
{
mgr.RefreshPriorities();
}
}
}
/// <summary>
/// The world pose of the object when the manipulation began.
/// </summary>
protected MixedRealityTransform WorldPoseOnManipulationStart;
/// <summary>
/// The initial world pose before any manipulations.
/// </summary>
protected MixedRealityTransform InitialWorldPose;
/// <summary>
/// Get flags that describe the type of transformations this constraint applies to.
/// </summary>
public abstract TransformFlags ConstraintType { get; }
#endregion Properties
#region Public Methods
/// <summary>
/// Called once before any constraints are computed.
/// </summary>
public virtual void Setup(MixedRealityTransform worldPose)
{
InitialWorldPose = worldPose;
}
/// <summary>
/// Called when manipulation starts on the attached object.
/// </summary>
public virtual void OnManipulationStarted(MixedRealityTransform worldPose)
{
WorldPoseOnManipulationStart = worldPose;
}
/// <summary>
/// Abstract method for applying constraints to transforms during manipulation
/// </summary>
public abstract void ApplyConstraint(ref MixedRealityTransform transform);
#endregion Public Methods
#region MonoBehaviour
/// <summary>
/// A Unity event function that is called when the script component has been enabled.
/// </summary>
protected void OnEnable()
{
var managers = gameObject.GetComponents<ConstraintManager>();
foreach (var manager in managers)
{
manager.AutoRegisterConstraint(this);
}
}
/// <summary>
/// A Unity event function that is called when the script component has been disabled.
/// </summary>
protected void OnDisable()
{
var managers = gameObject.GetComponents<ConstraintManager>();
foreach (var manager in managers)
{
manager.AutoUnregisterConstraint(this);
}
}
#endregion
}
}