Skip to content

Commit

Permalink
Merge pull request #592 from ExtendRealityLtd/feat/fixes-and-additions
Browse files Browse the repository at this point in the history
Feat/fixes and additions
  • Loading branch information
thestonefox authored Apr 17, 2024
2 parents a88eca9 + 170a241 commit 80ca814
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 22 deletions.
28 changes: 16 additions & 12 deletions Editor/Data/Type/CollapsibleUnityEventDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Zinnia.Data.Type
{
#if ZINNIA_IGNORE_CUSTOM_COLLAPSIBLE_DRAWER
#else
using System.Collections;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -46,18 +48,19 @@ public class CollapsibleUnityEventDrawer : UnityEventDrawer
public static void ReplaceDefaultDrawer()
{
System.Type utilityType = System.Type.GetType("UnityEditor.ScriptAttributeUtility, UnityEditor");
MethodInfo buildMethod = utilityType.GetMethod(
"BuildDrawerTypeForTypeDictionary",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
null,
System.Type.EmptyTypes,
null);
FieldInfo dictionaryField = utilityType.GetField(
"s_DrawerTypeForType",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
FieldInfo drawerField = utilityType
.GetNestedType("DrawerKeySet", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.GetField("drawer", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (utilityType == null)
{
return;
}

MethodInfo buildMethod = utilityType.GetMethod("BuildDrawerTypeForTypeDictionary", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, System.Type.EmptyTypes, null);
FieldInfo dictionaryField = utilityType.GetField("s_DrawerTypeForType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
System.Type drawerKeySet = utilityType.GetNestedType("DrawerKeySet", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (drawerKeySet == null)
{
return;
}
FieldInfo drawerField = drawerKeySet.GetField("drawer", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

// Ensure the key set is populated.
buildMethod.Invoke(null, null);
Expand Down Expand Up @@ -126,4 +129,5 @@ protected virtual void DrawHeader(Rect position)
DrawEventHeader(headerRect);
}
}
#endif
}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ Because Zinnia is a package tests have to be explicitly enabled for this package

The package will show up in the Unity Package Manager UI once the above steps have been carried out. From then on the package can be updated by selecting the package in the Unity Package Manager and clicking on the `Update` button or using the version selection UI.

## Script Define Symbols

There are a collection of custom script define symbols that are included that can affect functionalities provided within Zinnia:

* `ZINNIA_IGNORE_CUSTOM_COLLAPSIBLE_DRAWER` - Disables the collapsible event drawer functionality in the inspector windows.
* `ZINNIA_IGNORE_CUSTOM_INSPECTOR_EDITOR` - Disables the custom zinnia inspector that handles automatically updating property values when changed in the inspector.
* `ZINNIA_IGNORE_CUSTOM_LIST_EDITOR` - Disables the custom observable list editor in any version of Unity.
* `ZINNIA_IGNORE_PIPELINE_MATERIALS` - Prevents the `PipelineMaterialApplier` from updating materials to match the current render pipeline mode.
* `ZINNIA_USE_CUSTOM_LIST_EDITOR` - Force the custom observable list editor in the version of Unity 2020.3 or above.
* `ZINNIA_USE_ISACTIVEANDENABLED` - Determines whether to use the `behaviour.isActiveAndEnabled` property on a behvaiour when calling the `CheckIsActiveAndEnabled` method instead of using the more robust `behaviour.gameObject.activeInHierarchy && behaviour.enabled`.

## Naming

Inspired by the [Zinnia] genus of plants known for their colorful, long lasting flower heads and their great ease to grow from seeds. This repository, much like the Zinnia flower aims to be easy to use and allow your projects to grow and flourish into long lasting, easy to maintain solutions.
Expand Down
36 changes: 33 additions & 3 deletions Runtime/Cast/PointsCast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ public RuleContainer _targetPointValidity
_targetPointValidity = value;
}
}
[Tooltip("Allows to optionally determine if the raycast hit of the cast is valud based on the set rules.")]
[SerializeField]
private RuleContainer raycastHitValidity;
/// <summary>
/// Allows to optionally determine if the raycast hit of the cast is valud based on the set rules.
/// </summary>
public RuleContainer RaycastHitValidity
{
get
{
return raycastHitValidity;
}
set
{
raycastHitValidity = value;
}
}
[Tooltip("The amount of distance the cursor has to move before the destination of the cursor is updated to a new position.")]
[SerializeField]
private float cursorLockThreshold;
Expand Down Expand Up @@ -227,7 +244,7 @@ public float TransitionDuration
public UnityEvent ResultsChanged = new UnityEvent();

/// <summary>
/// The result of the most recent cast. <see langword="null"/> when the cast didn't hit anything or an invalid _target according to <see cref="_targetValidity"/> or <see cref="_targetPointValidity"/> rules.
/// The result of the most recent cast. <see langword="null"/> when the cast didn't hit anything or an invalid _target according to <see cref="_targetValidity"/> or <see cref="_targetPointValidity"/> or <see cref="RaycastHitValidity"/> rules.
/// </summary>
private RaycastHit? _targetHit;
public RaycastHit? _targetHit
Expand All @@ -246,7 +263,7 @@ protected set
}
}
/// <summary>
/// Whether the current <see cref="_targetHit"/> is valid based on the <see cref="_targetValidity"/> and <see cref="_targetPointValidity"/> rules.
/// Whether the current <see cref="_targetHit"/> is valid based on the <see cref="_targetValidity"/> and <see cref="_targetPointValidity"/> and <see cref="RaycastHitValidity"/> rules.
/// </summary>
public bool Is_targetHitValid { get; protected set; }
/// <summary>
Expand Down Expand Up @@ -323,6 +340,19 @@ public virtual void Clear_targetPointValidity()
_targetPointValidity = default;
}

/// <summary>
/// Clears <see cref="RaycastHitValidity"/>.
/// </summary>
public virtual void ClearRaycastHitValidity()
{
if (!this.IsValidState())
{
return;
}

RaycastHitValidity = default;
}

/// <summary>
/// Clears the <see cref="DestinationPointOverride"/>.
/// </summary>
Expand Down Expand Up @@ -414,7 +444,7 @@ protected virtual RaycastHit GetActual_targetHit(RaycastHit actualHitData, bool h
/// </summary>
protected virtual void OnAfter_targetHitChange()
{
Is_targetHitValid = _targetHit != null && _targetValidity.Accepts(_targetHit.Value.transform.gameObject) && _targetPointValidity.Accepts(_targetHit.Value.point);
Is_targetHitValid = _targetHit != null && _targetValidity.Accepts(_targetHit.Value.transform.gameObject) && _targetPointValidity.Accepts(_targetHit.Value.point) && RaycastHitValidity.Accepts(_targetHit);
}
}
}
10 changes: 5 additions & 5 deletions Runtime/Cast/StraightLineCast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public int DragEffectDensity
}
}
}
[Tooltip("The amount of height offset to apply to the curved drag line.")]
[Tooltip("The amount of offset to apply to the curved drag line.")]
[SerializeField]
private float dragCurveOffset;
private Vector3 dragCurveOffset;
/// <summary>
/// The amount of height offset to apply to the curved drag line.
/// The amount of offset to apply to the curved drag line.
/// </summary>
public float DragCurveOffset
public Vector3 DragCurveOffset
{
get
{
Expand Down Expand Up @@ -321,7 +321,7 @@ protected virtual void GeneratePoints(Vector3 originPoint, Vector3 midPoint, Vec
{
curvePoints.Clear();
curvePoints.Add(originPoint);
curvePoints.Add(midPoint + (Vector3.back * DragCurveOffset));
curvePoints.Add(midPoint + DragCurveOffset);
curvePoints.Add(destinationPoint);
curvePoints.Add(destinationPoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
/// </summary>
public class TransformPositionDifferenceRotation : PropertyModifier
{
[Tooltip("The maximum distance the Source GameObject can be from the Offset GameObject to allow the rotation to apply.")]
[SerializeField]
private Vector3 sourceToOffsetMaximumDistance = Vector3.one * float.PositiveInfinity;
/// <summary>
/// The maximum distance the Source <see cref="GameObject"/> can be from the Offset <see cref="GameObject"/> to allow the rotation to apply.
/// </summary>
public Vector3 SourceToOffsetMaximumDistance
{
get
{
return sourceToOffsetMaximumDistance;
}
set
{
sourceToOffsetMaximumDistance = value;
}
}
[Tooltip("The drag applied to the rotation to slow it down.")]
[SerializeField]
private float angularDrag = 1f;
Expand Down Expand Up @@ -127,7 +144,7 @@ public virtual void ResetPreviousState()
/// <param name="offset">The offset of the _target against the source when modifying.</param>
protected override void DoModify(GameObject source, GameObject _target, GameObject offset = null)
{
AngularVelocity = CalculateAngularVelocity(source, _target);
AngularVelocity = CalculateAngularVelocity(source, _target, offset);
_target.transform.localRotation *= Quaternion.Euler(AngularVelocity);
}

Expand All @@ -141,18 +158,25 @@ protected virtual void OnDisable()
/// </summary>
/// <param name="source">The source to utilize in the modification.</param>
/// <param name="_target">The _target to modify.</param>
/// <param name="offset">The offset of the _target against the source when modifying.</param>
/// <returns>The angular velocity to project onto the _target.</returns>
protected virtual Vector3 CalculateAngularVelocity(GameObject source, GameObject _target)
protected virtual Vector3 CalculateAngularVelocity(GameObject source, GameObject _target, GameObject offset)
{
Vector3 negatePosition = Ancestor != null ? Ancestor.transform.position : Vector3.zero;
Vector3 sourcePosition = source.transform.position - negatePosition;
Vector3 _targetPosition = _target.transform.position - negatePosition;
Vector3 offsetPosition = offset != null ? offset.transform.position - negatePosition : Vector3.zero;

if (previousSourcePosition == null)
{
previousSourcePosition = sourcePosition;
}

if (offset != null && !sourcePosition.WithinDistance(offsetPosition, SourceToOffsetMaximumDistance))
{
return Vector3.zero;
}

float xDegree = FollowOnAxis.xState ? CalculateAngle(_target.transform.right, _targetPosition, (Vector3)previousSourcePosition, sourcePosition) : 0f;
float yDegree = FollowOnAxis.yState ? CalculateAngle(_target.transform.up, _targetPosition, (Vector3)previousSourcePosition, sourcePosition) : 0f;
float zDegree = FollowOnAxis.zState ? CalculateAngle(_target.transform.forward, _targetPosition, (Vector3)previousSourcePosition, sourcePosition) : 0f;
Expand Down

0 comments on commit 80ca814

Please sign in to comment.
  NODES
COMMUNITY 1
Note 1
Project 3
USERS 1