3 Commits

Author SHA1 Message Date
RaduMCosma
2c94852939 - added exception to skip preview of unsupported audio clips
- fixed a feature that automatically resizes asset Type and Size columns by content
- fixed sorting issue when loading a new file/folder
- asset list is now sorted by 2 columns, first by the column you click, then by the column you previously clicked
2015-11-04 14:16:03 +02:00
RaduMCosma
5ba447aba2 Merge branch 'master' of https://github.com/RaduMC/UnityStudio.git 2015-11-03 14:59:32 +02:00
RaduMCosma
cdfcba78a9 - fixed bug when attempting to preview unsupported fonts
- added failsafe for ReadStringToNull
- added status messages for loading and previewing assets
2015-11-03 14:59:26 +02:00
6 changed files with 174 additions and 123 deletions

View File

@@ -105,6 +105,10 @@ namespace Unity_Studio
extension = ".fsb";
preloadData.InfoText += "FSB";
break;
case 2://FSB5
extension = ".fsb";
preloadData.InfoText += "FSB";
break;
case 13:
extension = ".mp3";
preloadData.InfoText += "MP3";

View File

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

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.
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
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.
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.
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 { int accelerometerFrequency = a_Stream.ReadInt32(); }//3.5.0 and up
}
//fail in Unity 5 beta
companyName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
productName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
}

View File

@@ -62,7 +62,6 @@
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.sceneTreeView = new Unity_Studio.GOHierarchy();
this.treeSearch = new System.Windows.Forms.TextBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.assetListView = new System.Windows.Forms.ListView();
@@ -75,6 +74,7 @@
this.previewPanel = new System.Windows.Forms.Panel();
this.assetInfoLabel = new System.Windows.Forms.Label();
this.FMODpanel = new System.Windows.Forms.Panel();
this.FMODcopyright = new System.Windows.Forms.Label();
this.FMODinfoLabel = new System.Windows.Forms.Label();
this.FMODtimerLabel = new System.Windows.Forms.Label();
this.FMODstatusLabel = new System.Windows.Forms.Label();
@@ -100,6 +100,7 @@
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.saveFolderDialog1 = new System.Windows.Forms.SaveFileDialog();
this.treeTip = new System.Windows.Forms.ToolTip(this.components);
this.sceneTreeView = new Unity_Studio.GOHierarchy();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
@@ -390,8 +391,6 @@
this.splitContainer1.SplitterDistance = 420;
this.splitContainer1.TabIndex = 2;
this.splitContainer1.TabStop = false;
this.splitContainer1.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.splitContainer1_SplitterMoved);
this.splitContainer1.Resize += new System.EventHandler(this.splitContainer1_Resize);
//
// tabControl1
//
@@ -418,17 +417,6 @@
this.tabPage1.Text = "Scene Hierarchy";
this.tabPage1.UseVisualStyleBackColor = true;
//
// sceneTreeView
//
this.sceneTreeView.CheckBoxes = true;
this.sceneTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
this.sceneTreeView.HideSelection = false;
this.sceneTreeView.Location = new System.Drawing.Point(0, 20);
this.sceneTreeView.Name = "sceneTreeView";
this.sceneTreeView.Size = new System.Drawing.Size(410, 588);
this.sceneTreeView.TabIndex = 1;
this.sceneTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.sceneTreeView_AfterCheck);
//
// treeSearch
//
this.treeSearch.Dock = System.Windows.Forms.DockStyle.Top;
@@ -454,6 +442,7 @@
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Asset List";
this.tabPage2.UseVisualStyleBackColor = true;
this.tabPage2.Resize += new System.EventHandler(this.tabPage2_Resize);
//
// assetListView
//
@@ -490,6 +479,7 @@
// columnHeaderSize
//
this.columnHeaderSize.Text = "Size";
this.columnHeaderSize.Width = 23;
//
// listSearch
//
@@ -552,6 +542,7 @@
//
this.FMODpanel.Anchor = System.Windows.Forms.AnchorStyles.None;
this.FMODpanel.BackColor = System.Drawing.SystemColors.ControlDark;
this.FMODpanel.Controls.Add(this.FMODcopyright);
this.FMODpanel.Controls.Add(this.FMODinfoLabel);
this.FMODpanel.Controls.Add(this.FMODtimerLabel);
this.FMODpanel.Controls.Add(this.FMODstatusLabel);
@@ -567,6 +558,16 @@
this.FMODpanel.TabIndex = 2;
this.FMODpanel.Visible = false;
//
// 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.";
//
// FMODinfoLabel
//
this.FMODinfoLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
@@ -801,6 +802,17 @@
this.saveFolderDialog1.RestoreDirectory = true;
this.saveFolderDialog1.Title = "Browse for folder";
//
// sceneTreeView
//
this.sceneTreeView.CheckBoxes = true;
this.sceneTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
this.sceneTreeView.HideSelection = false;
this.sceneTreeView.Location = new System.Drawing.Point(0, 20);
this.sceneTreeView.Name = "sceneTreeView";
this.sceneTreeView.Size = new System.Drawing.Size(410, 588);
this.sceneTreeView.TabIndex = 1;
this.sceneTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.sceneTreeView_AfterCheck);
//
// UnityStudioForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -917,6 +929,7 @@
private System.Windows.Forms.TextBox classTextBox;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem exportClassStructuresMenuItem;
private System.Windows.Forms.Label FMODcopyright;
}
}

View File

@@ -14,10 +14,9 @@ using Tao.DevIl;
using System.Web.Script.Serialization;
//Load parent nodes even if they are not selected to provide transformations?
//For extracting bundles, first check if file exists then decompress
//rigurous search for search files; look into Path.Combine
/*TODO
Load parent nodes even if they are not selected to provide transformations?
For extracting bundles, first check if file exists then decompress*/
namespace Unity_Studio
{
@@ -25,8 +24,8 @@ namespace Unity_Studio
{
private List<string> unityFiles = new List<string>(); //files to load
public static List<AssetsFile> assetsfileList = new List<AssetsFile>(); //loaded files
private List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>(); //used to hold all listItems while the list is being filtered
private List<AssetPreloadData> visibleAssets = new List<AssetPreloadData>(); //used to build the listView
private List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>(); //used to hold all assets while the ListView is filtered
private List<AssetPreloadData> visibleAssets = new List<AssetPreloadData>(); //used to build the ListView from all or filtered assets
private AssetPreloadData lastSelectedItem = null;
private AssetPreloadData lastLoadedAsset = null;
//private AssetsFile mainDataFile = null;
@@ -40,7 +39,6 @@ namespace Unity_Studio
private FMOD.Sound sound = null;
private FMOD.Channel channel = null;
private FMOD.SoundGroup masterSoundGroup = null;
private FMOD.MODE loopMode = FMOD.MODE.LOOP_OFF;
private uint FMODlenms = 0;
private float FMODVolume = 0.8f;
@@ -48,10 +46,11 @@ namespace Unity_Studio
private Bitmap imageTexture = null;
private bool startFilter = false;
private bool isNameSorted = false;
private bool isTypeSorted = false;
private bool isSizeSorted = false;
//asset list sortign helpers
private int firstSortColumn = -1;
private int secondSortColumn = 0;
private bool reverseSort = false;
private bool enableFiltering = false;
//tree search
private int nextGObject = 0;
@@ -609,7 +608,6 @@ namespace Unity_Studio
#region first loop - read asset data & create list
if (!dontLoadAssetsMenuItem.Checked)
{
StatusStripUpdate("Building asset list...");
assetListView.BeginUpdate();
progressBar1.Value = 0;
progressBar1.Maximum = totalAssetCount;
@@ -618,6 +616,8 @@ namespace Unity_Studio
foreach (var assetsFile in assetsfileList)
{
StatusStripUpdate("Building asset list from " + Path.GetFileName(assetsFile.filePath));
var a_Stream = assetsFile.a_Stream;
var fileGen = assetsFile.fileGen;
//var m_version = assetsFile.m_version;
@@ -752,9 +752,10 @@ namespace Unity_Studio
visibleAssets = exportableAssets;
assetListView.VirtualListSize = visibleAssets.Count;
assetListView.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
resizeNameColumn();
//won't work because ListView is not visible
//assetListView.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
//assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
//resizeAssetListColumns();
assetListView.EndUpdate();
progressBar1.Value = 0;
@@ -764,13 +765,13 @@ namespace Unity_Studio
#region second loop - build tree structure
if (!dontBuildHierarchyMenuItem.Checked)
{
StatusStripUpdate("Building tree structure...");
sceneTreeView.BeginUpdate();
progressBar1.Value = 0;
progressBar1.Maximum = totalTreeNodes;
foreach (var assetsFile in assetsfileList)
{
StatusStripUpdate("Building tree structure from " + Path.GetFileName(assetsFile.filePath));
GameObject fileNode = new GameObject(null);
fileNode.Text = Path.GetFileName(assetsFile.filePath);
@@ -867,6 +868,7 @@ namespace Unity_Studio
{
case 0: treeSearch.Select(); break;
case 1:
resizeAssetListColumns(); //required because the ListView is not visible on app launch
classPreviewPanel.Visible = false;
previewPanel.Visible = true;
listSearch.Select();
@@ -965,9 +967,62 @@ namespace Unity_Studio
}
private void resizeAssetListColumns()
{
assetListView.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.HeaderSize);
assetListView.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.HeaderSize);
assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
var test = SystemInformation.VerticalScrollBarWidth;
var vscroll = ((float)visibleAssets.Count / (float)assetListView.Height) > 0.0567f;
columnHeaderName.Width = assetListView.Width - columnHeaderType.Width - columnHeaderSize.Width - (vscroll ? 25 : 5);
}
private void tabPage2_Resize(object sender, EventArgs e)
{
resizeAssetListColumns();
}
/*private void splitContainer1_Resize(object sender, EventArgs e)
{
switch (tabControl1.SelectedIndex)
{
case 1: resizeAssetListColumns(); break;
}
}
private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
{
switch (tabControl1.SelectedIndex)
{
case 1: resizeAssetListColumns(); break;
}
}*/
private void listSearch_Enter(object sender, EventArgs e)
{
if (listSearch.Text == " Filter ")
{
listSearch.Text = "";
listSearch.ForeColor = System.Drawing.SystemColors.WindowText;
enableFiltering = true;
}
}
private void listSearch_Leave(object sender, EventArgs e)
{
if (listSearch.Text == "")
{
enableFiltering = false;
listSearch.Text = " Filter ";
listSearch.ForeColor = System.Drawing.SystemColors.GrayText;
}
}
private void ListSearchTextChanged(object sender, EventArgs e)
{
if (startFilter)
if (enableFiltering)
{
assetListView.BeginUpdate();
assetListView.SelectedIndices.Clear();
@@ -978,65 +1033,49 @@ namespace Unity_Studio
}
}
private void listSearch_Enter(object sender, EventArgs e)
{
if (listSearch.Text == " Filter ")
{
listSearch.Text = "";
listSearch.ForeColor = System.Drawing.SystemColors.WindowText;
startFilter = true;
}
}
private void listSearch_Leave(object sender, EventArgs e)
{
if (listSearch.Text == "")
{
startFilter = false;
listSearch.Text = " Filter ";
listSearch.ForeColor = System.Drawing.SystemColors.GrayText;
}
}
private void assetListView_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (firstSortColumn != e.Column)
{
reverseSort = false;
secondSortColumn = firstSortColumn;
}
else { reverseSort = !reverseSort; }
firstSortColumn = e.Column;
assetListView.BeginUpdate();
assetListView.SelectedIndices.Clear();
switch (e.Column)
{
case 0:
if (isNameSorted) { visibleAssets.Reverse(); }
else
visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b)
{
visibleAssets.Sort((x, y) => x.Text.CompareTo(y.Text));
isNameSorted = true;
}
int xdiff = reverseSort ? b.Text.CompareTo(a.Text) : a.Text.CompareTo(b.Text);
if (xdiff != 0) return xdiff;
else return secondSortColumn == 1 ? a.TypeString.CompareTo(b.TypeString) : a.exportSize.CompareTo(b.exportSize);
});
break;
case 1:
if (isTypeSorted) { visibleAssets.Reverse(); }
else
visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b)
{
visibleAssets.Sort((x, y) => x.TypeString.CompareTo(y.TypeString));
isTypeSorted = true;
}
int xdiff = reverseSort ? b.TypeString.CompareTo(a.TypeString) : a.TypeString.CompareTo(b.TypeString);
if (xdiff != 0) return xdiff;
else return secondSortColumn == 2 ? a.exportSize.CompareTo(b.exportSize) : a.Text.CompareTo(b.Text);
});
break;
case 2:
if (isSizeSorted) { visibleAssets.Reverse(); }
else
visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b)
{
visibleAssets.Sort((x, y) => x.exportSize.CompareTo(y.exportSize));
isSizeSorted = true;
}
int xdiff = reverseSort ? b.exportSize.CompareTo(a.exportSize) : a.exportSize.CompareTo(b.exportSize);
if (xdiff != 0) return xdiff;
else return secondSortColumn == 1 ? a.TypeString.CompareTo(b.TypeString) : a.Text.CompareTo(b.Text);
});
break;
}
assetListView.EndUpdate();
}
private void resizeNameColumn()
{
var vscroll = ((float)assetListView.VirtualListSize / (float)assetListView.Height) > 0.0567f;
columnHeaderName.Width = assetListView.Width - columnHeaderType.Width - columnHeaderSize.Width - (vscroll ? 25 : 5);
resizeAssetListColumns();
}
private void selectAsset(object sender, ListViewItemSelectionChangedEventArgs e)
@@ -1049,6 +1088,7 @@ namespace Unity_Studio
fontPreviewBox.Visible = false;
FMODpanel.Visible = false;
lastLoadedAsset = null;
StatusStripUpdate("");
FMOD.RESULT result;
if (sound != null)
@@ -1088,23 +1128,6 @@ namespace Unity_Studio
}
private void splitContainer1_Resize(object sender, EventArgs e)
{
switch (tabControl1.TabIndex)
{
case 1: resizeNameColumn(); break;
}
}
private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
{
switch (tabControl1.TabIndex)
{
case 1: resizeNameColumn(); break;
}
}
private void PreviewAsset(AssetPreloadData asset)
{
switch (asset.Type2)
@@ -1147,6 +1170,7 @@ namespace Unity_Studio
previewPanel.BackgroundImage = imageTexture;
previewPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
}
else { StatusStripUpdate("Unsupported image for preview. Try to export."); }
break;
}
#endregion
@@ -1155,7 +1179,7 @@ namespace Unity_Studio
{
AudioClip m_AudioClip = new AudioClip(asset, true);
if (m_AudioClip.m_Type != 22 && m_AudioClip.m_Type != 1)
if (m_AudioClip.m_Type == 13 && m_AudioClip.m_Type == 14 && m_AudioClip.m_Type == 20)
{
//MemoryStream memoryStream = new MemoryStream(m_AudioData, true);
//System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(memoryStream);
@@ -1202,7 +1226,7 @@ namespace Unity_Studio
ERRCHECK(result);
FMODinfoLabel.Text = FMODfrequency.ToString() + " Hz";
}
else { StatusStripUpdate("Unsuported format"); }
else { StatusStripUpdate("Unsuported audio format"); }
break;
}
#endregion
@@ -1225,7 +1249,7 @@ namespace Unity_Studio
{
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);
Marshal.Copy(m_Font.m_FontData, 0, data, m_Font.m_FontData.Length);
@@ -1266,6 +1290,7 @@ namespace Unity_Studio
fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 72, FontStyle.Regular);
fontPreviewBox.Visible = true;
}
else { StatusStripUpdate("Unsupported font for preview. Try to export."); }
break;
}
@@ -2921,25 +2946,28 @@ namespace Unity_Studio
{
unityFont m_Font = new unityFont(asset);
string fontPath = exportPath + "\\" + asset.Text;
if (uniqueNames.Checked) { fontPath += " #" + asset.uniqueID; }
fontPath += m_Font.extension;
if (File.Exists(fontPath))
if (m_Font.m_FontData != null)
{
StatusStripUpdate("Font file " + Path.GetFileName(fontPath) + " already exists");
}
else
{
StatusStripUpdate("Exporting Font: " + Path.GetFileName(fontPath));
string fontPath = exportPath + "\\" + asset.Text;
if (uniqueNames.Checked) { fontPath += " #" + asset.uniqueID; }
fontPath += m_Font.extension;
using (BinaryWriter writer = new BinaryWriter(File.Open(fontPath, FileMode.Create)))
if (File.Exists(fontPath))
{
writer.Write(m_Font.m_FontData);
writer.Close();
StatusStripUpdate("Font file " + Path.GetFileName(fontPath) + " already exists");
}
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;
}
@@ -3023,7 +3051,6 @@ namespace Unity_Studio
enablePreview.Checked = (bool)Properties.Settings.Default["enablePreview"];
openAfterExport.Checked = (bool)Properties.Settings.Default["openAfterExport"];
assetGroupOptions.SelectedIndex = (int)Properties.Settings.Default["assetGroupOption"];
resizeNameColumn();
}
private void resetForm()
@@ -3057,6 +3084,10 @@ namespace Unity_Studio
fontPreviewBox.Visible = false;
lastSelectedItem = null;
lastLoadedAsset = null;
firstSortColumn = -1;
secondSortColumn = 0;
reverseSort = false;
enableFiltering = false;
FMODinit();