IValueProxy.cs
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/******************************************************************************
* Copyright (C) Leap Motion, Inc. 2011-2017. *
* Leap Motion proprietary and confidential. *
* *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
******************************************************************************/
using UnityEngine;
namespace Leap.Unity {
/// <summary>
/// A simple interface that allows an object to act as a 'proxy'
/// interface to another object. The proxy can store a serialized
/// representation of a value on another object. The value of
/// the proxy can either be updated from the object (pull), or
/// be pushed out to the object (push).
///
/// This interface is normally used in animation systems where
/// something that needs to be animated does not have an easily
/// animatable representation. The proxy stands in as the animatable
/// representation, while still allowing normal reads and writes.
/// </summary>
public interface IValueProxy {
/// <summary>
/// Called when this proxy should push its serialized representation
/// out to the target object.
/// </summary>
void OnPushValue();
/// <summary>
/// Called when this proxy should pull from the target object into
/// its serialized representation.
/// </summary>
void OnPullValue();
}
/// <summary>
/// A helpful implementation of IValueProxy. The class is a monobehaviour and so
/// can be attached to game objects. Auto-pushing can also be turned on and off.
/// When Auto-pushing is enabled, the behaviour will push the value on every
/// LateUpdate.
/// </summary>
public abstract class AutoValueProxy : MonoBehaviour, IValueProxy {
[SerializeField, HideInInspector]
private bool _autoPushingEnabled = false;
public bool autoPushingEnabled {
get {
return _autoPushingEnabled;
}
set {
_autoPushingEnabled = value;
}
}
public abstract void OnPullValue();
public abstract void OnPushValue();
private void LateUpdate() {
if (_autoPushingEnabled) {
OnPushValue();
}
}
}
}