Skip to content

Commit

Permalink
feat(structure): provide mechanism to change properties via UnityEvents
Browse files Browse the repository at this point in the history
Some property types cannot be changed via UnityEvents as they are not
supported in the UnityEvent inspector, such as Enums, Vectors and
Vector3State.

This has been fixed by adding custom setter methods that can be called
via the UnityEvent inspector using primitive types that are supported
to allow this data to still be set.
  • Loading branch information
thestonefox committed Jul 10, 2020
1 parent 33463ce commit 98ae181
Show file tree
Hide file tree
Showing 27 changed files with 613 additions and 9 deletions.
29 changes: 28 additions & 1 deletion Runtime/Action/SurfaceChangeAction.cs
Expand Up @@ -29,7 +29,34 @@ public class SurfaceChangeAction : BooleanAction
protected SurfaceData previousData;

/// <summary>
/// Digests <see cref="SurfaceData"/> and compares the current surface to the previous surface to determine if a change has occured.
/// Sets the <see cref="CheckAxis"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetCheckAxisX(bool value)
{
CheckAxis = new Vector3State(value, CheckAxis.yState, CheckAxis.zState);
}

/// <summary>
/// Sets the <see cref="CheckAxis"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetCheckAxisY(bool value)
{
CheckAxis = new Vector3State(CheckAxis.xState, value, CheckAxis.zState);
}

/// <summary>
/// Sets the <see cref="CheckAxis"/> z value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetCheckAxisZ(bool value)
{
CheckAxis = new Vector3State(CheckAxis.xState, CheckAxis.yState, value);
}

/// <summary>
/// Digests <see cref="SurfaceData"/> and compares the current surface to the previous surface to determine if a change has occurred.
/// </summary>
/// <param name="surfaceData">The <see cref="SurfaceData"/> to check on.</param>
[RequiresBehaviourState]
Expand Down
18 changes: 18 additions & 0 deletions Runtime/Cast/ParabolicLineCast.cs
Expand Up @@ -53,6 +53,24 @@ public class ParabolicLineCast : PointsCast
/// </summary>
protected readonly List<Vector3> curvePoints = new List<Vector3>();

/// <summary>
/// Sets the <see cref="MaximumLength"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetMaximumLengthX(float value)
{
MaximumLength = new Vector2(value, MaximumLength.y);
}

/// <summary>
/// Sets the <see cref="MaximumLength"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetMaximumLengthY(float value)
{
MaximumLength = new Vector2(MaximumLength.x, value);
}

protected override void OnEnable()
{
base.OnEnable();
Expand Down
6 changes: 3 additions & 3 deletions Runtime/Cast/PointsCast.cs
Expand Up @@ -40,7 +40,7 @@ public class EventData
public bool IsValid { get; set; }

/// <summary>
/// The points along the the most recent cast.
/// The points along the most recent cast.
/// </summary>
public HeapAllocationFreeReadOnlyList<Vector3> Points { get; set; }

Expand Down Expand Up @@ -108,12 +108,12 @@ public class UnityEvent : UnityEvent<EventData> { }
/// </summary>
public bool IsTargetHitValid { get; protected set; }
/// <summary>
/// The points along the the most recent cast.
/// The points along the most recent cast.
/// </summary>
public HeapAllocationFreeReadOnlyList<Vector3> Points => points;

/// <summary>
/// The points along the the most recent cast.
/// The points along the most recent cast.
/// </summary>
protected readonly List<Vector3> points = new List<Vector3>();
/// <summary>
Expand Down
16 changes: 13 additions & 3 deletions Runtime/Data/Operation/Extraction/TimeComponentExtractor.cs
Expand Up @@ -3,6 +3,7 @@
using System;
using UnityEngine;
using UnityEngine.Events;
using Zinnia.Extension;

/// <summary>
/// Extracts and emits the elements from <see cref="Time"/>.
Expand Down Expand Up @@ -45,11 +46,11 @@ public enum TimeComponent
/// </summary>
TimeStepTypeDeltaTime,
/// <summary>
/// The timeScale-independant time for this frame. This is the time in seconds since the start of the game.
/// The timeScale-independent time for this frame. This is the time in seconds since the start of the game.
/// </summary>
UnscaledTime,
/// <summary>
/// The TimeScale-independant time the latest MonoBehaviour.FixedUpdate has started. This is the time in seconds since the start of the game.
/// The TimeScale-independent time the latest MonoBehaviour.FixedUpdate has started. This is the time in seconds since the start of the game.
/// </summary>
FixedUnscaledTime,
/// <summary>
Expand All @@ -69,7 +70,7 @@ public enum TimeComponent
/// </summary>
TimeStepTypeUnscaledDeltaTime,
/// <summary>
/// Slows game playback time to allow screenshots to be saved between frames.
/// Slows game playback time to allow screen shots to be saved between frames.
/// </summary>
CaptureFrameRate,
/// <summary>
Expand Down Expand Up @@ -106,6 +107,15 @@ public enum TimeComponent
TimeSinceLevelLoad
}

/// <summary>
/// Sets the <see cref="Source"/>.
/// </summary>
/// <param name="index">The index of the <see cref="TimeComponent"/>.</param>
public virtual void SetSource(int index)
{
Source = EnumExtensions.GetByIndex<TimeComponent>(index);
}

/// <inheritdoc />
protected override float? ExtractValue()
{
Expand Down
10 changes: 10 additions & 0 deletions Runtime/Data/Operation/Extraction/TransformDirectionExtractor.cs
Expand Up @@ -3,6 +3,7 @@
using Malimbe.PropertySerializationAttribute;
using Malimbe.XmlDocumentationAttribute;
using UnityEngine;
using Zinnia.Extension;

/// <summary>
/// Extracts a chosen axis of a <see cref="Transform"/>.
Expand Down Expand Up @@ -35,6 +36,15 @@ public enum AxisDirection
[field: DocumentedByXml]
public AxisDirection Direction { get; set; }

/// <summary>
/// Sets the <see cref="Direction"/>.
/// </summary>
/// <param name="index">The index of the <see cref="AxisDirection"/>.</param>
public virtual void SetDirection(int index)
{
Direction = EnumExtensions.GetByIndex<AxisDirection>(index);
}

/// <inheritdoc />
protected override Vector3? ExtractValue()
{
Expand Down
54 changes: 54 additions & 0 deletions Runtime/Data/Operation/Mutation/RigidbodyPropertyMutator.cs
Expand Up @@ -68,6 +68,33 @@ public virtual void SetTarget(GameObject target)
Target = target.TryGetComponent<Rigidbody>(true, true);
}

/// <summary>
/// Sets the <see cref="Velocity"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetVelocityX(float value)
{
Velocity = new Vector3(value, Velocity.y, Velocity.z);
}

/// <summary>
/// Sets the <see cref="Velocity"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetVelocityY(float value)
{
Velocity = new Vector3(Velocity.x, value, Velocity.z);
}

/// <summary>
/// Sets the <see cref="Velocity"/> z value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetVelocityZ(float value)
{
Velocity = new Vector3(Velocity.x, Velocity.y, value);
}

/// <summary>
/// Sets the velocity of the <see cref="Target"/> to zero.
/// </summary>
Expand All @@ -77,6 +104,33 @@ public virtual void ClearVelocity()
Velocity = Vector3.zero;
}

/// <summary>
/// Sets the <see cref="AngularVelocity"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetAngularVelocityX(float value)
{
AngularVelocity = new Vector3(value, AngularVelocity.y, AngularVelocity.z);
}

/// <summary>
/// Sets the <see cref="AngularVelocity"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetAngularVelocityY(float value)
{
AngularVelocity = new Vector3(AngularVelocity.x, value, AngularVelocity.z);
}

/// <summary>
/// Sets the <see cref="AngularVelocity"/> z value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetAngularVelocityZ(float value)
{
AngularVelocity = new Vector3(AngularVelocity.x, AngularVelocity.y, value);
}

/// <summary>
/// Sets the angular velocity of the <see cref="Target"/> to zero.
/// </summary>
Expand Down
29 changes: 28 additions & 1 deletion Runtime/Data/Operation/Mutation/TransformEulerRotationMutator.cs
Expand Up @@ -10,7 +10,7 @@
using Zinnia.Extension;

/// <summary>
/// Mutates the euler rotation of a transform with an optional custom rotation origin.
/// Mutates the Euler rotation of a transform with an optional custom rotation origin.
/// </summary>
public class TransformEulerRotationMutator : TransformPropertyMutator
{
Expand All @@ -29,6 +29,33 @@ public class TransformEulerRotationMutator : TransformPropertyMutator
public Vector3State ApplyOriginOnAxis { get; set; } = Vector3State.True;
#endregion

/// <summary>
/// Sets the <see cref="ApplyOriginOnAxis"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetApplyOriginOnAxisX(bool value)
{
ApplyOriginOnAxis = new Vector3State(value, ApplyOriginOnAxis.yState, ApplyOriginOnAxis.zState);
}

/// <summary>
/// Sets the <see cref="ApplyOriginOnAxis"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetApplyOriginOnAxisY(bool value)
{
ApplyOriginOnAxis = new Vector3State(ApplyOriginOnAxis.xState, value, ApplyOriginOnAxis.zState);
}

/// <summary>
/// Sets the <see cref="ApplyOriginOnAxis"/> z value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetApplyOriginOnAxisZ(bool value)
{
ApplyOriginOnAxis = new Vector3State(ApplyOriginOnAxis.xState, ApplyOriginOnAxis.yState, value);
}

/// <inheritdoc/>
protected override float GetGlobalAxisValue(int axis)
{
Expand Down
27 changes: 27 additions & 0 deletions Runtime/Data/Operation/Mutation/TransformPositionMutator.cs
Expand Up @@ -27,6 +27,33 @@ public class TransformPositionMutator : TransformPropertyMutator
public Vector3State ApplyFacingDirectionOnAxis { get; set; } = Vector3State.True;
#endregion

/// <summary>
/// Sets the <see cref="ApplyFacingDirectionOnAxis"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetApplyFacingDirectionOnAxisX(bool value)
{
ApplyFacingDirectionOnAxis = new Vector3State(value, ApplyFacingDirectionOnAxis.yState, ApplyFacingDirectionOnAxis.zState);
}

/// <summary>
/// Sets the <see cref="ApplyFacingDirectionOnAxis"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetApplyFacingDirectionOnAxisY(bool value)
{
ApplyFacingDirectionOnAxis = new Vector3State(ApplyFacingDirectionOnAxis.xState, value, ApplyFacingDirectionOnAxis.zState);
}

/// <summary>
/// Sets the <see cref="ApplyFacingDirectionOnAxis"/> z value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetApplyFacingDirectionOnAxisZ(bool value)
{
ApplyFacingDirectionOnAxis = new Vector3State(ApplyFacingDirectionOnAxis.xState, ApplyFacingDirectionOnAxis.yState, value);
}

/// <inheritdoc/>
protected override float GetGlobalAxisValue(int axis)
{
Expand Down
27 changes: 27 additions & 0 deletions Runtime/Data/Operation/Mutation/TransformPropertyMutator.cs
Expand Up @@ -33,6 +33,33 @@ public abstract class TransformPropertyMutator : MonoBehaviour
public Vector3State MutateOnAxis { get; set; } = Vector3State.True;
#endregion

/// <summary>
/// Sets the <see cref="MutateOnAxis"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetMutateOnAxisX(bool value)
{
MutateOnAxis = new Vector3State(value, MutateOnAxis.yState, MutateOnAxis.zState);
}

/// <summary>
/// Sets the <see cref="MutateOnAxis"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetMutateOnAxisY(bool value)
{
MutateOnAxis = new Vector3State(MutateOnAxis.xState, value, MutateOnAxis.zState);
}

/// <summary>
/// Sets the <see cref="MutateOnAxis"/> z value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetMutateOnAxisZ(bool value)
{
MutateOnAxis = new Vector3State(MutateOnAxis.xState, MutateOnAxis.yState, value);
}

/// <summary>
/// Sets the property to the new value.
/// </summary>
Expand Down
Expand Up @@ -33,6 +33,24 @@ public class UnityEvent : UnityEvent<Vector2> { }
/// </summary>
protected Vector2 outputAngle;

/// <summary>
/// Sets the <see cref="Direction"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetDirectionX(float value)
{
Direction = new Vector2(value, Direction.y);
}

/// <summary>
/// Sets the <see cref="Direction"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetDirectionY(float value)
{
Direction = new Vector2(Direction.x, value);
}

/// <summary>
/// Transforms the given <see cref="float"/> angle into a <see cref="Vector2"/> direction.
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions Runtime/Data/Type/Transformation/Conversion/Vector2ToAngle.cs
Expand Up @@ -64,6 +64,33 @@ public enum AngleUnit
[field: DocumentedByXml]
public Vector2 Origin { get; set; } = new Vector2(0f, 1f);

/// <summary>
/// Sets the <see cref="Unit"/>.
/// </summary>
/// <param name="index">The index of the <see cref="AngleUnit"/>.</param>
public virtual void SetUnit(int index)
{
Unit = EnumExtensions.GetByIndex<AngleUnit>(index);
}

/// <summary>
/// Sets the <see cref="Origin"/> x value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetOriginX(float value)
{
Origin = new Vector2(value, Origin.y);
}

/// <summary>
/// Sets the <see cref="Origin"/> y value.
/// </summary>
/// <param name="value">The value to set to.</param>
public virtual void SetOriginY(float value)
{
Origin = new Vector2(Origin.x, value);
}

/// <summary>
/// The full circle in radians.
/// </summary>
Expand Down

0 comments on commit 98ae181

Please sign in to comment.