add option to not rotate texture +
small ui enhancments
This commit is contained in:
parent
4e07a847ef
commit
1420bb04b5
|
@ -4,7 +4,6 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
using Bread2Unity;
|
using Bread2Unity;
|
||||||
|
|
||||||
namespace Bread2Unity
|
namespace Bread2Unity
|
||||||
|
@ -13,9 +12,10 @@ namespace Bread2Unity
|
||||||
{
|
{
|
||||||
public const string EditorFolderName = "bread2unity";
|
public const string EditorFolderName = "bread2unity";
|
||||||
private GameObject _prefab;
|
private GameObject _prefab;
|
||||||
private DataModel animation;
|
private DataModel _animation;
|
||||||
private List<PrefabData> _prefabDataList = new List<PrefabData>();
|
private List<PrefabData> _prefabDataList = new List<PrefabData>();
|
||||||
private List<string> _animationsIndexes;
|
private List<string> _animationsIndexes;
|
||||||
|
private bool shouldRotate = false;
|
||||||
private Vector2 _scrollPosition;
|
private Vector2 _scrollPosition;
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ namespace Bread2Unity
|
||||||
|
|
||||||
public void OnGUI()
|
public void OnGUI()
|
||||||
{
|
{
|
||||||
|
// Logo
|
||||||
Texture logo =
|
Texture logo =
|
||||||
(Texture)AssetDatabase.LoadAssetAtPath($"Assets/Editor/{EditorFolderName}/logo.png", typeof(Texture));
|
(Texture)AssetDatabase.LoadAssetAtPath($"Assets/Editor/{EditorFolderName}/logo.png", typeof(Texture));
|
||||||
GUILayout.Box(logo, GUILayout.ExpandWidth(true), GUILayout.Height(60));
|
GUILayout.Box(logo, GUILayout.ExpandWidth(true), GUILayout.Height(60));
|
||||||
|
@ -40,7 +41,7 @@ namespace Bread2Unity
|
||||||
GUIStyle desc = EditorStyles.label;
|
GUIStyle desc = EditorStyles.label;
|
||||||
desc.wordWrap = true;
|
desc.wordWrap = true;
|
||||||
desc.fontStyle = FontStyle.BoldAndItalic;
|
desc.fontStyle = FontStyle.BoldAndItalic;
|
||||||
|
// Description
|
||||||
GUILayout.Box(
|
GUILayout.Box(
|
||||||
"bread2unity is a tool built with the purpose of converting RH Megamix animations to unity. And to generally speed up development by a lot.",
|
"bread2unity is a tool built with the purpose of converting RH Megamix animations to unity. And to generally speed up development by a lot.",
|
||||||
desc);
|
desc);
|
||||||
|
@ -48,6 +49,7 @@ namespace Bread2Unity
|
||||||
GUILayout.Space(60);
|
GUILayout.Space(60);
|
||||||
EditorGUIUtility.labelWidth = 100;
|
EditorGUIUtility.labelWidth = 100;
|
||||||
|
|
||||||
|
// Prefab Selector
|
||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginHorizontal();
|
||||||
EditorGUILayout.PrefixLabel("Prefab");
|
EditorGUILayout.PrefixLabel("Prefab");
|
||||||
_prefab = (GameObject)EditorGUILayout.ObjectField(_prefab, typeof(GameObject), false);
|
_prefab = (GameObject)EditorGUILayout.ObjectField(_prefab, typeof(GameObject), false);
|
||||||
|
@ -55,6 +57,7 @@ namespace Bread2Unity
|
||||||
|
|
||||||
EditorGUILayout.Separator();
|
EditorGUILayout.Separator();
|
||||||
|
|
||||||
|
// Prefab data input
|
||||||
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, GUILayout.MaxHeight(60));
|
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, GUILayout.MaxHeight(60));
|
||||||
var plusGuiStyle = new GUIStyle(GUI.skin.button)
|
var plusGuiStyle = new GUIStyle(GUI.skin.button)
|
||||||
{
|
{
|
||||||
|
@ -88,15 +91,22 @@ namespace Bread2Unity
|
||||||
|
|
||||||
EditorGUILayout.Separator();
|
EditorGUILayout.Separator();
|
||||||
|
|
||||||
|
// Add line button
|
||||||
if (GUILayout.Button("+", plusGuiStyle, GUILayout.Height(40), GUILayout.Width(40)))
|
if (GUILayout.Button("+", plusGuiStyle, GUILayout.Height(40), GUILayout.Width(40)))
|
||||||
{
|
{
|
||||||
_prefabDataList.Add(new PrefabData("", 0));
|
_prefabDataList.Add(new PrefabData("", 0));
|
||||||
_animationsIndexes.Add("");
|
_animationsIndexes.Add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUILayout.Separator();
|
GUILayout.Space(12f);
|
||||||
|
|
||||||
if (GUILayout.Button("Create Prefabs (WIP)") && _prefab != null)
|
// Rotate check box
|
||||||
|
shouldRotate = GUILayout.Toggle(shouldRotate, "Rotate Spritesheet");
|
||||||
|
|
||||||
|
GUILayout.Space(12f);
|
||||||
|
|
||||||
|
// Create button
|
||||||
|
if (GUILayout.Button("Generate Assets") && _prefab != null)
|
||||||
{
|
{
|
||||||
//Choose png and bccad files
|
//Choose png and bccad files
|
||||||
var bccadFilePath = EditorUtility.OpenFilePanel("Open BCCAD File", null, "bccad");
|
var bccadFilePath = EditorUtility.OpenFilePanel("Open BCCAD File", null, "bccad");
|
||||||
|
@ -105,7 +115,7 @@ namespace Bread2Unity
|
||||||
if (bccadFilePath != null && pngFilePath != null)
|
if (bccadFilePath != null && pngFilePath != null)
|
||||||
{
|
{
|
||||||
var bccad = BCCAD.Read(File.ReadAllBytes(bccadFilePath));
|
var bccad = BCCAD.Read(File.ReadAllBytes(bccadFilePath));
|
||||||
var spriteTexture = SpriteCreator.ComputeSprites(bccad, pngFilePath, _prefab.name);
|
var spriteTexture = SpriteCreator.ComputeSprites(bccad, pngFilePath, _prefab.name, shouldRotate);
|
||||||
//Create prefab from prefab data
|
//Create prefab from prefab data
|
||||||
for (int i = 0; i < _prefabDataList.Count; i++)
|
for (int i = 0; i < _prefabDataList.Count; i++)
|
||||||
{
|
{
|
||||||
|
@ -123,11 +133,15 @@ namespace Bread2Unity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUILayout.Space(12f);
|
||||||
|
|
||||||
if (GUILayout.Button("bccad test"))
|
if (GUILayout.Button("bccad test"))
|
||||||
{
|
{
|
||||||
BccadTest.TestBccad();
|
BccadTest.TestBccad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUILayout.Space(12f);
|
||||||
|
|
||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginHorizontal();
|
||||||
if (GUILayout.Button("Bread Download", GUILayout.Height(40)))
|
if (GUILayout.Button("Bread Download", GUILayout.Height(40)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@ Rhythm Heaven animation to Unity animation converter
|
||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
|
|
||||||
- [ ] add option for rotate texture
|
- [X] add option for rotate texture
|
||||||
- [ ] remove npe (animationController)
|
- [ ] remove npe (animationController)
|
||||||
|
|
||||||
- [ ] change animations save location
|
- [ ] change animations save location
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace Bread2Unity
|
||||||
public class SpriteCreator : MonoBehaviour
|
public class SpriteCreator : MonoBehaviour
|
||||||
{
|
{
|
||||||
public const int PixelsPerUnit = 100;
|
public const int PixelsPerUnit = 100;
|
||||||
public static Texture2D ComputeSprites(BCCAD bccad, string texturePath, string prefabName)
|
public static Texture2D ComputeSprites(BCCAD bccad, string texturePath, string prefabName, bool shouldRotate = false)
|
||||||
{
|
{
|
||||||
var textureName = Path.GetFileName(texturePath);
|
var textureName = Path.GetFileName(texturePath);
|
||||||
var spritesFolder =
|
var spritesFolder =
|
||||||
|
@ -26,9 +26,9 @@ namespace Bread2Unity
|
||||||
$"{textureName}";
|
$"{textureName}";
|
||||||
var newTexture = new Texture2D(bccad.sheetW, bccad.sheetH);
|
var newTexture = new Texture2D(bccad.sheetW, bccad.sheetH);
|
||||||
newTexture.LoadImage(File.ReadAllBytes(texturePath));
|
newTexture.LoadImage(File.ReadAllBytes(texturePath));
|
||||||
var rotatedTexture = RotateTexture(newTexture);
|
var finalTexture = shouldRotate ? RotateTexture(newTexture) : newTexture;
|
||||||
rotatedTexture.name = textureName.Substring(0, textureName.Length - ".png".Length);
|
finalTexture.name = textureName.Substring(0, textureName.Length - ".png".Length);
|
||||||
File.WriteAllBytes(destTexturePath, rotatedTexture.EncodeToPNG());
|
File.WriteAllBytes(destTexturePath, finalTexture.EncodeToPNG());
|
||||||
AssetDatabase.ImportAsset(destTexturePath);
|
AssetDatabase.ImportAsset(destTexturePath);
|
||||||
var ti = AssetImporter.GetAtPath(destTexturePath) as TextureImporter;
|
var ti = AssetImporter.GetAtPath(destTexturePath) as TextureImporter;
|
||||||
|
|
||||||
|
@ -43,17 +43,17 @@ namespace Bread2Unity
|
||||||
ti.textureCompression = TextureImporterCompression.Uncompressed;
|
ti.textureCompression = TextureImporterCompression.Uncompressed;
|
||||||
var newData = new List<SpriteMetaData>();
|
var newData = new List<SpriteMetaData>();
|
||||||
var rectCtr = 0;
|
var rectCtr = 0;
|
||||||
var heightRatio = (float)rotatedTexture.height / bccad.sheetH;
|
var heightRatio = (float)finalTexture.height / bccad.sheetH;
|
||||||
var widthRatio = (float)rotatedTexture.width / bccad.sheetW;
|
var widthRatio = (float)finalTexture.width / bccad.sheetW;
|
||||||
foreach (var r in bccad.regions)
|
foreach (var r in bccad.regions)
|
||||||
{
|
{
|
||||||
var smd = new SpriteMetaData
|
var smd = new SpriteMetaData
|
||||||
{
|
{
|
||||||
pivot = new Vector2(0.5f, 0.5f),
|
pivot = new Vector2(0.5f, 0.5f),
|
||||||
alignment = 0,
|
alignment = 0,
|
||||||
name = rotatedTexture.name + "_" + rectCtr,
|
name = finalTexture.name + "_" + rectCtr,
|
||||||
rect = new Rect(r.regionX * widthRatio,
|
rect = new Rect(r.regionX * widthRatio,
|
||||||
rotatedTexture.height - (r.regionH + r.regionY) * heightRatio, r.regionW * widthRatio,
|
finalTexture.height - (r.regionH + r.regionY) * heightRatio, r.regionW * widthRatio,
|
||||||
r.regionH * heightRatio)
|
r.regionH * heightRatio)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ namespace Bread2Unity
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetDatabase.ImportAsset(destTexturePath, ImportAssetOptions.ForceUpdate);
|
AssetDatabase.ImportAsset(destTexturePath, ImportAssetOptions.ForceUpdate);
|
||||||
return rotatedTexture;
|
return finalTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Texture2D RotateTexture(Texture2D image)
|
public static Texture2D RotateTexture(Texture2D image)
|
||||||
|
|
Loading…
Reference in a new issue