Skip to content

Commit 098b3f4

Browse files
committed
added some utils
1 parent 75534ee commit 098b3f4

6 files changed

+166
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Signals For Unity3D
1+
# Signals For Unity3D v1.0.0
22
## Documentation
3-
You can find the API documentation [here](https://jheiling.github.io/unity-signals/) or in the docs folder.
3+
You can find the API documentation [here](https://jheiling.github.io/unity-signals/).
44
## What Are Signals?
55
A Signal is a [ScriptableObject](https://docs.unity3d.com/ScriptReference/ScriptableObject.html) which holds a value and triggers a [UnityEvent](https://docs.unity3d.com/ScriptReference/Events.UnityEvent_1.html) when a new value is assigned.
66
## Why Should I Use Them?

Utils/EulerAnglesTracker.cs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using UnityEngine;
2+
using Signals.Common;
3+
4+
5+
6+
namespace Signals.Utils
7+
{
8+
/// <summary>
9+
/// Tracks the rotation of a GameObject in euler angles.
10+
/// </summary>
11+
[AddComponentMenu("Signals/Utils/EulerAnglesTracker")]
12+
public class EulerAnglesTracker : MonoBehaviour
13+
{
14+
[SerializeField] Vector3Signal _signal;
15+
[SerializeField] bool _local;
16+
Transform _transform;
17+
18+
/// <summary>
19+
/// The signal that keeps track of the rotation.
20+
/// </summary>
21+
public Vector3Signal Signal
22+
{
23+
get
24+
{
25+
return _signal;
26+
}
27+
28+
set
29+
{
30+
_signal = value;
31+
}
32+
}
33+
34+
/// <summary>
35+
/// True to track local instead of global rotation.
36+
/// </summary>
37+
public bool Local
38+
{
39+
get
40+
{
41+
return _local;
42+
}
43+
44+
set
45+
{
46+
_local = value;
47+
}
48+
}
49+
50+
void Start()
51+
{
52+
_transform = transform;
53+
}
54+
55+
void Update()
56+
{
57+
if(_signal) _signal.Value = _local ? _transform.localEulerAngles : _transform.eulerAngles;
58+
}
59+
}
60+
}

Utils/EulerAnglesTracker.cs.meta

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Utils/PositionTracker.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Signals.Utils
1313
public class PositionTracker : MonoBehaviour
1414
{
1515
[SerializeField] Vector3Signal _signal;
16+
[SerializeField] bool _local;
1617
Transform _transform;
1718

1819
/// <summary>
@@ -31,14 +32,30 @@ public Vector3Signal Signal
3132
}
3233
}
3334

35+
/// <summary>
36+
/// True to track local instead of global position.
37+
/// </summary>
38+
public bool Local
39+
{
40+
get
41+
{
42+
return _local;
43+
}
44+
45+
set
46+
{
47+
_local = value;
48+
}
49+
}
50+
3451
void Start()
3552
{
3653
_transform = transform;
3754
}
3855

3956
void Update()
4057
{
41-
if(_signal) _signal.Value = _transform.position;
58+
if(_signal) _signal.Value = _local ? _transform.localPosition : _transform.position;
4259
}
4360
}
4461
}

Utils/RotationTracker.cs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using UnityEngine;
2+
using Signals.Common;
3+
4+
5+
6+
namespace Signals.Utils
7+
{
8+
/// <summary>
9+
/// Tracks the rotation of a GameObject.
10+
/// </summary>
11+
[AddComponentMenu("Signals/Utils/RotationTracker")]
12+
public class RotationTracker : MonoBehaviour
13+
{
14+
[SerializeField] QuaternionSignal _signal;
15+
[SerializeField] bool _local;
16+
Transform _transform;
17+
18+
/// <summary>
19+
/// The signal that keeps track of the rotation.
20+
/// </summary>
21+
public QuaternionSignal Signal
22+
{
23+
get
24+
{
25+
return _signal;
26+
}
27+
28+
set
29+
{
30+
_signal = value;
31+
}
32+
}
33+
34+
/// <summary>
35+
/// True to track local instead of global rotation.
36+
/// </summary>
37+
public bool Local
38+
{
39+
get
40+
{
41+
return _local;
42+
}
43+
44+
set
45+
{
46+
_local = value;
47+
}
48+
}
49+
50+
void Start()
51+
{
52+
_transform = transform;
53+
}
54+
55+
void Update()
56+
{
57+
if(_signal) _signal.Value = _local ? _transform.localRotation : _transform.rotation;
58+
}
59+
}
60+
}

Utils/RotationTracker.cs.meta

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)