Skip to content

Commit

Permalink
com.unity.2d.animation@7.1.2
Browse files Browse the repository at this point in the history
## [7.1.2] - 2024-09-25
### Fixed
- Fixed SpriteSkin's playmode test failures. (case DANB-690)
- Documentation, comments, and other requirements to conform to Package Validation. (DANB-709)
- Sprite Resolver missing sprite previews when dealing with large number of entries. (DANB-715)
- Misaligned label previews in Sprite Resolver's inspector. (DANB-720)
- Sprite Resolver component not updated after Sprite Library Asset has been modified. (DANB-734)
- IK gizmos are displayed in the SceneView when IKManager2D is active in Animation Preview window. (DANB-736)
- IK solvers are misaligned when bones have different depths. (DANB-751)
  • Loading branch information
Unity Technologies committed Sep 25, 2024
1 parent 3de69c0 commit c2a3a62
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 147 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [7.1.2] - 2024-09-25
### Fixed
- Fixed SpriteSkin's playmode test failures. (case DANB-690)
- Documentation, comments, and other requirements to conform to Package Validation. (DANB-709)
- Sprite Resolver missing sprite previews when dealing with large number of entries. (DANB-715)
- Misaligned label previews in Sprite Resolver's inspector. (DANB-720)
- Sprite Resolver component not updated after Sprite Library Asset has been modified. (DANB-734)
- IK gizmos are displayed in the SceneView when IKManager2D is active in Animation Preview window. (DANB-736)
- IK solvers are misaligned when bones have different depths. (DANB-751)

## [7.1.1] - 2024-05-30
### Fixed
- Fixed the IK bones flipped at certain angels. (case DANB-594)
Expand Down
40 changes: 25 additions & 15 deletions Editor/SpriteLib/SpriteResolverInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct SpriteCategorySelectionList

public void OnEnable()
{
m_SpriteSelectorWidget.Initialize(GetInstanceID());

m_SpriteKey = serializedObject.FindProperty("m_SpriteKey");
m_LabelHash = serializedObject.FindProperty("m_labelHash");
m_CategoryHash = serializedObject.FindProperty("m_CategoryHash");
Expand All @@ -56,14 +58,19 @@ public void OnDisable()
spriteResolver.onDeserializedCallback -= SpriteResolverDeserializedCallback;
}

void OnDestroy()
{
m_SpriteSelectorWidget.Dispose();
}

void SpriteResolverDeserializedCallback()
{
if (!m_IgnoreNextDeserializeCallback)
{
m_ReInitOnNextGUI = true;
}
}

SpriteResolver spriteResolver => target as SpriteResolver;

bool IsSpriteHashAssigned => SpriteResolver.ConvertFloatToInt(m_SpriteKey.floatValue) != 0;
Expand All @@ -87,25 +94,25 @@ void GetCategoryAndLabelStringValue(out string categoryName, out string labelNam
}
}
}

void UpdateSpriteLibrary()
{
m_SpriteLibSelection.Clear();

var spriteLib = spriteResolver.spriteLibrary;
string categoryName ="", labelName ="";
string categoryName = "", labelName = "";
if (spriteLib != null)
{
GetCategoryAndLabelStringValue(out categoryName, out labelName);
var enumerator = spriteLib.categoryNames;
foreach(var category in spriteLib.categoryNames)
foreach (var category in spriteLib.categoryNames)
{
if (!m_SpriteLibSelection.ContainsKey(category))
{
var entries = spriteLib.GetEntryNames(category);
if (entries == null)
entries = new string[0];

var selectionList = new SpriteCategorySelectionList()
{
entryNames = entries.ToArray(),
Expand All @@ -117,10 +124,11 @@ void UpdateSpriteLibrary()
};

m_SpriteLibSelection.Add(category, selectionList);

}
}
}

m_CategorySelection = new string[1 + m_SpriteLibSelection.Keys.Count];
m_CategorySelection[0] = Style.noCategory.text;
for (int i = 0; i < m_SpriteLibSelection.Keys.Count; ++i)
Expand All @@ -130,6 +138,7 @@ void UpdateSpriteLibrary()
if (selection.categoryName == categoryName)
m_CategorySelectionIndex = i + 1;
}

ValidateCategorySelectionIndexValue();
if (m_CategorySelectionIndex > 0)
{
Expand All @@ -140,7 +149,7 @@ void UpdateSpriteLibrary()
{
var labelIndex = Array.FindIndex(m_SpriteLibSelection[categoryName].entryNames,
x => x == labelName);

if (labelIndex >= 0 ||
m_SpriteLibSelection[categoryName].entryNames.Length <= m_LabelSelectionIndex)
{
Expand All @@ -152,6 +161,7 @@ void UpdateSpriteLibrary()
{
m_SpriteSelectorWidget.UpdateContents(new Sprite[0]);
}

spriteResolver.spriteLibChanged = false;
}

Expand All @@ -177,11 +187,11 @@ public override void OnInspectorGUI()

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

EditorGUI.BeginChangeCheck();
using (new EditorGUI.DisabledScope(m_CategorySelection.Length <= 1))
m_CategorySelectionIndex = EditorGUILayout.Popup(Style.categoryLabel, m_CategorySelectionIndex, m_CategorySelection);

SpriteCategorySelectionList selection;
m_SpriteLibSelection.TryGetValue(m_CategorySelection[m_CategorySelectionIndex], out selection);

Expand All @@ -194,16 +204,16 @@ public override void OnInspectorGUI()
{
if (entryNames.Length == 0)
{
m_LabelSelectionIndex = EditorGUILayout.Popup(Style.labelLabel, 0, new [] {Style.categoryIsEmptyLabel});
m_LabelSelectionIndex = EditorGUILayout.Popup(Style.labelLabel, 0, new[] { Style.categoryIsEmptyLabel });
}
else
{
m_LabelSelectionIndex = EditorGUILayout.Popup(Style.labelLabel, m_LabelSelectionIndex, entryNames);
}
}

m_LabelSelectionIndex = m_SpriteSelectorWidget.ShowGUI(m_LabelSelectionIndex);


if (EditorGUI.EndChangeCheck())
{
Expand Down Expand Up @@ -248,10 +258,10 @@ public override void OnInspectorGUI()
}

ApplyModifiedProperty();
if (m_SpriteSelectorWidget.NeedUpdatePreview())
if (m_SpriteSelectorWidget.UpdateSpritePreviews())
this.Repaint();
}

void ApplyModifiedProperty()
{
m_IgnoreNextDeserializeCallback = true;
Expand Down
147 changes: 103 additions & 44 deletions Editor/SpriteLib/SpriteSelectionWidget.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEditor.U2D.Common;

namespace UnityEditor.U2D.Animation
{
Expand All @@ -11,96 +13,153 @@ class Styles

public Styles()
{
gridListStyle = new GUIStyle("GridList");
gridListStyle.alignment = GUI.skin.button.alignment;
gridListStyle = new GUIStyle("GridList")
{
alignment = GUI.skin.button.alignment,
padding = new RectOffset(k_GridCellPadding, k_GridCellPadding, k_GridCellPadding, k_GridCellPadding),
fixedHeight = k_TargetPreviewSize,
fixedWidth = k_TargetPreviewSize
};
}
}

static Texture2D spriteLoadingThumbnail
{
get
{
if (s_LoadingSpriteTexture == null)
s_LoadingSpriteTexture = AssetPreview.GetMiniTypeThumbnail(typeof(Sprite));
return s_LoadingSpriteTexture;
}
}

Sprite[] m_SpriteList = new Sprite[0];
Texture2D[] m_SpritePreviews = new Texture2D[0];
List<int> m_SpritePreviewNeedFetching = new List<int>();
static Texture2D s_LoadingSpriteTexture;

const int k_TargetPreviewSize = 64;
const int k_GridCellPadding = 2;
const int k_ScrollbarWidthOffset = 10;

List<int> m_SpritePreviewNeedFetching = new();

Sprite[] m_SpriteList = Array.Empty<Sprite>();
Texture2D[] m_SpritePreviews = Array.Empty<Texture2D>();

int m_ClientId = 0;
int m_PreviewCacheSize = 0;

Vector2 m_ScrollPos;
Styles m_Style;
const int kTargetPreviewSize = 64;
public SpriteSelectorWidget()
{}


public void Initialize(int clientId)
{
m_ClientId = clientId;
}

public void Dispose()
{
if (m_ClientId != 0)
{
InternalEditorBridge.ClearAssetPreviews(m_ClientId);
m_ClientId = 0;
}
}

public void UpdateContents(Sprite[] sprites)
{
m_SpritePreviewNeedFetching.Clear();

InternalEditorBridge.ClearAssetPreviews(m_ClientId);

var spriteCount = sprites.Length;
m_PreviewCacheSize = spriteCount + 1;
InternalEditorBridge.SetAssetPreviewTextureCacheSize(m_PreviewCacheSize, m_ClientId);

m_SpriteList = sprites;
m_SpritePreviews = new Texture2D[spriteCount];
m_SpritePreviewNeedFetching.Clear();

m_SpritePreviewNeedFetching.Capacity = spriteCount;
for (var i = 0; i < spriteCount; ++i)
m_SpritePreviewNeedFetching.Add(i);
UpdateSpritePreviews();
}


public int ShowGUI(int selectedIndex)
{
if (m_Style == null)
m_Style = new Styles();

UpdateSpritePreviews();

var drawRect = EditorGUILayout.GetControlRect(false, kTargetPreviewSize + 10f, new[] {GUILayout.ExpandWidth(true)});
if(Event.current.type == EventType.Repaint)
var drawRect = EditorGUILayout.GetControlRect(false, k_TargetPreviewSize + 10f, new[] { GUILayout.ExpandWidth(true) });
if (Event.current.type == EventType.Repaint)
GUI.skin.box.Draw(drawRect, false, false, false, false);
if (m_SpriteList == null || m_SpriteList.Length == 0)
{
return selectedIndex;
}

selectedIndex = (selectedIndex > m_SpriteList.Length) ? 0 : selectedIndex;
float columnF;
int columnCount, rowCount;
GetRowColumnCount(drawRect.width - 20, kTargetPreviewSize, m_SpriteList.Length, out columnCount, out rowCount, out columnF);

var widthMargin = (m_Style.gridListStyle.margin.left + m_Style.gridListStyle.margin.right) * 0.5f;
var heightMargin = (m_Style.gridListStyle.margin.top + m_Style.gridListStyle.margin.bottom) * 0.5f;
GetRowColumnCount(drawRect.width - k_ScrollbarWidthOffset, k_TargetPreviewSize + Mathf.RoundToInt(widthMargin), m_SpriteList.Length, out var columnCount, out var rowCount);
if (columnCount > 0 && rowCount > 0)
{
float contentSize = (columnF * kTargetPreviewSize) / columnCount;
var gridRect = new Rect(drawRect.x, drawRect.y, drawRect.width - 20, rowCount * contentSize);
m_ScrollPos = GUI.BeginScrollView(drawRect,m_ScrollPos, gridRect, false, false, GUIStyle.none, GUI.skin.verticalScrollbar);

m_Style.gridListStyle.fixedWidth = contentSize;
m_Style.gridListStyle.fixedHeight = contentSize;
selectedIndex = GUI.SelectionGrid( gridRect, selectedIndex, m_SpritePreviews, columnCount, m_Style.gridListStyle);
var height = rowCount * (k_TargetPreviewSize + heightMargin);
var width = columnCount * (k_TargetPreviewSize + widthMargin);
var scrollViewRect = new Rect(drawRect.x - k_ScrollbarWidthOffset, drawRect.y, width, height);
m_ScrollPos = GUI.BeginScrollView(drawRect, m_ScrollPos, scrollViewRect, false, false, GUIStyle.none, GUI.skin.verticalScrollbar);

var gridRect = scrollViewRect;
gridRect.x += (drawRect.width - width - k_ScrollbarWidthOffset) * 0.5f;
selectedIndex = GUI.SelectionGrid(gridRect, selectedIndex, m_SpritePreviews, columnCount, m_Style.gridListStyle);

GUI.EndScrollView();
}

return selectedIndex;
}

static void GetRowColumnCount(float drawWidth, int size, int contentCount, out int column, out int row, out float columnf)
static void GetRowColumnCount(float drawWidth, int size, int contentCount, out int columnCount, out int rowCount)
{
columnf = drawWidth / size;
column = (int)Mathf.Floor(columnf);
if (column == 0)
row = 0;
columnCount = (int)drawWidth / size;
if (columnCount == 0)
rowCount = 0;
else
row = (int)Mathf.Ceil((contentCount + column) / column);
rowCount = Math.Max(1, Mathf.CeilToInt((float)contentCount / columnCount));
}

public bool NeedUpdatePreview()
{
return m_SpritePreviewNeedFetching.Count > 0;
}

void UpdateSpritePreviews()
public bool UpdateSpritePreviews()
{
for (int i = 0; i < m_SpritePreviewNeedFetching.Count; ++i)
var remainingPreviewCount = m_SpritePreviewNeedFetching.Count;
if (remainingPreviewCount == 0)
return false;

for (var i = remainingPreviewCount - 1; i >= 0; --i)
{
var index = m_SpritePreviewNeedFetching[i];
if(m_SpriteList[index] == null)
if (m_SpriteList[index] == null)
{
m_SpritePreviews[index] = EditorGUIUtility.Load("icons/console.warnicon.png") as Texture2D;
m_SpritePreviewNeedFetching.RemoveAt(i);
}
else
m_SpritePreviews[index] = AssetPreview.GetAssetPreview(m_SpriteList[index]);
if (m_SpritePreviews[index] != null)
{
m_SpritePreviewNeedFetching.RemoveAt(i);
--i;
var spriteId = m_SpriteList[index].GetInstanceID();
var spritePreview = InternalEditorBridge.GetAssetPreview(spriteId, m_ClientId);
if (spritePreview != null)
{
m_SpritePreviews[index] = spritePreview;
m_SpritePreviewNeedFetching.RemoveAt(i);
}
else
{
m_SpritePreviews[index] = spriteLoadingThumbnail;
if (!InternalEditorBridge.IsLoadingAssetPreview(spriteId, m_ClientId))
m_SpritePreviewNeedFetching.RemoveAt(i);
}
}
}

return remainingPreviewCount != m_SpritePreviewNeedFetching.Count;
}
}
}
13 changes: 12 additions & 1 deletion IK/Editor/IKEditorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,18 @@ private void OnSceneGUI(SceneView sceneView)
foreach (var ikManager2D in m_IKManagers)
{
if (ikManager2D != null && ikManager2D.isActiveAndEnabled)
IKGizmos.instance.DoSolversGUI(ikManager2D);
{
if (!EditorSceneManager.IsPreviewSceneObject(ikManager2D))
{
if (PrefabStageUtility.GetCurrentPrefabStage() == null)
IKGizmos.instance.DoSolversGUI(ikManager2D);
}
else
{
if (PrefabStageUtility.GetCurrentPrefabStage()?.scene == ikManager2D.gameObject.scene)
IKGizmos.instance.DoSolversGUI(ikManager2D);
}
}
}

if (!IKGizmos.instance.isDragging && IsDraggingATool())
Expand Down
Loading

0 comments on commit c2a3a62

Please sign in to comment.