11using System.Collections;
12using System.Collections.Generic;
35 return _attachmentPoints;
38 if (_attachmentPoints != value) {
40 Undo.IncrementCurrentGroup();
41 Undo.SetCurrentGroupName(
"Modify Attachment Points");
43 Undo.RecordObject(
this,
"Modify AttachmentHands Points");
46 _attachmentPoints = value;
47 refreshAttachmentHandTransforms();
52 private Func<Hand>[] _handAccessors;
62 public Func<Hand>[]
handAccessors {
get {
return _handAccessors; }
set { _handAccessors = value; } }
77 if (getIsPrefab())
return;
85 if (getIsPrefab())
return;
91 private void reinitialize() {
92 refreshHandAccessors();
93 refreshAttachmentHands();
96 EditorApplication.delayCall += refreshAttachmentHandTransforms;
98 refreshAttachmentHandTransforms();
104 if (Utils.IsObjectPartOfPrefabAsset(
this.gameObject)) {
109 bool requiresReinitialization =
false;
111 using (
new ProfilerSample(
"Attachment Hands Update", this.gameObject)) {
112 for (
int i = 0; i < _attachmentHands.Length; i++) {
115 if (attachmentHand ==
null) {
116 requiresReinitialization =
true;
121 attachmentHand.isTracked = leapHand !=
null;
123 using (
new ProfilerSample(attachmentHand.gameObject.name +
" Update Points")) {
124 foreach (var point
in attachmentHand.points) {
125 point.SetTransformUsingHand(leapHand);
130 if (requiresReinitialization) {
136 private void refreshHandAccessors() {
138 if (_handAccessors ==
null || _handAccessors.Length == 0) {
139 _handAccessors =
new Func<Hand>[2];
141 _handAccessors[0] =
new Func<Hand>(() => {
return Hands.Left; });
142 _handAccessors[1] =
new Func<Hand>(() => {
return Hands.Right; });
146 private void refreshAttachmentHands() {
148 bool isPrefab =
false;
150 isPrefab = getIsPrefab();
154 if (_attachmentHands ==
null || _attachmentHands.Length == 0 || (_attachmentHands[0] ==
null || _attachmentHands[1] ==
null)) {
155 _attachmentHands =
new AttachmentHand[2];
158 foreach (Transform child
in this.transform.GetChildren()) {
159 var attachmentHand = child.GetComponent<AttachmentHand>();
160 if (attachmentHand !=
null) {
161 _attachmentHands[attachmentHand.chirality ==
Chirality.Left ? 0 : 1] = attachmentHand;
168 if (isPrefab && (_attachmentHands[0] ==
null || _attachmentHands[0].transform.parent !=
this.transform
169 || _attachmentHands[1] ==
null || _attachmentHands[1].transform.parent !=
this.transform)) {
174 if (_attachmentHands[0] ==
null) {
175 GameObject obj =
new GameObject();
177 Undo.RegisterCreatedObjectUndo(obj,
"Created GameObject");
179 _attachmentHands[0] = obj.AddComponent<AttachmentHand>();
182 _attachmentHands[0].gameObject.name =
"Attachment Hand (Left)";
183 if (_attachmentHands[0].transform.parent !=
this.transform) _attachmentHands[0].transform.parent = this.transform;
185 if (_attachmentHands[1] ==
null) {
186 GameObject obj =
new GameObject();
188 Undo.RegisterCreatedObjectUndo(obj,
"Created GameObject");
190 _attachmentHands[1] = obj.AddComponent<AttachmentHand>();
193 _attachmentHands[1].gameObject.name =
"Attachment Hand (Right)";
194 if (_attachmentHands[1].transform.parent !=
this.transform) _attachmentHands[1].transform.parent = this.transform;
197 _attachmentHands[0].transform.SetSiblingIndex(0);
198 _attachmentHands[1].transform.SetSiblingIndex(1);
202 private void refreshAttachmentHandTransforms() {
203 if (
this ==
null)
return;
206 if (getIsPrefab())
return;
209 bool requiresReinitialization =
false;
211 if (_attachmentHands ==
null) {
212 requiresReinitialization =
true;
215 foreach (var hand
in _attachmentHands) {
218 requiresReinitialization =
true;
226 EditorUtility.SetDirty(
this);
230 if (requiresReinitialization) {
236 private bool getIsPrefab() {
237 return Utils.IsObjectPartOfPrefabAsset(this.gameObject);
This MonoBehaviour is managed by an AttachmentHands component on a parent MonoBehaviour....
void refreshAttachmentTransforms(AttachmentPointFlags points)
Chirality chirality
Gets the chirality of this AttachmentHand. This is set automatically by the AttachmentHands parent ob...
Add an GameObject with this script to your scene if you would like to have a Transform hierarchy that...
AttachmentHand[] attachmentHands
Gets or sets the array of AttachmentHand objects that this component manages. The length of this arra...
Func< Hand >[] handAccessors
Gets or sets the functions used to get the latest Leap.Hand data for the corresponding AttachmentHand...
AttachmentPointFlags attachmentPoints
AttachmentPointFlags
Flags for attachment points on the hand.