bread2unity BCCAD interpreter setup

This commit is contained in:
Braedon
2022-02-10 03:13:54 -05:00
parent 5dc432a9d9
commit 772ab2783c
19 changed files with 541 additions and 108 deletions

View File

@ -0,0 +1,94 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bread2Unity
{
public class BCCAD : IDataModel
{
public BCCAD Read(byte[] bytes)
{
sheetW = (ushort)bytes[4];
sheetH = (ushort)bytes[6];
ISprite spriteParts_ = new ISprite();
int max = (bytes[8] * 2) + 12;
int loopTimes = 0;
// this is pretty bad spaghetti code, and I wrote this when I had the flu at 3 AM. so you're welcome --Starpelly
for (int i = 12; i < max; i+=2) // 16 bit bytes, skip every 2nd byte
{
int ind = i + 4; // the first 4 contain the number of parts and an unknown number, I can skip these for now
ISpritePart part = new ISpritePart();
part.regionX = BitConverter.ToUInt16(bytes, ind + 0);
part.regionY = BitConverter.ToUInt16(bytes, ind + 2);
part.regionW = BitConverter.ToUInt16(bytes,ind + 4);
part.regionH = BitConverter.ToUInt16(bytes, ind + 6);
part.posX = BitConverter.ToInt16(bytes, ind + 8);
part.posY = BitConverter.ToInt16(bytes, ind + 10);
part.stretchX = BitConverter.ToSingle(bytes, ind + 12);
part.stretchY = BitConverter.ToSingle(bytes, ind + 14);
part.rotation = BitConverter.ToSingle(bytes, ind + 16);
part.flipX = bytes[ind + 18] != (byte)0;
part.flipY = bytes[ind + 20] != (byte)0;
// im sure the values between 20 and 28 are important so remind me to come back to these
part.opacity = bytes[ind + 28];
// Debug.Log(part.regionX);
spriteParts_.parts.Add(part);
int compare = 32;
if (loopTimes < 1)
{
compare = 32;
}
else if (loopTimes >= 1)
{
if (loopTimes % 2 == 0)
{
compare = 32;
}
else
{
compare = 34;
}
}
max += compare * 2;
i += compare * 2;
loopTimes++;
Debug.Log("offset: " + (ind + (compare - loopTimes + 1) * 2) + ", val: " + BitConverter.ToUInt16(bytes, (ind + (compare - loopTimes + 1) * 2)));
}
sprites.Add(spriteParts_);
return new BCCAD()
{
};
}
/// sprites length bytes start = 12
/// 20 = 1
/// 84 = 2
/// 152 = 3
/// 216 = 4
/// 284 - 5
///
///
/// 64
/// 64
/// -- Loop
/// 68
/// 64
/// 68
/// 64
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b4f0c7c12cfcc74bbfdc8c1be61d4b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
@ -27,11 +29,21 @@ namespace Bread2Unity
desc.wordWrap = true;
desc.fontStyle = FontStyle.BoldAndItalic;
GUILayout.Box("bread2unity is a tool built with the purpose of converting RH Megamix and Fever animations to unity. And to generally speed up development by a lot." +
"\nCreated by Starpelly.", desc);
GUILayout.Space(120);
if (GUILayout.Button("Test"))
{
string path = EditorUtility.OpenFilePanel("Open BCCAD File", null, "bccad");
if (path.Length != 0)
{
var fileContent = File.ReadAllBytes(path);
new BCCAD().Read(fileContent);
}
}
GUILayout.BeginHorizontal();
if (GUILayout.Button("Bread Download", GUILayout.Height(40)))
{

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4801a6826549d7d4a978c7387a1aa26a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bread2Unity
{
public class IAnimation
{
public List<IAnimationStep> steps;
}
public class IAnimationStep
{
public ushort spriteIndex;
public ushort delay;
public float stretchX;
public float stretchY;
public float rotation;
public byte opacity;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c33bcfd692627dd4a97ac1cd1d930420
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
namespace Bread2Unity
{
public class IDataModel
{
public List<ISprite> sprites = new List<ISprite>();
public List<IAnimation> animations = new List<IAnimation>();
public int sheetW;
public int sheetH;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ddf1fd563dabc6040a863537a081843a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
namespace Bread2Unity
{
public class ISprite
{
public List<ISpritePart> parts = new List<ISpritePart>();
}
public class ISpritePart
{
public ushort regionX;
public ushort regionY;
public ushort regionW;
public ushort regionH;
public short posX;
public short posY;
public float stretchX;
public float stretchY;
public float rotation;
public bool flipX;
public bool flipY;
public byte opacity;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d4aae79bea7b7234f9ce059ade5fce08
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: