Skip to content

Commit

Permalink
com.unity.2d.animation@9.0.3
Browse files Browse the repository at this point in the history
## [9.0.3] - 2023-04-18
### Fixed
- Fixed Sprite Resolver inspector not able to set category to 'No Category' if it contains the old hash value. (case DAB-395)
- Fixed Sprite Resolver inspector not updating its previews when the category is set externally to 'No Category'. (case DANB-389)
- Fixed an issue where the Limb IK solver will become unstable when the child bones have different Z position. (case DANB-413)
- Fixed an issue where changing Sprite Library reference in the Inspector will result in an exception. (case DANB-426)
- Fixed an issue where the CCD and Fabrik solvers will become unstable when the child bones have different Z position. (case DANB-418)

### Added
- Updated IK parameter names and comments in public APIs.
  • Loading branch information
Unity Technologies committed Apr 18, 2023
1 parent 250ad21 commit 9b5c8cf
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 120 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [9.0.3] - 2023-04-18
### Fixed
- Fixed Sprite Resolver inspector not able to set category to 'No Category' if it contains the old hash value. (case DAB-395)
- Fixed Sprite Resolver inspector not updating its previews when the category is set externally to 'No Category'. (case DANB-389)
- Fixed an issue where the Limb IK solver will become unstable when the child bones have different Z position. (case DANB-413)
- Fixed an issue where changing Sprite Library reference in the Inspector will result in an exception. (case DANB-426)
- Fixed an issue where the CCD and Fabrik solvers will become unstable when the child bones have different Z position. (case DANB-418)

### Added
- Updated IK parameter names and comments in public APIs.

## [9.0.2] - 2023-02-27
### Added
- Added support for Collections 2.0.0.
Expand Down
32 changes: 14 additions & 18 deletions Editor/SpriteLib/SpriteResolverInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void SpriteResolverDeserializedCallback()

SpriteResolver spriteResolver => target as SpriteResolver;

bool IsSpriteHashAssigned => m_SpriteHash.intValue != 0;

void GetCategoryAndLabelStringValue(out string categoryName, out string labelName)
{
categoryName = null;
Expand All @@ -74,13 +76,13 @@ void GetCategoryAndLabelStringValue(out string categoryName, out string labelNam
var entryHash = m_SpriteHash.intValue;
spriteLib.GetCategoryAndEntryNameFromHash(entryHash, out categoryName, out labelName);

if (string.IsNullOrEmpty(categoryName) || string.IsNullOrEmpty(labelName))
if (!IsSpriteHashAssigned && (string.IsNullOrEmpty(categoryName) || string.IsNullOrEmpty(labelName)))
{
m_SpriteHash.intValue = InternalEngineBridge.ConvertFloatToInt(m_SpriteKey.floatValue);
entryHash = m_SpriteHash.intValue;
spriteLib.GetCategoryAndEntryNameFromHash(entryHash, out categoryName, out labelName);
}
if (string.IsNullOrEmpty(categoryName) || string.IsNullOrEmpty(labelName))
if (!IsSpriteHashAssigned && (string.IsNullOrEmpty(categoryName) || string.IsNullOrEmpty(labelName)))
{
var labelHash = InternalEngineBridge.ConvertFloatToInt(m_LabelHash.floatValue);
var categoryHash = InternalEngineBridge.ConvertFloatToInt(m_CategoryHash.floatValue);
Expand All @@ -90,7 +92,7 @@ void GetCategoryAndLabelStringValue(out string categoryName, out string labelNam
}
}
}

void UpdateSpriteLibrary()
{
m_SpriteLibSelection.Clear();
Expand Down Expand Up @@ -177,9 +179,8 @@ public override void OnInspectorGUI()
UpdateSpriteLibrary();

GetCategoryAndLabelStringValue(out var currentCategoryValue, out var currentLabelValue);
var catIndex = Array.FindIndex(m_CategorySelection, x => x == currentCategoryValue);
if (catIndex >= 0)
m_CategorySelectionIndex = catIndex;

m_CategorySelectionIndex = Array.FindIndex(m_CategorySelection, x => x == currentCategoryValue);
ValidateCategorySelectionIndexValue();

EditorGUI.BeginChangeCheck();
Expand Down Expand Up @@ -234,18 +235,13 @@ public override void OnInspectorGUI()

if (m_PreviousCategoryValue != currentCategoryValue)
{
if (!string.IsNullOrEmpty(currentCategoryValue))
{
if (m_SpriteLibSelection.ContainsKey(currentCategoryValue))
{
m_SpriteSelectorWidget.UpdateContents(m_SpriteLibSelection[currentCategoryValue].sprites);
}
else
m_SpriteSelectorWidget.UpdateContents(new Sprite[0]);

this.Repaint();
}

if (!string.IsNullOrEmpty(currentCategoryValue) && m_SpriteLibSelection.ContainsKey(currentCategoryValue))
m_SpriteSelectorWidget.UpdateContents(m_SpriteLibSelection[currentCategoryValue].sprites);
else
m_SpriteSelectorWidget.UpdateContents(Array.Empty<Sprite>());

Repaint();

m_PreviousCategoryValue = currentCategoryValue;
}

Expand Down
7 changes: 5 additions & 2 deletions Editor/SpriteLib/SpriteSelectionWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ public SpriteSelectorWidget()

public void UpdateContents(Sprite[] sprites)
{
var spriteCount = sprites.Length;
m_SpriteList = sprites;
m_SpritePreviews = new Texture2D[sprites.Length];
for (int i = 0; i < m_SpritePreviews.Length; ++i)
m_SpritePreviews = new Texture2D[spriteCount];
m_SpritePreviewNeedFetching.Clear();
m_SpritePreviewNeedFetching.Capacity = spriteCount;
for (var i = 0; i < spriteCount; ++i)
m_SpritePreviewNeedFetching.Add(i);
UpdateSpritePreviews();
}
Expand Down
40 changes: 21 additions & 19 deletions IK/Runtime/CCDSolver2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UnityEngine.U2D.IK
{
/// <summary>
/// Component for 2D Cyclic Coordinate Descent (CCD) IK.
/// Component responsible for 2D Cyclic Coordinate Descent (CCD) IK.
/// </summary>
[MovedFrom("UnityEngine.Experimental.U2D.IK")]
[Solver2DMenuAttribute("Chain (CCD)")]
Expand Down Expand Up @@ -35,7 +35,7 @@ public sealed class CCDSolver2D : Solver2D
Vector3[] m_Positions;

/// <summary>
/// Get and Set the solver's integration count.
/// Get and set the solver's integration count.
/// </summary>
public int iterations
{
Expand All @@ -44,7 +44,7 @@ public int iterations
}

/// <summary>
/// Get and Set target distance tolerance.
/// Get and set target distance tolerance.
/// </summary>
public float tolerance
{
Expand All @@ -62,48 +62,50 @@ public float velocity
}

/// <summary>
/// Returns the number of chain in the solver.
/// Returns the number of chains in the solver.
/// </summary>
/// <returns>This always returns 1</returns>
/// <returns>Returns 1, because CCD Solver has only one chain.</returns>
protected override int GetChainCount() => 1;

/// <summary>
/// Gets the chain in the solver by index.
/// Gets the chain in the solver at index.
/// </summary>
/// <param name="index">Chain index.</param>
/// <returns>Returns IKChain2D at the index.</returns>
/// <param name="index">Index to query. Not used in this override.</param>
/// <returns>Returns IKChain2D for the Solver.</returns>
public override IKChain2D GetChain(int index) => m_Chain;

/// <summary>
/// DoPrepare override from base class.
/// Prepares the data required for updating the solver.
/// </summary>
protected override void DoPrepare()
{
if (m_Positions == null || m_Positions.Length != m_Chain.transformCount)
m_Positions = new Vector3[m_Chain.transformCount];

var root = m_Chain.rootTransform;
for (var i = 0; i < m_Chain.transformCount; ++i)
m_Positions[i] = m_Chain.transforms[i].position;
m_Positions[i] = root.TransformPoint((Vector2)root.InverseTransformPoint(m_Chain.transforms[i].position));
}

/// <summary>
/// DoUpdateIK override from base class.
/// Updates the IK and sets the chain's transform positions.
/// </summary>
/// <param name="effectorPositions">Target position for the chain.</param>
protected override void DoUpdateIK(List<Vector3> effectorPositions)
/// <param name="targetPositions">Target positions for the chain.</param>
protected override void DoUpdateIK(List<Vector3> targetPositions)
{
Profiler.BeginSample(nameof(CCDSolver2D.DoUpdateIK));

var effectorPosition = effectorPositions[0];
var effectorLocalPosition2D = m_Chain.transforms[0].InverseTransformPoint(effectorPosition);
effectorPosition = m_Chain.transforms[0].TransformPoint(effectorLocalPosition2D);
var root = m_Chain.rootTransform;
var targetPosition = targetPositions[0];
var targetLocalPosition2D = (Vector2)root.InverseTransformPoint(targetPosition);
targetPosition = root.TransformPoint(targetLocalPosition2D);

if (CCD2D.Solve(effectorPosition, GetPlaneRootTransform().forward, iterations, tolerance, Mathf.Lerp(k_MinVelocity, k_MaxVelocity, m_Velocity), ref m_Positions))
if (CCD2D.Solve(targetPosition, GetPlaneRootTransform().forward, iterations, tolerance, Mathf.Lerp(k_MinVelocity, k_MaxVelocity, m_Velocity), ref m_Positions))
{
for (var i = 0; i < m_Chain.transformCount - 1; ++i)
{
var startLocalPosition = m_Chain.transforms[i + 1].localPosition;
var endLocalPosition = m_Chain.transforms[i].InverseTransformPoint(m_Positions[i + 1]);
var startLocalPosition = (Vector2)m_Chain.transforms[i + 1].localPosition;
var endLocalPosition = (Vector2)m_Chain.transforms[i].InverseTransformPoint(m_Positions[i + 1]);
m_Chain.transforms[i].localRotation *= Quaternion.FromToRotation(startLocalPosition, endLocalPosition);
}
}
Expand Down
34 changes: 17 additions & 17 deletions IK/Runtime/FabrikSolver2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UnityEngine.U2D.IK
{
/// <summary>
/// Component for 2D Forward And Backward Reaching Inverse Kinematics (FABRIK) IK.
/// Component responsible for 2D Forward And Backward Reaching Inverse Kinematics (FABRIK) IK.
/// </summary>
[MovedFrom("UnityEngine.Experimental.U2D.IK")]
[Solver2DMenu("Chain (FABRIK)")]
Expand All @@ -31,7 +31,7 @@ public sealed class FabrikSolver2D : Solver2D
Vector3[] m_WorldPositions;

/// <summary>
/// Get and Set the solver's integration count.
/// Get and set the solver's integration count.
/// </summary>
public int iterations
{
Expand All @@ -40,7 +40,7 @@ public int iterations
}

/// <summary>
/// Get and Set target distance tolerance.
/// Get and set target distance tolerance.
/// </summary>
public float tolerance
{
Expand All @@ -49,20 +49,20 @@ public float tolerance
}

/// <summary>
/// Returns the number of chain in the solver.
/// Returns the number of chains in the solver.
/// </summary>
/// <returns>This always returns 1.</returns>
/// <returns>Returns 1, because FABRIK Solver has only one chain.</returns>
protected override int GetChainCount() => 1;

/// <summary>
/// Gets the chain in the solver by index.
/// Gets the chain in the solver at index.
/// </summary>
/// <param name="index">Chain index.</param>
/// <returns>Returns IKChain2D at the index.</returns>
/// <param name="index">Index to query. Not used in this override.</param>
/// <returns>Returns IKChain2D for the Solver.</returns>
public override IKChain2D GetChain(int index) => m_Chain;

/// <summary>
/// DoPrepare override from base class.
/// Prepares the data required for updating the solver.
/// </summary>
protected override void DoPrepare()
{
Expand All @@ -85,16 +85,16 @@ protected override void DoPrepare()
}

/// <summary>
/// DoUpdateIK override from base class.
/// Updates the IK and sets the chain's transform positions.
/// </summary>
/// <param name="effectorPositions">Target position for the chain.</param>
protected override void DoUpdateIK(List<Vector3> effectorPositions)
/// <param name="targetPositions">Target position for the chain.</param>
protected override void DoUpdateIK(List<Vector3> targetPositions)
{
Profiler.BeginSample(nameof(FabrikSolver2D.DoUpdateIK));

var effectorPosition = effectorPositions[0];
effectorPosition = GetPointOnSolverPlane(effectorPosition);
if (FABRIK2D.Solve(effectorPosition, iterations, tolerance, m_Lengths, ref m_Positions))
var targetPosition = targetPositions[0];
targetPosition = GetPointOnSolverPlane(targetPosition);
if (FABRIK2D.Solve(targetPosition, iterations, tolerance, m_Lengths, ref m_Positions))
{
// Convert all plane positions to world positions
for (var i = 0; i < m_Positions.Length; ++i)
Expand All @@ -104,8 +104,8 @@ protected override void DoUpdateIK(List<Vector3> effectorPositions)

for (var i = 0; i < m_Chain.transformCount - 1; ++i)
{
var startLocalPosition = m_Chain.transforms[i + 1].localPosition;
var endLocalPosition = m_Chain.transforms[i].InverseTransformPoint(m_WorldPositions[i + 1]);
var startLocalPosition = (Vector2)m_Chain.transforms[i + 1].localPosition;
var endLocalPosition = (Vector2)m_Chain.transforms[i].InverseTransformPoint(m_WorldPositions[i + 1]);
m_Chain.transforms[i].localRotation *= Quaternion.FromToRotation(startLocalPosition, endLocalPosition);
}
}
Expand Down
14 changes: 7 additions & 7 deletions IK/Runtime/IKChain2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class IKChain2D
protected float[] m_Lengths;

/// <summary>
/// Get Set the Unity Transform used as IK Effector.
/// Get and set the transform used as the IK Effector.
/// </summary>
public Transform effector
{
Expand All @@ -47,7 +47,7 @@ public Transform effector
}

/// <summary>
/// Get Set the Unity Transform used as IK Target.
/// Get and set the transform used as the IK Target.
/// </summary>
public Transform target
{
Expand All @@ -56,12 +56,12 @@ public Transform target
}

/// <summary>
/// Get the Unity Transforms that are in the IK Chain.
/// Get the transforms that are used in the IK Chain.
/// </summary>
public Transform[] transforms => m_Transforms;

/// <summary>
/// Get the root Unity Transform for the IK Chain.
/// Get the root transform for the IK Chain.
/// </summary>
public Transform rootTransform
{
Expand All @@ -84,7 +84,7 @@ Transform lastTransform
}

/// <summary>
/// Get and Set the number of Unity Transforms in the IK Chain.
/// Get and Set the number of transforms in the IK Chain.
/// </summary>
public int transformCount
{
Expand Down Expand Up @@ -177,7 +177,7 @@ void PrepareLengths()
}

/// <summary>
/// Restores IK Chain to it's default pose.
/// Restores the IK Chain to it's default pose.
/// </summary>
/// <param name="targetRotationIsConstrained">True to constrain the target rotation. False otherwise.</param>
public void RestoreDefaultPose(bool targetRotationIsConstrained)
Expand All @@ -188,7 +188,7 @@ public void RestoreDefaultPose(bool targetRotationIsConstrained)
}

/// <summary>
/// Explicitly stores the local rotation
/// Explicitly stores the local rotation.
/// </summary>
public void StoreLocalRotations()
{
Expand Down
7 changes: 3 additions & 4 deletions IK/Runtime/IKManager2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace UnityEngine.U2D.IK
{
/// <summary>
/// Component to manager 2D IK Solvers.
/// Component responsible for managing and updating 2D IK Solvers.
/// </summary>
[DefaultExecutionOrder(-2)]
[MovedFrom("UnityEngine.Experimental.U2D.IK")]
Expand All @@ -26,7 +26,7 @@ public partial class IKManager2D : MonoBehaviour, IPreviewable
float m_Weight = 1f;

/// <summary>
/// Get and Set the weight for solvers.
/// Get and set the weight for solvers.
/// </summary>
public float weight
{
Expand Down Expand Up @@ -110,8 +110,7 @@ public void UpdateManager()
}

/// <summary>
/// Used by the animation clip preview window.
/// Recommended to not use outside of this purpose.
/// Used by the animation clip preview window. Recommended to not use outside of this purpose.
/// </summary>
public void OnPreviewUpdate()
{
Expand Down
Loading

0 comments on commit 9b5c8cf

Please sign in to comment.