Tanoda
CustomChannelDataBase.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 System;
10using UnityEngine;
11
13
14 public partial class LeapGraphic {
15
21 public T GetCustomChannel<T>(string channelName) where T : CustomChannelDataBase {
22 if (!isAttachedToGroup) {
23 throw new Exception("Cannot get a custom channel by name if the graphic is not attached to a group.");
24 }
25
26 int index = -1;
27 for (int i = 0; i < _featureData.Count; i++) {
28 var feature = _featureData[i].feature as ICustomChannelFeature;
29 if (feature == null) {
30 continue;
31 }
32
33 if (feature.channelName == channelName) {
34 index = i;
35 break;
36 }
37 }
38
39 if (index == -1) {
40 throw new Exception("No custom channel of the name " + channelName + " could be found.");
41 }
42
43 T featureDataObj = _featureData[index] as T;
44 if (featureDataObj == null) {
45 throw new Exception("The channel name " + channelName + " did not match to a custom channel of type " + typeof(T).Name + ".");
46 }
47
48 return featureDataObj;
49 }
50 }
51
52 public abstract class CustomChannelDataBase : LeapFeatureData { }
53
54 public abstract class CustomChannelDataBase<T> : CustomChannelDataBase {
55
56 [SerializeField]
57 private T _value;
58
59 public T value {
60 get {
61 return _value;
62 }
63 set {
64 if (!value.Equals(_value)) {
66 _value = value;
67 }
68 }
69 }
70 }
71}
bool isAttachedToGroup
Returns whether or not this graphic is attached to any group. Can still return false at runtime even ...
Definition: LeapGraphic.cs:162
T GetCustomChannel< T >(string channelName)
Helper method to get a custom channel data object given the name of the feature it is attached to....