Tanoda
LeapSpaceAnchor.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using System;
11
12namespace Leap.Unity.Space {
13
14 [DisallowMultipleComponent]
15 public class LeapSpaceAnchor : MonoBehaviour {
16
17 [HideInInspector]
19
20 [HideInInspector]
22
24
25 protected virtual void OnEnable() { }
26
27 protected virtual void OnDisable() { }
28
30 if (this is LeapSpace) {
31 parent = this;
32 } else {
33 parent = GetAnchor(transform.parent);
34 }
35 }
36
37 public static LeapSpaceAnchor GetAnchor(Transform root) {
38 while (true) {
39 if (root == null) {
40 return null;
41 }
42
43 var anchor = root.GetComponent<LeapSpaceAnchor>();
44 if (anchor != null && anchor.enabled) {
45 return anchor;
46 }
47
48 root = root.parent;
49 }
50 }
51 }
52}
static LeapSpaceAnchor GetAnchor(Transform root)