fix bug where hidden object didn't have the right z translation when finally shown
This commit is contained in:
parent
897180c51f
commit
c8810cbaa2
|
@ -104,18 +104,7 @@ namespace Bread2Unity
|
||||||
var spriteFrames = new List<ObjectReferenceKeyframe>();
|
var spriteFrames = new List<ObjectReferenceKeyframe>();
|
||||||
|
|
||||||
var currentTime = 0f;
|
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)
|
foreach (var currentStep in animation.Steps)
|
||||||
{
|
{
|
||||||
|
@ -196,8 +185,23 @@ namespace Bread2Unity
|
||||||
animationClip.SetCurve(child.name, typeof(SpriteRenderer), "m_FlipY", flipYCurve);
|
animationClip.SetCurve(child.name, typeof(SpriteRenderer), "m_FlipY", flipYCurve);
|
||||||
if ((from part in partsOfGameObject select part.RegionIndex.Index).Distinct().Count() > 1)
|
if ((from part in partsOfGameObject select part.RegionIndex.Index).Distinct().Count() > 1)
|
||||||
AnimationUtility.SetObjectReferenceCurve(animationClip, spriteBinding, spriteFrames.ToArray());
|
AnimationUtility.SetObjectReferenceCurve(animationClip, spriteBinding, spriteFrames.ToArray());
|
||||||
|
|
||||||
|
//Check if there is any need for z animation
|
||||||
|
var setOfZIndexes = new HashSet<float>();
|
||||||
|
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 ||
|
if ((from part in partsOfGameObject select part.PosX).Distinct().Count() > 1 ||
|
||||||
(from part in partsOfGameObject select part.PosY).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.TranslateX).Distinct().Count() > 1 ||
|
||||||
animation.Steps.Select(step => step.TranslateY).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.x", scaleXCurve);
|
||||||
animationClip.SetCurve(child.name, typeof(Transform), "localScale.y", scaleYCurve);
|
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
|
// 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));
|
.Any(step => !step.Color.Equals(Color.white));
|
||||||
if (colorChanges || partsOfGameObject.Select(part => part.Multicolor).Distinct().Count() > 1)
|
if (colorChanges || partsOfGameObject.Select(part => part.Multicolor).Distinct().Count() > 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,8 +39,10 @@ namespace Bread2Unity
|
||||||
_children.Add(child);
|
_children.Add(child);
|
||||||
RegionToChild.Add(part.RegionIndex, child);
|
RegionToChild.Add(part.RegionIndex, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all regions
|
// Get all regions
|
||||||
var anim = _data.Animations;
|
var anim = _data.Animations;
|
||||||
var bccadSprites = anim.SelectMany(a => a.Steps).Select(step => step.BccadSprite).Distinct().ToList();
|
var bccadSprites = anim.SelectMany(a => a.Steps).Select(step => step.BccadSprite).Distinct().ToList();
|
||||||
|
@ -81,7 +83,8 @@ namespace Bread2Unity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<RegionIndex> FindNotAdjacentRegions(List<RegionIndex> regions, List<BccadSprite> sprites, List<RegionIndex> availableRegions)
|
private static List<RegionIndex> FindNotAdjacentRegions(List<RegionIndex> regions, List<BccadSprite> sprites,
|
||||||
|
List<RegionIndex> availableRegions)
|
||||||
{
|
{
|
||||||
var notAdjacentRegions = new List<RegionIndex>(availableRegions);
|
var notAdjacentRegions = new List<RegionIndex>(availableRegions);
|
||||||
foreach (var sprite in sprites)
|
foreach (var sprite in sprites)
|
||||||
|
@ -94,7 +97,6 @@ namespace Bread2Unity
|
||||||
notAdjacentRegions.Remove(r);
|
notAdjacentRegions.Remove(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return notAdjacentRegions;
|
return notAdjacentRegions;
|
||||||
|
@ -103,7 +105,8 @@ namespace Bread2Unity
|
||||||
public List<Tuple<int, SpritePart, GameObject>> GetHiddenParts()
|
public List<Tuple<int, SpritePart, GameObject>> GetHiddenParts()
|
||||||
{
|
{
|
||||||
var sprite = _bccad.sprites[_data.SpriteIndex];
|
var sprite = _bccad.sprites[_data.SpriteIndex];
|
||||||
var pairs = new List<Tuple<int, SpritePart, GameObject>>();
|
// index, part, game object
|
||||||
|
var hiddenParts = new List<Tuple<int, SpritePart, GameObject>>();
|
||||||
var gameObjects = new List<GameObject>(_children);
|
var gameObjects = new List<GameObject>(_children);
|
||||||
foreach (var part in sprite.parts)
|
foreach (var part in sprite.parts)
|
||||||
{
|
{
|
||||||
|
@ -116,19 +119,16 @@ namespace Bread2Unity
|
||||||
//find a random part associated with the game object
|
//find a random part associated with the game object
|
||||||
var region = RegionToChild.FirstOrDefault(keyValuePair => keyValuePair.Value == gameObject)
|
var region = RegionToChild.FirstOrDefault(keyValuePair => keyValuePair.Value == gameObject)
|
||||||
.Key;
|
.Key;
|
||||||
var parts = _data.Animations.SelectMany(anim => anim.Steps).Select(s => s.BccadSprite)
|
var partIndexPairs = _data.Animations.SelectMany(anim => anim.Steps).Select(s => s.BccadSprite)
|
||||||
.SelectMany(bccadSprite => bccadSprite.parts);
|
.SelectMany(bccadSprite => bccadSprite.parts.Select((part, index) => new {part, index}));
|
||||||
|
|
||||||
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<int, SpritePart, GameObject>(index, part, gameObject));
|
|
||||||
|
|
||||||
|
// 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<int, SpritePart, GameObject>(partIndexPair.index, partIndexPair.part, gameObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
return pairs;
|
return hiddenParts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue