Add color animations + small color enhancements.
This commit is contained in:
parent
a4a0b31c47
commit
f24407c92f
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using Bread2Unity;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
using UnityEditor.Graphs;
|
||||
using UnityEngine;
|
||||
using Animation = Bread2Unity.Animation;
|
||||
|
||||
|
@ -96,13 +97,28 @@ namespace Bread2Unity
|
|||
var scaleXCurve = new BccadCurve();
|
||||
var scaleYCurve = new BccadCurve();
|
||||
|
||||
var rColorCurve = new BccadCurve();
|
||||
var gColorCurve = new BccadCurve();
|
||||
var bColorCurve = new BccadCurve();
|
||||
var opacityCurve = new BccadCurve();
|
||||
var spriteFrames = new List<ObjectReferenceKeyframe>();
|
||||
|
||||
var currentTime = 0f;
|
||||
// Check to see if we need to animate colors
|
||||
|
||||
for (int stepIndex = 0; stepIndex < animation.Steps.Count; stepIndex++)
|
||||
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)
|
||||
{
|
||||
var currentStep = animation.Steps[stepIndex];
|
||||
var bccadSprite = currentStep.BccadSprite;
|
||||
// Find the index of part of the game object
|
||||
var partIndex = bccadSprite.parts.Select((value, index) => new { value, index })
|
||||
|
@ -121,7 +137,7 @@ namespace Bread2Unity
|
|||
var height = bccadSpritePart.StretchY / bccadPrefab.HeightRatio;
|
||||
var x = (bccadSpritePart.PosX + currentStep.TranslateX - 512f) /
|
||||
SpriteCreator.PixelsPerUnit + sprite.bounds.size.x * 0.5f * width;
|
||||
var y = -(bccadSpritePart.PosY + currentStep.TranslateY- 512f) / SpriteCreator.PixelsPerUnit -
|
||||
var y = -(bccadSpritePart.PosY + currentStep.TranslateY - 512f) / SpriteCreator.PixelsPerUnit -
|
||||
sprite.bounds.size.y * 0.5f * height;
|
||||
var z = -0.00001f * partIndex;
|
||||
|
||||
|
@ -146,6 +162,12 @@ namespace Bread2Unity
|
|||
flipYCurve.AddKey(currentTime, bccadSpritePart.FlipY ? 1 : 0);
|
||||
|
||||
rotationCurve.AddKey(currentTime, -bccadSpritePart.Rotation);
|
||||
|
||||
var color = bccadSpritePart.Multicolor * currentStep.Color;
|
||||
rColorCurve.AddKey(currentTime, color.r);
|
||||
gColorCurve.AddKey(currentTime, color.g);
|
||||
bColorCurve.AddKey(currentTime, color.b);
|
||||
opacityCurve.AddKey(currentTime, color.a);
|
||||
}
|
||||
|
||||
// Increase the time for the next frame
|
||||
|
@ -195,6 +217,17 @@ 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)))
|
||||
.Any(step => !step.Color.Equals(Color.white));
|
||||
if (colorChanges || partsOfGameObject.Select(part => part.Multicolor).Distinct().Count() > 1)
|
||||
{
|
||||
animationClip.SetCurve(child.name, typeof(SpriteRenderer), "m_Color.r", rColorCurve);
|
||||
animationClip.SetCurve(child.name, typeof(SpriteRenderer), "m_Color.g", gColorCurve);
|
||||
animationClip.SetCurve(child.name, typeof(SpriteRenderer), "m_Color.b", bColorCurve);
|
||||
animationClip.SetCurve(child.name, typeof(SpriteRenderer), "m_Color.a", opacityCurve);
|
||||
}
|
||||
}
|
||||
|
||||
animationClip.frameRate = 30; //fps
|
||||
|
|
|
@ -56,8 +56,8 @@ namespace Bread2Unity
|
|||
var spriteRenderer = (SpriteRenderer)gameObjectPart.AddComponent(typeof(SpriteRenderer));
|
||||
|
||||
spriteRenderer.sprite = sprite;
|
||||
spriteRenderer.color = spritePart.GetColor();
|
||||
spriteRenderer.flipX = spritePart.FlipX;
|
||||
spriteRenderer.color = spritePart.Multicolor;
|
||||
spriteRenderer.flipY = spritePart.FlipY;
|
||||
spriteRenderer.enabled = true;
|
||||
gameObjectPart.transform.SetParent(prefab.ParentObject.transform);
|
||||
|
|
|
@ -60,7 +60,8 @@ namespace Bread2Unity
|
|||
Convert.ToInt32(byteBuffer.ReadByte() & 0xff) / 255f,
|
||||
Convert.ToInt32(byteBuffer.ReadByte() & 0xff) / 255f);
|
||||
|
||||
part.Opacity = byteBuffer.ReadByte();
|
||||
part.Multicolor.a = byteBuffer.ReadByte() / 255f;
|
||||
|
||||
for (int k = 0; k < 12; k++)
|
||||
{
|
||||
byteBuffer.ReadByte();
|
||||
|
@ -118,7 +119,7 @@ namespace Bread2Unity
|
|||
byteBuffer.ReadByte();
|
||||
byteBuffer.ReadByte();
|
||||
byteBuffer.ReadByte();
|
||||
step.Opacity = Convert.ToByte(Convert.ToInt32(byteBuffer.ReadShort()) & 0xFF);
|
||||
step.Color.a = Convert.ToInt32(byteBuffer.ReadShort() & 0xFF) / 255f;
|
||||
anim.Steps.Add(step);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ namespace Bread2Unity
|
|||
public bool FlipX;
|
||||
public bool FlipY;
|
||||
|
||||
public byte Opacity;
|
||||
|
||||
public byte designation;
|
||||
public short unknown;
|
||||
|
@ -35,7 +34,7 @@ namespace Bread2Unity
|
|||
public float brDepth;
|
||||
public Color Multicolor;
|
||||
public Color ScreenColor;
|
||||
public Color GetColor() => new Color(Multicolor.r, Multicolor.g, Multicolor.b, Opacity / 255f);
|
||||
// public Color GetColor() => new Color(Multicolor.r, Multicolor.g, Multicolor.b, Multicolor.a);
|
||||
}
|
||||
|
||||
public struct RegionIndex
|
||||
|
|
Loading…
Reference in a new issue