Skip to content

Commit

Permalink
added some utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jheiling committed Feb 8, 2018
1 parent 75534ee commit 098b3f4
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Signals For Unity3D
# Signals For Unity3D v1.0.0
## Documentation
You can find the API documentation [here](https://jheiling.github.io/unity-signals/) or in the docs folder.
You can find the API documentation [here](https://jheiling.github.io/unity-signals/).
## What Are Signals?
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.
## Why Should I Use Them?
Expand Down
60 changes: 60 additions & 0 deletions Utils/EulerAnglesTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using UnityEngine;
using Signals.Common;



namespace Signals.Utils
{
/// <summary>
/// Tracks the rotation of a GameObject in euler angles.
/// </summary>
[AddComponentMenu("Signals/Utils/EulerAnglesTracker")]
public class EulerAnglesTracker : MonoBehaviour
{
[SerializeField] Vector3Signal _signal;
[SerializeField] bool _local;
Transform _transform;

/// <summary>
/// The signal that keeps track of the rotation.
/// </summary>
public Vector3Signal Signal
{
get
{
return _signal;
}

set
{
_signal = value;
}
}

/// <summary>
/// True to track local instead of global rotation.
/// </summary>
public bool Local
{
get
{
return _local;
}

set
{
_local = value;
}
}

void Start()
{
_transform = transform;
}

void Update()
{
if(_signal) _signal.Value = _local ? _transform.localEulerAngles : _transform.eulerAngles;
}
}
}
13 changes: 13 additions & 0 deletions Utils/EulerAnglesTracker.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion Utils/PositionTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Signals.Utils
public class PositionTracker : MonoBehaviour
{
[SerializeField] Vector3Signal _signal;
[SerializeField] bool _local;
Transform _transform;

/// <summary>
Expand All @@ -31,14 +32,30 @@ public Vector3Signal Signal
}
}

/// <summary>
/// True to track local instead of global position.
/// </summary>
public bool Local
{
get
{
return _local;
}

set
{
_local = value;
}
}

void Start()
{
_transform = transform;
}

void Update()
{
if(_signal) _signal.Value = _transform.position;
if(_signal) _signal.Value = _local ? _transform.localPosition : _transform.position;
}
}
}
60 changes: 60 additions & 0 deletions Utils/RotationTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using UnityEngine;
using Signals.Common;



namespace Signals.Utils
{
/// <summary>
/// Tracks the rotation of a GameObject.
/// </summary>
[AddComponentMenu("Signals/Utils/RotationTracker")]
public class RotationTracker : MonoBehaviour
{
[SerializeField] QuaternionSignal _signal;
[SerializeField] bool _local;
Transform _transform;

/// <summary>
/// The signal that keeps track of the rotation.
/// </summary>
public QuaternionSignal Signal
{
get
{
return _signal;
}

set
{
_signal = value;
}
}

/// <summary>
/// True to track local instead of global rotation.
/// </summary>
public bool Local
{
get
{
return _local;
}

set
{
_local = value;
}
}

void Start()
{
_transform = transform;
}

void Update()
{
if(_signal) _signal.Value = _local ? _transform.localRotation : _transform.rotation;
}
}
}
13 changes: 13 additions & 0 deletions Utils/RotationTracker.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 098b3f4

Please sign in to comment.