Tanoda
LeapGraphicFeature.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 System.Reflection;
11using System.Collections.Generic;
12using UnityEngine;
13using Leap.Unity.Query;
14
16
17 public abstract class LeapGraphicFeatureBase {
18
19 [NonSerialized]
20 private bool _isDirty = true; //everything defaults dirty at the start!
21
22 //Unity cannot serialize lists of objects that have no serializable fields
23 //when it is set to text-serialization. A feature might have no specific
24 //data, so we add this dummy bool to ensure it gets serialized anyway
25 [SerializeField]
26 private bool _dummyBool;
27
28 public bool isDirty {
29 get {
30 return _isDirty;
31 }
32 set {
33 _isDirty = value;
34 }
35 }
36
37 public bool isDirtyOrEditTime {
38 get {
39#if UNITY_EDITOR
40 if (!Application.isPlaying) {
41 return true;
42 } else
43#endif
44 {
45 return _isDirty;
46 }
47 }
48 }
49
51 return SupportInfo.FullSupport();
52 }
53
54 public abstract void AssignFeatureReferences();
55 public abstract void ClearDataObjectReferences();
56 public abstract void AddFeatureData(LeapFeatureData data);
57
58 public abstract Type GetDataObjectType();
60 }
61
62 public abstract class LeapGraphicFeature<DataType> : LeapGraphicFeatureBase
63 where DataType : LeapFeatureData, new() {
64
68 [NonSerialized]
69 public List<DataType> featureData = new List<DataType>();
70
71 public override void AssignFeatureReferences() {
72 foreach (var dataObj in featureData) {
73 dataObj.feature = this;
74 }
75 }
76
77 public override void ClearDataObjectReferences() {
78 featureData.Clear();
79 }
80
81 public override void AddFeatureData(LeapFeatureData data) {
82 this.featureData.Add(data as DataType);
83 }
84
85 public override Type GetDataObjectType() {
86 return typeof(DataType);
87 }
88
90 DataType data = new DataType();
91 data.graphic = graphic;
92 return data;
93 }
94 }
95
96 [Serializable]
97 public abstract class LeapFeatureData {
98 [NonSerialized]
100
101 [NonSerialized]
103
104 public void MarkFeatureDirty() {
105 if (feature != null) {
106 feature.isDirty = true;
107 }
108 }
109
110#if UNITY_EDITOR
111 public static Type GetFeatureType(Type dataObjType) {
112 var allTypes = Assembly.GetAssembly(dataObjType).GetTypes();
113 return allTypes.Query().
114 Where(t => t.IsSubclassOf(typeof(LeapGraphicFeatureBase)) &&
115 t != typeof(LeapGraphicFeatureBase) &&
116 !t.IsAbstract &&
117 t.BaseType.GetGenericArguments()[0] == dataObjType).
118 FirstOrDefault();
119 }
120#endif
121 }
122}
abstract void AddFeatureData(LeapFeatureData data)
abstract LeapFeatureData CreateFeatureDataForGraphic(LeapGraphic graphic)
virtual SupportInfo GetSupportInfo(LeapGraphicGroup group)
override LeapFeatureData CreateFeatureDataForGraphic(LeapGraphic graphic)
List< DataType > featureData
A list of all feature data.
override void AddFeatureData(LeapFeatureData data)
The support info class provides a very basic way to notify that something is fully supported,...
Definition: SupportInfo.cs:21
static SupportInfo FullSupport()
Helper getter to return a struct that signifies full support.
Definition: SupportInfo.cs:28