From c8810cbaa2fca7e4050477b0a066fe0b44ea1f21 Mon Sep 17 00:00:00 2001 From: EliyaFishman <45822259+EliyaFishman@users.noreply.github.com> Date: Mon, 5 Dec 2022 20:52:52 +0200 Subject: [PATCH] fix bug where hidden object didn't have the right z translation when finally shown --- .../AssetGenerators/AnimationCreator.cs | 31 +++++++++++-------- .../AssetGenerators/BccadPrefab.cs | 26 ++++++++-------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Assets/Editor/bread2unity/AssetGenerators/AnimationCreator.cs b/Assets/Editor/bread2unity/AssetGenerators/AnimationCreator.cs index 8ae5074a2..31c356cad 100644 --- a/Assets/Editor/bread2unity/AssetGenerators/AnimationCreator.cs +++ b/Assets/Editor/bread2unity/AssetGenerators/AnimationCreator.cs @@ -104,18 +104,7 @@ namespace Bread2Unity var spriteFrames = new List(); var currentTime = 0f; - // Check to see if we need to animate colors - foreach (var step in animation.Steps) - { - var sprite = step.BccadSprite; - foreach (var part in sprite.parts) - { - if (!partsOfGameObject.Contains(part)) - continue; - var color = part.Multicolor * step.Color; - } - } foreach (var currentStep in animation.Steps) { @@ -196,8 +185,23 @@ namespace Bread2Unity animationClip.SetCurve(child.name, typeof(SpriteRenderer), "m_FlipY", flipYCurve); if ((from part in partsOfGameObject select part.RegionIndex.Index).Distinct().Count() > 1) AnimationUtility.SetObjectReferenceCurve(animationClip, spriteBinding, spriteFrames.ToArray()); + + //Check if there is any need for z animation + var setOfZIndexes = new HashSet(); + foreach (var sprite in spritesAssociatedWithPrefab) + { + for (int i = 0; i < sprite.parts.Count && setOfZIndexes.Count < 2; i++) + { + var part = sprite.parts[i]; + if(bccadPrefab.RegionToChild[part.RegionIndex] != child) + continue; + setOfZIndexes.Add(i); + } + } + if ((from part in partsOfGameObject select part.PosX).Distinct().Count() > 1 || (from part in partsOfGameObject select part.PosY).Distinct().Count() > 1 || + setOfZIndexes.Count > 1 || animation.Steps.Select(step => step.TranslateX).Distinct().Count() > 1 || animation.Steps.Select(step => step.TranslateY).Distinct().Count() > 1) { @@ -217,9 +221,10 @@ namespace Bread2Unity animationClip.SetCurve(child.name, typeof(Transform), "localScale.x", scaleXCurve); animationClip.SetCurve(child.name, typeof(Transform), "localScale.y", scaleYCurve); } - + // We check if any of the steps color that have the game object is not white - var colorChanges = animation.Steps.Where(step => step.BccadSprite.parts.Any(part => partsOfGameObject.Contains(part))) + var colorChanges = animation.Steps + .Where(step => step.BccadSprite.parts.Any(part => partsOfGameObject.Contains(part))) .Any(step => !step.Color.Equals(Color.white)); if (colorChanges || partsOfGameObject.Select(part => part.Multicolor).Distinct().Count() > 1) { diff --git a/Assets/Editor/bread2unity/AssetGenerators/BccadPrefab.cs b/Assets/Editor/bread2unity/AssetGenerators/BccadPrefab.cs index e9d38a227..30ec32aeb 100644 --- a/Assets/Editor/bread2unity/AssetGenerators/BccadPrefab.cs +++ b/Assets/Editor/bread2unity/AssetGenerators/BccadPrefab.cs @@ -39,8 +39,10 @@ namespace Bread2Unity _children.Add(child); RegionToChild.Add(part.RegionIndex, child); } + return; } + // Get all regions var anim = _data.Animations; var bccadSprites = anim.SelectMany(a => a.Steps).Select(step => step.BccadSprite).Distinct().ToList(); @@ -81,7 +83,8 @@ namespace Bread2Unity } } - private static List FindNotAdjacentRegions(List regions, List sprites, List availableRegions) + private static List FindNotAdjacentRegions(List regions, List sprites, + List availableRegions) { var notAdjacentRegions = new List(availableRegions); foreach (var sprite in sprites) @@ -94,7 +97,6 @@ namespace Bread2Unity notAdjacentRegions.Remove(r); } } - } return notAdjacentRegions; @@ -103,7 +105,8 @@ namespace Bread2Unity public List> GetHiddenParts() { var sprite = _bccad.sprites[_data.SpriteIndex]; - var pairs = new List>(); + // index, part, game object + var hiddenParts = new List>(); var gameObjects = new List(_children); foreach (var part in sprite.parts) { @@ -116,19 +119,16 @@ namespace Bread2Unity //find a random part associated with the game object var region = RegionToChild.FirstOrDefault(keyValuePair => keyValuePair.Value == gameObject) .Key; - var parts = _data.Animations.SelectMany(anim => anim.Steps).Select(s => s.BccadSprite) - .SelectMany(bccadSprite => bccadSprite.parts); - - var partIndexPair = parts - .Select((value, index) => new { value, index }) - .First(pair => pair.value.RegionIndex.Equals(region)); - var index = partIndexPair.index; - var part = partIndexPair.value; - pairs.Add(new Tuple(index, part, gameObject)); + var partIndexPairs = _data.Animations.SelectMany(anim => anim.Steps).Select(s => s.BccadSprite) + .SelectMany(bccadSprite => bccadSprite.parts.Select((part, index) => new {part, index})); + // Get the first possible part that the game object can have. + var partIndexPair = partIndexPairs + .First(pair => pair.part.RegionIndex.Equals(region)); + hiddenParts.Add(new Tuple(partIndexPair.index, partIndexPair.part, gameObject)); } - return pairs; + return hiddenParts; } } } \ No newline at end of file