Tanoda
PropertyRecorder.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.Collections.Generic;
11using UnityEngine;
12#if UNITY_EDITOR
13using UnityEditor;
14#endif
15using Leap.Unity.Query;
16
17namespace Leap.Unity.Recording {
18
19 [DisallowMultipleComponent]
20 public class PropertyRecorder : MonoBehaviour {
21
22 [Serializable]
23 public class BindingSet : SerializableHashSet<string> { }
24
25 [SerializeField]
26 protected List<string> _bindings = new List<string>();
27
28 [SerializeField]
29 protected List<string> _expandedTypes = new List<string>();
30
31#if UNITY_EDITOR
32 [NonSerialized]
33 protected List<EditorCurveBinding> _cachedBindings;
34 public List<EditorCurveBinding> GetBindings(GameObject root) {
35 if (_cachedBindings == null) {
36 _cachedBindings =
37 AnimationUtility.GetAnimatableBindings(gameObject, root).Query().
38 Where(IsBindingEnabled).
39 Where(b => b.type != typeof(Transform) &&
40 b.type != typeof(GameObject)).
41 ToList();
42 }
43
44 return _cachedBindings;
45 }
46
47 public bool IsBindingEnabled(EditorCurveBinding binding) {
48 return _bindings.Contains(getKey(binding));
49 }
50
51 public void SetBindingEnabled(EditorCurveBinding binding, bool enabled) {
52 var key = getKey(binding);
53 if (enabled == IsBindingEnabled(binding)) {
54 return;
55 }
56
57 if (enabled) {
58 _bindings.Add(key);
59 } else {
60 _bindings.Remove(key);
61 }
62 }
63
64 public bool IsBindingExpanded(EditorCurveBinding binding) {
65 return _expandedTypes.Contains(binding.type.Name);
66 }
67
68 public void SetBindingExpanded(EditorCurveBinding binding, bool expanded) {
69 if (expanded == IsBindingExpanded(binding)) {
70 return;
71 }
72
73 if (expanded) {
74 _expandedTypes.Add(binding.type.Name);
75 } else {
76 _expandedTypes.Remove(binding.type.Name);
77 }
78 }
79
80 private string getKey(EditorCurveBinding binding) {
81 return binding.type.Name + " : " + binding.propertyName;
82 }
83#endif
84 }
85}