- fixed bug when attempting to preview unsupported fonts

- added failsafe for ReadStringToNull
- added status messages for loading and previewing assets
This commit is contained in:
RaduMCosma 2015-11-03 14:59:26 +02:00
parent a9c8a4ab79
commit cdfcba78a9
5 changed files with 58 additions and 35 deletions

View File

@ -163,21 +163,24 @@ namespace Unity_Studio
public string ReadAlignedString(int length) public string ReadAlignedString(int length)
{ {
if (length > 0 && length < (base.BaseStream.Length - base.BaseStream.Position))//crude failsafe
byte[] stringData = new byte[length];
base.Read(stringData, 0, length);
var result = System.Text.Encoding.UTF8.GetString(stringData); //must verify strange characters in PS3
/*string result = "";
char c;
for (int i = 0; i < length; i++)
{ {
c = (char)base.ReadByte(); byte[] stringData = new byte[length];
result += c.ToString(); base.Read(stringData, 0, length);
}*/ var result = System.Text.Encoding.UTF8.GetString(stringData); //must verify strange characters in PS3
AlignStream(4); /*string result = "";
return result; char c;
for (int i = 0; i < length; i++)
{
c = (char)base.ReadByte();
result += c.ToString();
}*/
AlignStream(4);
return result;
}
else { return ""; }
} }
public string ReadStringToNull() public string ReadStringToNull()

View File

@ -81,11 +81,11 @@ So Unity adds a -90 degree rotation, similar to the FBX PreRotation, to bring th
Except it does it as a regular rotation, and combines it with any other rotations in the Transform asset. Except it does it as a regular rotation, and combines it with any other rotations in the Transform asset.
Converting from Unity back to FBX, the same vertex conversion cannot be applied because we have to take into account the rotation. Converting from Unity back to FBX, the same vertex conversion cannot be applied because we have to take into account the rotation.
Option 0: convert vertices and transformations as -X,Y,Z and set FBX option to Y-up without PreRotation! Option 0: export vertices and transformations as -X,Y,Z and set FBX option to Y-up without PreRotation!
the result will be Max Z = FBX Y, Max -Y = FBX Z, Max X = FBX X => final order -X -Z Y the result will be Max Z = FBX Y, Max -Y = FBX Z, Max X = FBX X => final order -X -Z Y
Option 1: convert vertices and transformations as -X,-Z,Y and set FBX options as "Z-up". Option 1: export vertices and transformations as -X,-Z,Y and set FBX options as "Z-up".
The -90 rotation exported from Unity will bring the model in correct orientation. The -90 rotation exported from Unity will bring the model in correct orientation.
Option 2: convert vertices and transformations as -X,-Y,-Z, add -90 PreRotation to every Mesh Node and set FBX options as "Y-up". Option 2: export vertices and transformations as -X,-Y,-Z, add -90 PreRotation to every Mesh Node and set FBX options as "Y-up".
The -90 rotation from Unity plus the -90 PreRotation will bring the model in correct orientation. The -90 rotation from Unity plus the -90 PreRotation will bring the model in correct orientation.
Remember though that the PreRotation is baked into the Geometry. Remember though that the PreRotation is baked into the Geometry.

View File

@ -39,7 +39,7 @@ namespace Unity_Studio
else if (sourceFile.version[0] == 3 && sourceFile.version[1] <= 4) { } else if (sourceFile.version[0] == 3 && sourceFile.version[1] <= 4) { }
else { int accelerometerFrequency = a_Stream.ReadInt32(); }//3.5.0 and up else { int accelerometerFrequency = a_Stream.ReadInt32(); }//3.5.0 and up
} }
//fail in Unity 5 beta
companyName = a_Stream.ReadAlignedString(a_Stream.ReadInt32()); companyName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
productName = a_Stream.ReadAlignedString(a_Stream.ReadInt32()); productName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
} }

View File

@ -100,6 +100,7 @@
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.saveFolderDialog1 = new System.Windows.Forms.SaveFileDialog(); this.saveFolderDialog1 = new System.Windows.Forms.SaveFileDialog();
this.treeTip = new System.Windows.Forms.ToolTip(this.components); this.treeTip = new System.Windows.Forms.ToolTip(this.components);
this.FMODcopyright = new System.Windows.Forms.Label();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
@ -552,6 +553,7 @@
// //
this.FMODpanel.Anchor = System.Windows.Forms.AnchorStyles.None; this.FMODpanel.Anchor = System.Windows.Forms.AnchorStyles.None;
this.FMODpanel.BackColor = System.Drawing.SystemColors.ControlDark; this.FMODpanel.BackColor = System.Drawing.SystemColors.ControlDark;
this.FMODpanel.Controls.Add(this.FMODcopyright);
this.FMODpanel.Controls.Add(this.FMODinfoLabel); this.FMODpanel.Controls.Add(this.FMODinfoLabel);
this.FMODpanel.Controls.Add(this.FMODtimerLabel); this.FMODpanel.Controls.Add(this.FMODtimerLabel);
this.FMODpanel.Controls.Add(this.FMODstatusLabel); this.FMODpanel.Controls.Add(this.FMODstatusLabel);
@ -801,6 +803,16 @@
this.saveFolderDialog1.RestoreDirectory = true; this.saveFolderDialog1.RestoreDirectory = true;
this.saveFolderDialog1.Title = "Browse for folder"; this.saveFolderDialog1.Title = "Browse for folder";
// //
// FMODcopyright
//
this.FMODcopyright.AutoSize = true;
this.FMODcopyright.ForeColor = System.Drawing.SystemColors.ControlLight;
this.FMODcopyright.Location = new System.Drawing.Point(117, 187);
this.FMODcopyright.Name = "FMODcopyright";
this.FMODcopyright.Size = new System.Drawing.Size(283, 13);
this.FMODcopyright.TabIndex = 9;
this.FMODcopyright.Text = "Audio Engine supplied by FMOD by Firelight Technologies.";
//
// UnityStudioForm // UnityStudioForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -917,6 +929,7 @@
private System.Windows.Forms.TextBox classTextBox; private System.Windows.Forms.TextBox classTextBox;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem exportClassStructuresMenuItem; private System.Windows.Forms.ToolStripMenuItem exportClassStructuresMenuItem;
private System.Windows.Forms.Label FMODcopyright;
} }
} }

View File

@ -609,7 +609,6 @@ namespace Unity_Studio
#region first loop - read asset data & create list #region first loop - read asset data & create list
if (!dontLoadAssetsMenuItem.Checked) if (!dontLoadAssetsMenuItem.Checked)
{ {
StatusStripUpdate("Building asset list...");
assetListView.BeginUpdate(); assetListView.BeginUpdate();
progressBar1.Value = 0; progressBar1.Value = 0;
progressBar1.Maximum = totalAssetCount; progressBar1.Maximum = totalAssetCount;
@ -618,6 +617,8 @@ namespace Unity_Studio
foreach (var assetsFile in assetsfileList) foreach (var assetsFile in assetsfileList)
{ {
StatusStripUpdate("Building asset list from " + Path.GetFileName(assetsFile.filePath));
var a_Stream = assetsFile.a_Stream; var a_Stream = assetsFile.a_Stream;
var fileGen = assetsFile.fileGen; var fileGen = assetsFile.fileGen;
//var m_version = assetsFile.m_version; //var m_version = assetsFile.m_version;
@ -764,13 +765,13 @@ namespace Unity_Studio
#region second loop - build tree structure #region second loop - build tree structure
if (!dontBuildHierarchyMenuItem.Checked) if (!dontBuildHierarchyMenuItem.Checked)
{ {
StatusStripUpdate("Building tree structure...");
sceneTreeView.BeginUpdate(); sceneTreeView.BeginUpdate();
progressBar1.Value = 0; progressBar1.Value = 0;
progressBar1.Maximum = totalTreeNodes; progressBar1.Maximum = totalTreeNodes;
foreach (var assetsFile in assetsfileList) foreach (var assetsFile in assetsfileList)
{ {
StatusStripUpdate("Building tree structure from " + Path.GetFileName(assetsFile.filePath));
GameObject fileNode = new GameObject(null); GameObject fileNode = new GameObject(null);
fileNode.Text = Path.GetFileName(assetsFile.filePath); fileNode.Text = Path.GetFileName(assetsFile.filePath);
@ -1049,6 +1050,7 @@ namespace Unity_Studio
fontPreviewBox.Visible = false; fontPreviewBox.Visible = false;
FMODpanel.Visible = false; FMODpanel.Visible = false;
lastLoadedAsset = null; lastLoadedAsset = null;
StatusStripUpdate("");
FMOD.RESULT result; FMOD.RESULT result;
if (sound != null) if (sound != null)
@ -1147,6 +1149,7 @@ namespace Unity_Studio
previewPanel.BackgroundImage = imageTexture; previewPanel.BackgroundImage = imageTexture;
previewPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; previewPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
} }
else { StatusStripUpdate("Unsupported image for preview. Try to export."); }
break; break;
} }
#endregion #endregion
@ -1202,7 +1205,7 @@ namespace Unity_Studio
ERRCHECK(result); ERRCHECK(result);
FMODinfoLabel.Text = FMODfrequency.ToString() + " Hz"; FMODinfoLabel.Text = FMODfrequency.ToString() + " Hz";
} }
else { StatusStripUpdate("Unsuported format"); } else { StatusStripUpdate("Unsuported audio format"); }
break; break;
} }
#endregion #endregion
@ -1225,7 +1228,7 @@ namespace Unity_Studio
{ {
unityFont m_Font = new unityFont(asset); unityFont m_Font = new unityFont(asset);
if (m_Font.extension != ".otf" && m_Font.m_FontData.Length > 0) if (m_Font.extension != ".otf" && m_Font.m_FontData != null)
{ {
IntPtr data = Marshal.AllocCoTaskMem(m_Font.m_FontData.Length); IntPtr data = Marshal.AllocCoTaskMem(m_Font.m_FontData.Length);
Marshal.Copy(m_Font.m_FontData, 0, data, m_Font.m_FontData.Length); Marshal.Copy(m_Font.m_FontData, 0, data, m_Font.m_FontData.Length);
@ -1266,6 +1269,7 @@ namespace Unity_Studio
fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 72, FontStyle.Regular); fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 72, FontStyle.Regular);
fontPreviewBox.Visible = true; fontPreviewBox.Visible = true;
} }
else { StatusStripUpdate("Unsupported font for preview. Try to export."); }
break; break;
} }
@ -2921,25 +2925,28 @@ namespace Unity_Studio
{ {
unityFont m_Font = new unityFont(asset); unityFont m_Font = new unityFont(asset);
string fontPath = exportPath + "\\" + asset.Text; if (m_Font.m_FontData != null)
if (uniqueNames.Checked) { fontPath += " #" + asset.uniqueID; }
fontPath += m_Font.extension;
if (File.Exists(fontPath))
{ {
StatusStripUpdate("Font file " + Path.GetFileName(fontPath) + " already exists"); string fontPath = exportPath + "\\" + asset.Text;
} if (uniqueNames.Checked) { fontPath += " #" + asset.uniqueID; }
else fontPath += m_Font.extension;
{
StatusStripUpdate("Exporting Font: " + Path.GetFileName(fontPath));
using (BinaryWriter writer = new BinaryWriter(File.Open(fontPath, FileMode.Create))) if (File.Exists(fontPath))
{ {
writer.Write(m_Font.m_FontData); StatusStripUpdate("Font file " + Path.GetFileName(fontPath) + " already exists");
writer.Close();
} }
else
{
StatusStripUpdate("Exporting Font: " + Path.GetFileName(fontPath));
exportCount += 1; using (BinaryWriter writer = new BinaryWriter(File.Open(fontPath, FileMode.Create)))
{
writer.Write(m_Font.m_FontData);
writer.Close();
}
exportCount += 1;
}
} }
break; break;
} }