Tanoda
AnchorGroup.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
10using System.Collections;
11using System.Collections.Generic;
12using UnityEngine;
13
14namespace Leap.Unity.Interaction {
15
16 [System.Serializable]
17 public class AnchorSet : SerializableHashSet<Anchor> { }
18
19 public class AnchorGroup : MonoBehaviour {
20
21 [SerializeField]
22 [Tooltip("The anchors that are within this AnchorGroup. Anchorable objects associated "
23 + "this AnchorGroup can only be placed in anchors within this group.")]
24 private AnchorSet _anchors = null;
25 public AnchorSet anchors { get { return _anchors; } }
26
27 private HashSet<AnchorableBehaviour> _anchorableObjects = new HashSet<AnchorableBehaviour>();
31 public HashSet<AnchorableBehaviour> anchorableObjects { get { return _anchorableObjects; } }
32
33 void Awake() {
34 foreach (var anchor in anchors) {
35 Add(anchor);
36 }
37 }
38
39 void OnDestroy() {
40 foreach (var anchor in anchors) {
41 anchor.groups.Remove(this);
42 }
43 }
44
45 public bool Contains(Anchor anchor) {
46 return _anchors.Contains(anchor);
47 }
48
49 public bool Add(Anchor anchor) {
50 if (_anchors.Add(anchor)) {
51 anchor.groups.Add(this);
52 return true;
53 }
54 else {
55 return false;
56 }
57 }
58
59 public bool Remove(Anchor anchor) {
60 if (_anchors.Remove(anchor)) {
61 anchor.groups.Remove(this);
62 return true;
63 }
64 else {
65 return false;
66 }
67 }
68
70 anchorableObjects.Add(anchObj);
71 }
72
74 anchorableObjects.Add(anchObj);
75 }
76
77 }
78
79}
void NotifyAnchorableObjectAdded(AnchorableBehaviour anchObj)
Definition: AnchorGroup.cs:69
void NotifyAnchorableObjectRemoved(AnchorableBehaviour anchObj)
Definition: AnchorGroup.cs:73
bool Contains(Anchor anchor)
Definition: AnchorGroup.cs:45
HashSet< AnchorableBehaviour > anchorableObjects
Gets the AnchorableBehaviours that are set to this AnchorGroup.
Definition: AnchorGroup.cs:31
HashSet< AnchorGroup > groups
Definition: Anchor.cs:42
AnchorableBehaviours mix well with InteractionBehaviours you'd like to be able to pick up and place i...