Tidy up a part of the code

This commit is contained in:
Perfare 2017-02-12 04:57:24 +08:00
parent b580b293f3
commit 16ed347a30
14 changed files with 299 additions and 318 deletions

View File

@ -175,11 +175,11 @@ namespace Unity_Studio
preloadData.extension = ".AudioClip"; preloadData.extension = ".AudioClip";
preloadData.InfoText += "Unknown"; preloadData.InfoText += "Unknown";
} }
preloadData.InfoText += "\n3D: " + m_3D.ToString(); preloadData.InfoText += "\n3D: " + m_3D;
if (m_Name != "") { preloadData.Text = m_Name; } if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, preloadData.Size.ToString() }); preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
} }
} }
} }

View File

@ -188,7 +188,7 @@ namespace Unity_Studio
{ {
if (m_Name != "") { preloadData.Text = m_Name; } if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, preloadData.Size.ToString() }); preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
} }
} }
} }

View File

@ -161,7 +161,7 @@ namespace Unity_Studio
{ {
public int m_NumItems; public int m_NumItems;
public float m_Range = 1.0f; public float m_Range = 1.0f;
public float m_Start = 0.0f; public float m_Start;
public byte[] m_Data; public byte[] m_Data;
public byte m_BitSize; public byte m_BitSize;
} }
@ -174,7 +174,7 @@ namespace Unity_Studio
switch (inputBytes.Length) switch (inputBytes.Length)
{ {
case 1: case 1:
result = (float)inputBytes[0] / 255.0f; result = inputBytes[0] / 255.0f;
break; break;
case 2: case 2:
result = Half.ToHalf(inputBytes, 0); result = Half.ToHalf(inputBytes, 0);
@ -204,7 +204,7 @@ namespace Unity_Studio
} }
int groupSize = pakData.m_BitSize; //bitSize * 8 values / 8 bits int groupSize = pakData.m_BitSize; //bitSize * 8 values / 8 bits
byte[] group = new byte[groupSize]; byte[] group = new byte[groupSize];
int groupCount = (int)(pakData.m_NumItems / 8); int groupCount = pakData.m_NumItems / 8;
for (int g = 0; g < groupCount; g++) for (int g = 0; g < groupCount; g++)
{ {
@ -229,7 +229,7 @@ namespace Unity_Studio
//m_NumItems is not necessarily a multiple of 8, so there can be one extra group with fewer values //m_NumItems is not necessarily a multiple of 8, so there can be one extra group with fewer values
int endBytes = pakData.m_Data.Length - groupCount * groupSize; int endBytes = pakData.m_Data.Length - groupCount * groupSize;
int endVal = (int)(pakData.m_NumItems - groupCount * 8); int endVal = pakData.m_NumItems - groupCount * 8;
if (endBytes > 0) if (endBytes > 0)
{ {

View File

@ -55,7 +55,7 @@ namespace Unity_Studio
{ {
preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID;
} }
preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, preloadData.Size.ToString() }); preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
} }
} }

View File

@ -33,7 +33,7 @@ namespace Unity_Studio
{ {
if (m_Name != "") { preloadData.Text = m_Name; } if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, preloadData.Size.ToString() }); preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
} }
} }
else else
@ -56,7 +56,7 @@ namespace Unity_Studio
if (m_Name != "") { preloadData.Text = m_Name; } if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, preloadData.Size.ToString() }); preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
} }
a_Stream.AlignStream(4); a_Stream.AlignStream(4);
m_PathName = a_Stream.ReadAlignedString(a_Stream.ReadInt32()); m_PathName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());

View File

@ -141,8 +141,8 @@ namespace Unity_Studio
if (version[0] >= 4 || (version[0] == 3 && version[1] >= 4)) if (version[0] >= 4 || (version[0] == 3 && version[1] >= 4))
{ {
//AABB //AABB
float[] m_Center = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() }; float[] m_Center = { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
float[] m_Extent = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() }; float[] m_Extent = { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
bool m_DirtyAABB = a_Stream.ReadBoolean(); bool m_DirtyAABB = a_Stream.ReadBoolean();
} }
} }

View File

@ -53,7 +53,7 @@ namespace Unity_Studio
if (m_Name != "") { preloadData.Text = m_Name; } if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, preloadData.Size.ToString() }); preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
} }
a_Stream.AlignStream(4); a_Stream.AlignStream(4);

View File

@ -14,7 +14,7 @@ namespace Unity_Studio
public int m_Height; public int m_Height;
public int m_CompleteImageSize; public int m_CompleteImageSize;
public TextureFormat m_TextureFormat; public TextureFormat m_TextureFormat;
public bool m_MipMap = false; public bool m_MipMap;
public bool m_IsReadable; public bool m_IsReadable;
public bool m_ReadAllowed; public bool m_ReadAllowed;
public int m_ImageCount; public int m_ImageCount;
@ -39,11 +39,11 @@ namespace Unity_Studio
private int dwFlags = 0x1 + 0x2 + 0x4 + 0x1000; private int dwFlags = 0x1 + 0x2 + 0x4 + 0x1000;
//public int dwHeight; m_Height //public int dwHeight; m_Height
//public int dwWidth; m_Width //public int dwWidth; m_Width
private int dwPitchOrLinearSize = 0x0; private int dwPitchOrLinearSize;
private int dwMipMapCount = 0x1; private int dwMipMapCount = 0x1;
private int dwSize = 0x20; private int dwSize = 0x20;
private int dwFlags2; private int dwFlags2;
private int dwFourCC = 0x0; private int dwFourCC;
private int dwRGBBitCount; private int dwRGBBitCount;
private int dwRBitMask; private int dwRBitMask;
private int dwGBitMask; private int dwGBitMask;
@ -672,7 +672,7 @@ namespace Unity_Studio
} }
else else
{ {
preloadData.InfoText = "Width: " + m_Width.ToString() + "\nHeight: " + m_Height.ToString() + "\nFormat: "; preloadData.InfoText = "Width: " + m_Width + "\nHeight: " + m_Height + "\nFormat: ";
string type = m_TextureFormat.ToString(); string type = m_TextureFormat.ToString();
preloadData.InfoText += type; preloadData.InfoText += type;
@ -745,7 +745,7 @@ namespace Unity_Studio
} }
preloadData.InfoText += "\nAnisotropic level: " + m_Aniso.ToString() + "\nMip map bias: " + m_MipBias.ToString(); preloadData.InfoText += "\nAnisotropic level: " + m_Aniso + "\nMip map bias: " + m_MipBias;
switch (m_WrapMode) switch (m_WrapMode)
{ {
@ -755,7 +755,7 @@ namespace Unity_Studio
if (m_Name != "") { preloadData.Text = m_Name; } if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, preloadData.Size.ToString() }); preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
} }
} }
@ -906,6 +906,8 @@ namespace Unity_Studio
public Bitmap ConvertToBitmap(bool flip) public Bitmap ConvertToBitmap(bool flip)
{ {
if (image_data == null || image_data.Length == 0)
return null;
Bitmap bitmap = null; Bitmap bitmap = null;
switch (m_TextureFormat) switch (m_TextureFormat)
{ {
@ -981,28 +983,20 @@ namespace Unity_Studio
private Bitmap BGRA32ToBitmap() private Bitmap BGRA32ToBitmap()
{ {
if (image_data.Length > 0) var hObject = GCHandle.Alloc(image_data, GCHandleType.Pinned);
{ var pObject = hObject.AddrOfPinnedObject();
var hObject = GCHandle.Alloc(image_data, GCHandleType.Pinned); var bitmap = new Bitmap(m_Width, m_Height, m_Width * 4, PixelFormat.Format32bppArgb, pObject);
var pObject = hObject.AddrOfPinnedObject(); hObject.Free();
var bitmap = new Bitmap(m_Width, m_Height, m_Width * 4, PixelFormat.Format32bppArgb, pObject); return bitmap;
hObject.Free();
return bitmap;
}
return null;
} }
private Bitmap RGB565ToBitmap() private Bitmap RGB565ToBitmap()
{ {
if (image_data.Length > 0) var hObject = GCHandle.Alloc(image_data, GCHandleType.Pinned);
{ var pObject = hObject.AddrOfPinnedObject();
var hObject = GCHandle.Alloc(image_data, GCHandleType.Pinned); var bitmap = new Bitmap(m_Width, m_Height, m_Width * 2, PixelFormat.Format16bppRgb565, pObject);
var pObject = hObject.AddrOfPinnedObject(); hObject.Free();
var bitmap = new Bitmap(m_Width, m_Height, m_Width * 2, PixelFormat.Format16bppRgb565, pObject); return bitmap;
hObject.Free();
return bitmap;
}
return null;
} }
private Bitmap PVRToBitmap(byte[] pvrdata) private Bitmap PVRToBitmap(byte[] pvrdata)
@ -1126,8 +1120,8 @@ public enum TextureFormat
public static class KTXHeader public static class KTXHeader
{ {
public static byte[] IDENTIFIER = { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A }; public static byte[] IDENTIFIER = { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A };
public static byte[] ENDIANESS_LE = new byte[] { 1, 2, 3, 4 }; public static byte[] ENDIANESS_LE = { 1, 2, 3, 4 };
public static byte[] ENDIANESS_BE = new byte[] { 4, 3, 2, 1 }; public static byte[] ENDIANESS_BE = { 4, 3, 2, 1 };
// constants for glInternalFormat // constants for glInternalFormat
public static int GL_ETC1_RGB8_OES = 0x8D64; public static int GL_ETC1_RGB8_OES = 0x8D64;

View File

@ -28,9 +28,9 @@ namespace Unity_Studio
} }
m_GameObject = sourceFile.ReadPPtr(); m_GameObject = sourceFile.ReadPPtr();
m_LocalRotation = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() }; m_LocalRotation = new[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
m_LocalPosition = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() }; m_LocalPosition = new[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
m_LocalScale = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() }; m_LocalScale = new[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
int m_ChildrenCount = a_Stream.ReadInt32(); int m_ChildrenCount = a_Stream.ReadInt32();
for (int j = 0; j < m_ChildrenCount; j++) for (int j = 0; j < m_ChildrenCount; j++)
{ {

View File

@ -28,7 +28,7 @@ namespace Unity_Studio
public SortedDictionary<int, ClassStruct> ClassStructures = new SortedDictionary<int, ClassStruct>(); public SortedDictionary<int, ClassStruct> ClassStructures = new SortedDictionary<int, ClassStruct>();
private bool baseDefinitions = false; private bool baseDefinitions;
private List<int[]> classIDs = new List<int[]>();//use for 5.5.0 private List<int[]> classIDs = new List<int[]>();//use for 5.5.0
public class UnityShared public class UnityShared
@ -152,7 +152,7 @@ namespace Unity_Studio
int assetCount = a_Stream.ReadInt32(); int assetCount = a_Stream.ReadInt32();
#region asset preload table #region asset preload table
string assetIDfmt = "D" + assetCount.ToString().Length.ToString(); //format for unique ID string assetIDfmt = "D" + assetCount.ToString().Length; //format for unique ID
for (int i = 0; i < assetCount; i++) for (int i = 0; i < assetCount; i++)
{ {
@ -218,8 +218,8 @@ namespace Unity_Studio
} }
#endregion #endregion
buildType = m_Version.Split(new string[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, StringSplitOptions.RemoveEmptyEntries); buildType = m_Version.Split(new[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, StringSplitOptions.RemoveEmptyEntries);
string[] strver = (m_Version.Split(new string[] { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n" }, StringSplitOptions.RemoveEmptyEntries)); string[] strver = (m_Version.Split(new[] { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n" }, StringSplitOptions.RemoveEmptyEntries));
version = Array.ConvertAll(strver, int.Parse); version = Array.ConvertAll(strver, int.Parse);
if (fileGen >= 14) if (fileGen >= 14)
@ -286,7 +286,7 @@ namespace Unity_Studio
{ {
type1 = classID; type1 = classID;
} }
classIDs.Add(new int[] { type1, classID }); classIDs.Add(new[] { type1, classID });
classID = type1; classID = type1;
//TODO 某些文件出现type1=-1时还需要跳过16字节的情况 //TODO 某些文件出现type1=-1时还需要跳过16字节的情况
var temp = a_Stream.ReadInt32(); var temp = a_Stream.ReadInt32();

View File

@ -11,26 +11,32 @@ using System.Web.Script.Serialization;
namespace Unity_Studio namespace Unity_Studio
{ {
class UnityStudio internal static class UnityStudio
{ {
public List<string> unityFiles = new List<string>(); //files to load public static List<string> unityFiles = new List<string>(); //files to load
public HashSet<string> unityFilesHash = new HashSet<string>(); //improve performance public static HashSet<string> unityFilesHash = new HashSet<string>(); //improve performance
public List<AssetsFile> assetsfileList = new List<AssetsFile>(); //loaded files public static List<AssetsFile> assetsfileList = new List<AssetsFile>(); //loaded files
public HashSet<string> assetsfileListHash = new HashSet<string>(); //improve performance public static HashSet<string> assetsfileListHash = new HashSet<string>(); //improve performance
public static Dictionary<string, EndianStream> assetsfileandstream = new Dictionary<string, EndianStream>(); //use for read res files public static Dictionary<string, EndianStream> assetsfileandstream = new Dictionary<string, EndianStream>(); //use for read res files
public List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>(); //used to hold all assets while the ListView is filtered public static List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>(); //used to hold all assets while the ListView is filtered
public HashSet<string> exportableAssetsHash = new HashSet<string>(); //improve performance private static HashSet<string> exportableAssetsHash = new HashSet<string>(); //improve performance
public List<AssetPreloadData> visibleAssets = new List<AssetPreloadData>(); //used to build the ListView from all or filtered assets public static List<AssetPreloadData> visibleAssets = new List<AssetPreloadData>(); //used to build the ListView from all or filtered assets
public string productName = ""; public static string productName = "";
public string mainPath = ""; public static string mainPath = "";
public List<GameObject> fileNodes = new List<GameObject>(); public static List<GameObject> fileNodes = new List<GameObject>();
public Dictionary<string, Dictionary<string, string>> jsonMats; private static Dictionary<string, Dictionary<string, string>> jsonMats;
public Dictionary<string, SortedDictionary<int, ClassStruct>> AllClassStructures = new Dictionary<string, SortedDictionary<int, ClassStruct>>(); public static Dictionary<string, SortedDictionary<int, ClassStruct>> AllClassStructures = new Dictionary<string, SortedDictionary<int, ClassStruct>>();
//UI
public static Action<int> SetProgressBarValue;
public static Action<int> SetProgressBarMaximum;
public static Action ProgressBarPerformStep;
public static Action<string> StatusStripUpdate;
public static Action<int> ProgressBarMaximumAdd;
public void LoadAssetsFile(string fileName) public static void LoadAssetsFile(string fileName)
{ {
//var loadedAssetsFile = assetsfileList.Find(aFile => aFile.filePath == fileName); //var loadedAssetsFile = assetsfileList.Find(aFile => aFile.filePath == fileName);
//if (loadedAssetsFile == null) //if (loadedAssetsFile == null)
@ -110,11 +116,14 @@ namespace Unity_Studio
sharedFile.Index = unityFiles.IndexOf(sharedFilePath); sharedFile.Index = unityFiles.IndexOf(sharedFilePath);
} }
} }
if (value > 0)
ProgressBarMaximumAdd(value);
} }
} }
public void LoadBundleFile(string bundleFileName) public static void LoadBundleFile(string bundleFileName)
{ {
StatusStripUpdate("Decompressing " + Path.GetFileName(bundleFileName) + "...");
BundleFile b_File = new BundleFile(bundleFileName); BundleFile b_File = new BundleFile(bundleFileName);
List<AssetsFile> b_assetsfileList = new List<AssetsFile>(); List<AssetsFile> b_assetsfileList = new List<AssetsFile>();
@ -136,7 +145,7 @@ namespace Unity_Studio
Regex.IsMatch(memFile.fileName, "BuildPlayer-.*?")); Regex.IsMatch(memFile.fileName, "BuildPlayer-.*?"));
break; break;
} }
StatusStripUpdate("Loading " + memFile.fileName);
//create dummy path to be used for asset extraction //create dummy path to be used for asset extraction
memFile.fileName = Path.GetDirectoryName(bundleFileName) + "\\" + memFile.fileName; memFile.fileName = Path.GetDirectoryName(bundleFileName) + "\\" + memFile.fileName;
@ -145,8 +154,8 @@ namespace Unity_Studio
{ {
//make use of the bundle file version //make use of the bundle file version
assetsFile.m_Version = b_File.versionEngine; assetsFile.m_Version = b_File.versionEngine;
assetsFile.version = Array.ConvertAll((b_File.versionEngine.Split(new string[] { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n" }, StringSplitOptions.RemoveEmptyEntries)), int.Parse); assetsFile.version = Array.ConvertAll((b_File.versionEngine.Split(new[] { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n" }, StringSplitOptions.RemoveEmptyEntries)), int.Parse);
assetsFile.buildType = b_File.versionEngine.Split(new string[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, StringSplitOptions.RemoveEmptyEntries); assetsFile.buildType = b_File.versionEngine.Split(new[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, StringSplitOptions.RemoveEmptyEntries);
} }
if (validAssetsFile) if (validAssetsFile)
{ {
@ -172,7 +181,7 @@ namespace Unity_Studio
} }
} }
public void MergeSplitAssets(string dirPath) public static void MergeSplitAssets(string dirPath)
{ {
string[] splitFiles = Directory.GetFiles(dirPath, "*.split0"); string[] splitFiles = Directory.GetFiles(dirPath, "*.split0");
foreach (var splitFile in splitFiles) foreach (var splitFile in splitFiles)
@ -181,14 +190,12 @@ namespace Unity_Studio
string destPath = Path.GetDirectoryName(splitFile) + "\\"; string destPath = Path.GetDirectoryName(splitFile) + "\\";
if (!File.Exists(destPath + destFile)) if (!File.Exists(destPath + destFile))
{ {
//StatusStripUpdate("Merging " + destFile + " split files...");
string[] splitParts = Directory.GetFiles(destPath, destFile + ".split*"); string[] splitParts = Directory.GetFiles(destPath, destFile + ".split*");
using (var destStream = File.Create(destPath + destFile)) using (var destStream = File.Create(destPath + destFile))
{ {
for (int i = 0; i < splitParts.Length; i++) for (int i = 0; i < splitParts.Length; i++)
{ {
string splitPart = destPath + destFile + ".split" + i.ToString(); string splitPart = destPath + destFile + ".split" + i;
using (var sourceStream = File.OpenRead(splitPart)) using (var sourceStream = File.OpenRead(splitPart))
sourceStream.CopyTo(destStream); // You can pass the buffer size as second argument. sourceStream.CopyTo(destStream); // You can pass the buffer size as second argument.
} }
@ -197,11 +204,11 @@ namespace Unity_Studio
} }
} }
public int extractBundleFile(string bundleFileName) public static int extractBundleFile(string bundleFileName)
{ {
int extractedCount = 0; int extractedCount = 0;
//StatusStripUpdate("Decompressing " + Path.GetFileName(bundleFileName) + " ,,,"); StatusStripUpdate("Decompressing " + Path.GetFileName(bundleFileName) + " ,,,");
string extractPath = bundleFileName + "_unpacked\\"; string extractPath = bundleFileName + "_unpacked\\";
Directory.CreateDirectory(extractPath); Directory.CreateDirectory(extractPath);
@ -216,13 +223,9 @@ namespace Unity_Studio
Directory.CreateDirectory(Path.GetDirectoryName(filePath)); Directory.CreateDirectory(Path.GetDirectoryName(filePath));
} }
if (File.Exists(filePath)) if (!File.Exists(filePath))
{ {
//StatusStripUpdate("File " + memFile.fileName + " already exists"); StatusStripUpdate("Extracting " + Path.GetFileName(memFile.fileName));
}
else
{
//StatusStripUpdate("Extracting " + Path.GetFileName(memFile.fileName));
extractedCount += 1; extractedCount += 1;
using (FileStream file = new FileStream(filePath, FileMode.Create, System.IO.FileAccess.Write)) using (FileStream file = new FileStream(filePath, FileMode.Create, System.IO.FileAccess.Write))
@ -236,22 +239,21 @@ namespace Unity_Studio
return extractedCount; return extractedCount;
} }
public void BuildAssetStructures(bool loadAssetsMenuItem, bool displayAll, bool buildHierarchyMenuItem, bool buildClassStructuresMenuItem) public static void BuildAssetStructures(bool loadAssetsMenuItem, bool displayAll, bool buildHierarchyMenuItem, bool buildClassStructuresMenuItem)
{ {
#region first loop - read asset data & create list #region first loop - read asset data & create list
if (loadAssetsMenuItem) if (loadAssetsMenuItem)
{ {
//assetListView.BeginUpdate(); SetProgressBarValue(0);
string fileIDfmt = "D" + assetsfileList.Count.ToString().Length.ToString(); SetProgressBarMaximum(assetsfileList.Sum(x => x.preloadTable.Values.Count));
string fileIDfmt = "D" + assetsfileList.Count.ToString().Length;
foreach (var assetsFile in assetsfileList) for (var i = 0; i < assetsfileList.Count; i++)
{ {
//StatusStripUpdate("Building asset list from " + Path.GetFileName(assetsFile.filePath)); var assetsFile = assetsfileList[i];
StatusStripUpdate("Building asset list from " + Path.GetFileName(assetsFile.filePath));
string fileID = assetsfileList.IndexOf(assetsFile).ToString(fileIDfmt);
//ListViewGroup assetGroup = new ListViewGroup(Path.GetFileName(assetsFile.filePath));
string fileID = i.ToString(fileIDfmt);
foreach (var asset in assetsFile.preloadTable.Values) foreach (var asset in assetsFile.preloadTable.Values)
{ {
@ -260,68 +262,68 @@ namespace Unity_Studio
switch (asset.Type2) switch (asset.Type2)
{ {
case 1: //GameObject case 1: //GameObject
{ {
GameObject m_GameObject = new GameObject(asset); GameObject m_GameObject = new GameObject(asset);
assetsFile.GameObjectList.Add(asset.m_PathID, m_GameObject); assetsFile.GameObjectList.Add(asset.m_PathID, m_GameObject);
//totalTreeNodes++; //totalTreeNodes++;
break; break;
} }
case 4: //Transform case 4: //Transform
{ {
Transform m_Transform = new Transform(asset); Transform m_Transform = new Transform(asset);
assetsFile.TransformList.Add(asset.m_PathID, m_Transform); assetsFile.TransformList.Add(asset.m_PathID, m_Transform);
break; break;
} }
case 224: //RectTransform case 224: //RectTransform
{ {
RectTransform m_Rect = new RectTransform(asset); RectTransform m_Rect = new RectTransform(asset);
assetsFile.TransformList.Add(asset.m_PathID, m_Rect.m_Transform); assetsFile.TransformList.Add(asset.m_PathID, m_Rect.m_Transform);
break; break;
} }
//case 21: //Material //case 21: //Material
case 28: //Texture2D case 28: //Texture2D
{ {
Texture2D m_Texture2D = new Texture2D(asset, false); Texture2D m_Texture2D = new Texture2D(asset, false);
exportable = true; exportable = true;
break; break;
} }
case 48: //Shader case 48: //Shader
{ {
Shader m_Shader = new Shader(asset, false); Shader m_Shader = new Shader(asset, false);
exportable = true; exportable = true;
break; break;
} }
case 49: //TextAsset case 49: //TextAsset
{ {
TextAsset m_TextAsset = new TextAsset(asset, false); TextAsset m_TextAsset = new TextAsset(asset, false);
exportable = true; exportable = true;
break; break;
} }
case 83: //AudioClip case 83: //AudioClip
{ {
AudioClip m_AudioClip = new AudioClip(asset, false); AudioClip m_AudioClip = new AudioClip(asset, false);
exportable = true; exportable = true;
break; break;
} }
case 114: //MonoBehaviour case 114: //MonoBehaviour
{ {
var m_MonoBehaviour = new MonoBehaviour(asset, false); var m_MonoBehaviour = new MonoBehaviour(asset, false);
if (asset.Type1 != asset.Type2 && assetsFile.ClassStructures.ContainsKey(asset.Type1)) if (asset.Type1 != asset.Type2 && assetsFile.ClassStructures.ContainsKey(asset.Type1))
exportable = true;
break;
}
case 128: //Font
{
unityFont m_Font = new unityFont(asset, false);
exportable = true; exportable = true;
break; break;
} }
case 128: //Font
{
unityFont m_Font = new unityFont(asset, false);
exportable = true;
break;
}
case 129: //PlayerSettings case 129: //PlayerSettings
{ {
var plSet = new PlayerSettings(asset); var plSet = new PlayerSettings(asset);
productName = plSet.productName; productName = plSet.productName;
break; break;
} }
case 21: //Material case 21: //Material
case 43: //Mesh case 43: //Mesh
case 74: //AnimationClip case 74: //AnimationClip
@ -329,18 +331,18 @@ namespace Unity_Studio
case 91: //AnimatorController case 91: //AnimatorController
case 115: //MonoScript case 115: //MonoScript
case 213: //Sprite case 213: //Sprite
{ {
if (asset.Offset + 4 > asset.sourceFile.a_Stream.BaseStream.Length) if (asset.Offset + 4 > asset.sourceFile.a_Stream.BaseStream.Length)
break;
asset.sourceFile.a_Stream.Position = asset.Offset;
var len = asset.sourceFile.a_Stream.ReadInt32();
if (len > 0 && len < asset.Size - 4)
{
var bytes = asset.sourceFile.a_Stream.ReadBytes(len);
asset.Text = Encoding.UTF8.GetString(bytes);
}
break; break;
asset.sourceFile.a_Stream.Position = asset.Offset;
var len = asset.sourceFile.a_Stream.ReadInt32();
if (len > 0 && len < asset.Size - 4)
{
var bytes = asset.sourceFile.a_Stream.ReadBytes(len);
asset.Text = Encoding.UTF8.GetString(bytes);
} }
break;
}
} }
if (!exportable && displayAll) if (!exportable && displayAll)
{ {
@ -349,7 +351,7 @@ namespace Unity_Studio
asset.Text = asset.TypeString + " #" + asset.uniqueID; asset.Text = asset.TypeString + " #" + asset.uniqueID;
} }
asset.extension = ".dat"; asset.extension = ".dat";
asset.SubItems.AddRange(new string[] { asset.TypeString, asset.Size.ToString() }); asset.SubItems.AddRange(new[] {asset.TypeString, asset.Size.ToString()});
exportable = true; exportable = true;
} }
if (exportable) if (exportable)
@ -360,6 +362,7 @@ namespace Unity_Studio
} }
assetsFile.exportableAssets.Add(asset); assetsFile.exportableAssets.Add(asset);
} }
ProgressBarPerformStep();
} }
exportableAssets.AddRange(assetsFile.exportableAssets); exportableAssets.AddRange(assetsFile.exportableAssets);
//if (assetGroup.Items.Count > 0) { listView1.Groups.Add(assetGroup); } //if (assetGroup.Items.Count > 0) { listView1.Groups.Add(assetGroup); }
@ -377,11 +380,11 @@ namespace Unity_Studio
fileNodes = new List<GameObject>(); fileNodes = new List<GameObject>();
if (buildHierarchyMenuItem) if (buildHierarchyMenuItem)
{ {
//sceneTreeView.BeginUpdate(); SetProgressBarValue(1);
SetProgressBarMaximum(assetsfileList.Sum(x => x.GameObjectList.Values.Count) + 1);
foreach (var assetsFile in assetsfileList) foreach (var assetsFile in assetsfileList)
{ {
//StatusStripUpdate("Building tree structure from " + Path.GetFileName(assetsFile.filePath)); 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);
fileNode.m_Name = "RootNode"; fileNode.m_Name = "RootNode";
@ -407,6 +410,7 @@ namespace Unity_Studio
} }
parentNode.Nodes.Add(m_GameObject); parentNode.Nodes.Add(m_GameObject);
ProgressBarPerformStep();
} }
@ -416,7 +420,6 @@ namespace Unity_Studio
} }
fileNodes.Add(fileNode); fileNodes.Add(fileNode);
} }
//sceneTreeView.EndUpdate();
if (File.Exists(mainPath + "\\materials.json")) if (File.Exists(mainPath + "\\materials.json"))
{ {
@ -451,11 +454,9 @@ namespace Unity_Studio
} }
} }
#endregion #endregion
} }
public void WriteFBX(string FBXfile, bool allNodes) public static void WriteFBX(string FBXfile, bool allNodes)
{ {
var timestamp = DateTime.Now; var timestamp = DateTime.Now;
@ -884,7 +885,7 @@ namespace Unity_Studio
Transform m_Transform; Transform m_Transform;
if (assetsfileList.TryGetTransform(m_GameObject.m_Transform, out m_Transform)) if (assetsfileList.TryGetTransform(m_GameObject.m_Transform, out m_Transform))
{ {
float[] m_EulerRotation = QuatToEuler(new float[] { m_Transform.m_LocalRotation[0], -m_Transform.m_LocalRotation[1], -m_Transform.m_LocalRotation[2], m_Transform.m_LocalRotation[3] }); float[] m_EulerRotation = QuatToEuler(new[] { m_Transform.m_LocalRotation[0], -m_Transform.m_LocalRotation[1], -m_Transform.m_LocalRotation[2], m_Transform.m_LocalRotation[3] });
ob.AppendFormat("\n\t\t\tP: \"Lcl Translation\", \"Lcl Translation\", \"\", \"A\",{0},{1},{2}", -m_Transform.m_LocalPosition[0], m_Transform.m_LocalPosition[1], m_Transform.m_LocalPosition[2]); ob.AppendFormat("\n\t\t\tP: \"Lcl Translation\", \"Lcl Translation\", \"\", \"A\",{0},{1},{2}", -m_Transform.m_LocalPosition[0], m_Transform.m_LocalPosition[1], m_Transform.m_LocalPosition[2]);
ob.AppendFormat("\n\t\t\tP: \"Lcl Rotation\", \"Lcl Rotation\", \"\", \"A\",{0},{1},{2}", m_EulerRotation[0], m_EulerRotation[1], m_EulerRotation[2]);//handedness is switched in quat ob.AppendFormat("\n\t\t\tP: \"Lcl Rotation\", \"Lcl Rotation\", \"\", \"A\",{0},{1},{2}", m_EulerRotation[0], m_EulerRotation[1], m_EulerRotation[2]);//handedness is switched in quat
@ -1155,11 +1156,11 @@ namespace Unity_Studio
FBXwriter.Write(cb); FBXwriter.Write(cb);
cb.Clear(); cb.Clear();
//StatusStripUpdate("Finished exporting " + Path.GetFileName(FBXfile)); StatusStripUpdate("Finished exporting " + Path.GetFileName(FBXfile));
} }
} }
public void MeshFBX(Mesh m_Mesh, string MeshID, StringBuilder ob) private static void MeshFBX(Mesh m_Mesh, string MeshID, StringBuilder ob)
{ {
if (m_Mesh.m_VertexCount > 0)//general failsafe if (m_Mesh.m_VertexCount > 0)//general failsafe
{ {
@ -1534,7 +1535,7 @@ namespace Unity_Studio
} }
} }
public static float[] QuatToEuler(float[] q) private static float[] QuatToEuler(float[] q)
{ {
double eax = 0; double eax = 0;
double eay = 0; double eay = 0;
@ -1576,7 +1577,7 @@ namespace Unity_Studio
return new float[3] { (float)(eax * 180 / Math.PI), (float)(eay * 180 / Math.PI), (float)(eaz * 180 / Math.PI) }; return new float[3] { (float)(eax * 180 / Math.PI), (float)(eay * 180 / Math.PI), (float)(eaz * 180 / Math.PI) };
} }
public static byte[] RandomColorGenerator(string name) private static byte[] RandomColorGenerator(string name)
{ {
int nameHash = name.GetHashCode(); int nameHash = name.GetHashCode();
Random r = new Random(nameHash); Random r = new Random(nameHash);
@ -1589,14 +1590,14 @@ namespace Unity_Studio
return new byte[3] { red, green, blue }; return new byte[3] { red, green, blue };
} }
public void ExportRawFile(AssetPreloadData asset, string exportFilepath) public static void ExportRawFile(AssetPreloadData asset, string exportFilepath)
{ {
asset.sourceFile.a_Stream.Position = asset.Offset; asset.sourceFile.a_Stream.Position = asset.Offset;
var bytes = asset.sourceFile.a_Stream.ReadBytes(asset.Size); var bytes = asset.sourceFile.a_Stream.ReadBytes(asset.Size);
File.WriteAllBytes(exportFilepath, bytes); File.WriteAllBytes(exportFilepath, bytes);
} }
public bool ExportTexture(AssetPreloadData asset, string exportPathName, bool flip) public static bool ExportTexture(AssetPreloadData asset, string exportPathName, bool flip)
{ {
var m_Texture2D = new Texture2D(asset, true); var m_Texture2D = new Texture2D(asset, true);
var convert = (bool)Properties.Settings.Default["convertTexture"]; var convert = (bool)Properties.Settings.Default["convertTexture"];
@ -1628,7 +1629,7 @@ namespace Unity_Studio
return true; return true;
} }
public bool ExportAudioClip(AssetPreloadData asset, string exportFilename, string exportFileextension) public static bool ExportAudioClip(AssetPreloadData asset, string exportFilename, string exportFileextension)
{ {
var oldextension = exportFileextension; var oldextension = exportFileextension;
if ((bool)Properties.Settings.Default["convertfsb"] && exportFileextension == ".fsb") if ((bool)Properties.Settings.Default["convertfsb"] && exportFileextension == ".fsb")
@ -1709,22 +1710,22 @@ namespace Unity_Studio
return true; return true;
} }
public void ExportMonoBehaviour(MonoBehaviour m_MonoBehaviour, string exportFilename) public static void ExportMonoBehaviour(MonoBehaviour m_MonoBehaviour, string exportFilename)
{ {
File.WriteAllText(exportFilename, m_MonoBehaviour.serializedText); File.WriteAllText(exportFilename, m_MonoBehaviour.serializedText);
} }
public void ExportShader(Shader m_Shader, string exportFilename) public static void ExportShader(Shader m_Shader, string exportFilename)
{ {
File.WriteAllBytes(exportFilename, m_Shader.m_Script); File.WriteAllBytes(exportFilename, m_Shader.m_Script);
} }
public void ExportText(TextAsset m_TextAsset, string exportFilename) public static void ExportText(TextAsset m_TextAsset, string exportFilename)
{ {
File.WriteAllBytes(exportFilename, m_TextAsset.m_Script); File.WriteAllBytes(exportFilename, m_TextAsset.m_Script);
} }
public void ExportFont(unityFont m_Font, string exportFilename) public static void ExportFont(unityFont m_Font, string exportFilename)
{ {
if (m_Font.m_FontData != null) if (m_Font.m_FontData != null)
{ {
@ -1732,19 +1733,14 @@ namespace Unity_Studio
} }
} }
public bool ExportFileExists(string filename, string assetType) public static bool ExportFileExists(string filename, string assetType)
{ {
if (File.Exists(filename)) if (File.Exists(filename))
{ {
//StatusStripUpdate(assetType + " file " + Path.GetFileName(filename) + " already exists");
return true; return true;
} }
else Directory.CreateDirectory(Path.GetDirectoryName(filename));
{ return false;
Directory.CreateDirectory(Path.GetDirectoryName(filename));
//StatusStripUpdate("Exporting " + assetType + ": " + Path.GetFileName(filename));
return false;
}
} }
} }
} }

View File

@ -11,7 +11,7 @@ namespace Unity_Studio
//m_FileID 0 means current file //m_FileID 0 means current file
public int m_FileID = -1; public int m_FileID = -1;
//m_PathID acts more like a hash in some games //m_PathID acts more like a hash in some games
public long m_PathID = 0; public long m_PathID;
} }
public static class PPtrHelpers public static class PPtrHelpers

View File

@ -834,7 +834,6 @@
this.Name = "UnityStudioForm"; this.Name = "UnityStudioForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Unity Studio"; this.Text = "Unity Studio";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.UnityStudioForm_FormClosing);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.UnityStudioForm_KeyDown); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.UnityStudioForm_KeyDown);
this.menuStrip1.ResumeLayout(false); this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout(); this.menuStrip1.PerformLayout();

View File

@ -11,52 +11,40 @@ using System.Runtime.InteropServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing.Text; using System.Drawing.Text;
using System.Threading.Tasks; using static Unity_Studio.UnityStudio;
/*TODO
For extracting bundles, first check if file exists then decompress
Font index error in Dreamfall Chapters
*/
namespace Unity_Studio namespace Unity_Studio
{ {
partial class UnityStudioForm : Form partial class UnityStudioForm : Form
{ {
private UnityStudio ustudio = new UnityStudio(); private AssetPreloadData lastSelectedItem;
private AssetPreloadData lastLoadedAsset;
private AssetPreloadData lastSelectedItem = null; private string[] fileTypes = { "globalgamemanagers", "maindata.", "level*.", "*.assets", "*.sharedAssets", "CustomAssetBundle-*", "CAB-*", "BuildPlayer-*" };
private AssetPreloadData lastLoadedAsset = null;
//private AssetsFile mainDataFile = null;
private string[] fileTypes = new string[] { "globalgamemanagers", "maindata.", "level*.", "*.assets", "*.sharedAssets", "CustomAssetBundle-*", "CAB-*", "BuildPlayer-*" }; private FMOD.System system;
private FMOD.Sound sound;
private FMOD.System system = null; private FMOD.Channel channel;
private FMOD.Sound sound = null; private FMOD.SoundGroup masterSoundGroup;
private FMOD.Channel channel = null;
private FMOD.SoundGroup masterSoundGroup = null;
//private FMOD.ChannelGroup channelGroup = null;
private FMOD.MODE loopMode = FMOD.MODE.LOOP_OFF; private FMOD.MODE loopMode = FMOD.MODE.LOOP_OFF;
private uint FMODlenms = 0; private uint FMODlenms;
private float FMODVolume = 0.8f; private float FMODVolume = 0.8f;
private float FMODfrequency; private float FMODfrequency;
private Bitmap imageTexture = null; private Bitmap imageTexture;
//asset list sorting helpers //asset list sorting helpers
private int firstSortColumn = -1; private int firstSortColumn = -1;
private int secondSortColumn = 0; private int secondSortColumn;
private bool reverseSort = false; private bool reverseSort;
private bool enableFiltering = false; private bool enableFiltering;
//tree search //tree search
private int nextGObject = 0; private int nextGObject;
List<GameObject> treeSrcResults = new List<GameObject>(); private List<GameObject> treeSrcResults = new List<GameObject>();
//counters for progress bar private PrivateFontCollection pfc = new PrivateFontCollection();
//private int totalAssetCount = 0;
//private int totalTreeNodes = 0;
PrivateFontCollection pfc = new PrivateFontCollection();
[DllImport("gdi32.dll")] [DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts); private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
@ -67,47 +55,43 @@ namespace Unity_Studio
if (openFileDialog1.ShowDialog() == DialogResult.OK) if (openFileDialog1.ShowDialog() == DialogResult.OK)
{ {
resetForm(); resetForm();
ustudio.mainPath = Path.GetDirectoryName(openFileDialog1.FileNames[0]); mainPath = Path.GetDirectoryName(openFileDialog1.FileNames[0]);
Task task = null; ThreadPool.QueueUserWorkItem(state =>
if (openFileDialog1.FilterIndex == 1)
{ {
ustudio.MergeSplitAssets(ustudio.mainPath); if (openFileDialog1.FilterIndex == 1)
{
MergeSplitAssets(mainPath);
//unityFiles.AddRange(openFileDialog1.FileNames); //unityFiles.AddRange(openFileDialog1.FileNames);
foreach (var i in openFileDialog1.FileNames) foreach (var i in openFileDialog1.FileNames)
{
ustudio.unityFiles.Add(i);
ustudio.unityFilesHash.Add(Path.GetFileName(i));
}
progressBar1.Value = 0;
progressBar1.Maximum = ustudio.unityFiles.Count;
task = new Task(() =>
{
//use a for loop because list size can change
for (int f = 0; f < ustudio.unityFiles.Count; f++)
{ {
StatusStripUpdate("Loading " + Path.GetFileName(ustudio.unityFiles[f])); unityFiles.Add(i);
ustudio.LoadAssetsFile(ustudio.unityFiles[f]); unityFilesHash.Add(Path.GetFileName(i));
}
SetProgressBarValue(0);
SetProgressBarMaximum(unityFiles.Count);
//use a for loop because list size can change
for (int f = 0; f < unityFiles.Count; f++)
{
StatusStripUpdate("Loading " + Path.GetFileName(unityFiles[f]));
LoadAssetsFile(unityFiles[f]);
ProgressBarPerformStep(); ProgressBarPerformStep();
} }
}); }
} else
else
{
progressBar1.Value = 0;
progressBar1.Maximum = openFileDialog1.FileNames.Length;
task = new Task(() =>
{ {
SetProgressBarValue(0);
SetProgressBarMaximum(unityFiles.Count);
foreach (var filename in openFileDialog1.FileNames) foreach (var filename in openFileDialog1.FileNames)
{ {
ustudio.LoadBundleFile(filename); LoadBundleFile(filename);
ProgressBarPerformStep(); ProgressBarPerformStep();
} }
}); }
} BuildAssetStrucutres();
task.ContinueWith(task2 => { BuildAssetStrucutres(); }); unityFilesHash.Clear();
task.ContinueWith(task2 => { ustudio.unityFilesHash.Clear(); ustudio.assetsfileListHash.Clear(); }); assetsfileListHash.Clear();
task.Start(); });
} }
} }
@ -123,20 +107,20 @@ namespace Unity_Studio
if (openFolderDialog1.ShowDialog() == DialogResult.OK) if (openFolderDialog1.ShowDialog() == DialogResult.OK)
{ {
//mainPath = folderBrowserDialog1.SelectedPath; //mainPath = folderBrowserDialog1.SelectedPath;
ustudio.mainPath = openFolderDialog1.FileName; mainPath = openFolderDialog1.FileName;
if (Path.GetFileName(ustudio.mainPath) == "Select folder") if (Path.GetFileName(mainPath) == "Select folder")
{ ustudio.mainPath = Path.GetDirectoryName(ustudio.mainPath); } { mainPath = Path.GetDirectoryName(mainPath); }
if (Directory.Exists(ustudio.mainPath)) if (Directory.Exists(mainPath))
{ {
resetForm(); resetForm();
//TODO find a way to read data directly instead of merging files //TODO find a way to read data directly instead of merging files
ustudio.MergeSplitAssets(ustudio.mainPath); MergeSplitAssets(mainPath);
for (int t = 0; t < fileTypes.Length; t++) for (int t = 0; t < fileTypes.Length; t++)
{ {
string[] fileNames = Directory.GetFiles(ustudio.mainPath, fileTypes[t], SearchOption.AllDirectories); string[] fileNames = Directory.GetFiles(mainPath, fileTypes[t], SearchOption.AllDirectories);
#region sort specific types alphanumerically #region sort specific types alphanumerically
if (fileNames.Length > 0 && (t == 1 || t == 2)) if (fileNames.Length > 0 && (t == 1 || t == 2))
{ {
@ -156,8 +140,8 @@ namespace Unity_Studio
}); });
foreach (var i in sortedList) foreach (var i in sortedList)
{ {
ustudio.unityFiles.Add(i); unityFiles.Add(i);
ustudio.unityFilesHash.Add(Path.GetFileName(i)); unityFilesHash.Add(Path.GetFileName(i));
} }
} }
@ -166,27 +150,27 @@ namespace Unity_Studio
{ {
foreach (var i in fileNames) foreach (var i in fileNames)
{ {
ustudio.unityFiles.Add(i); unityFiles.Add(i);
ustudio.unityFilesHash.Add(Path.GetFileName(i)); unityFilesHash.Add(Path.GetFileName(i));
} }
} }
} }
ustudio.unityFiles = ustudio.unityFiles.Distinct().ToList(); unityFiles = unityFiles.Distinct().ToList();
progressBar1.Value = 0; progressBar1.Value = 0;
progressBar1.Maximum = ustudio.unityFiles.Count; progressBar1.Maximum = unityFiles.Count;
ThreadPool.QueueUserWorkItem(delegate ThreadPool.QueueUserWorkItem(delegate
{ {
//use a for loop because list size can change //use a for loop because list size can change
for (int f = 0; f < ustudio.unityFiles.Count; f++) for (int f = 0; f < unityFiles.Count; f++)
{ {
var fileName = ustudio.unityFiles[f]; var fileName = unityFiles[f];
StatusStripUpdate("Loading " + Path.GetFileName(fileName)); StatusStripUpdate("Loading " + Path.GetFileName(fileName));
ustudio.LoadAssetsFile(fileName); LoadAssetsFile(fileName);
ProgressBarPerformStep(); ProgressBarPerformStep();
} }
ustudio.unityFilesHash.Clear(); unityFilesHash.Clear();
ustudio.assetsfileListHash.Clear(); assetsfileListHash.Clear();
BuildAssetStrucutres(); BuildAssetStrucutres();
}); });
} }
@ -211,10 +195,10 @@ namespace Unity_Studio
{ {
foreach (var fileName in openBundleDialog.FileNames) foreach (var fileName in openBundleDialog.FileNames)
{ {
extractedCount += ustudio.extractBundleFile(fileName); extractedCount += extractBundleFile(fileName);
ProgressBarPerformStep(); ProgressBarPerformStep();
} }
StatusStripUpdate("Finished extracting " + extractedCount.ToString() + " files."); StatusStripUpdate("Finished extracting " + extractedCount + " files.");
}); });
} }
} }
@ -246,10 +230,10 @@ namespace Unity_Studio
{ {
foreach (var fileName in bundleFiles) foreach (var fileName in bundleFiles)
{ {
extractedCount += ustudio.extractBundleFile(fileName); extractedCount += extractBundleFile(fileName);
ProgressBarPerformStep(); ProgressBarPerformStep();
} }
StatusStripUpdate("Finished extracting " + extractedCount.ToString() + " files."); StatusStripUpdate("Finished extracting " + extractedCount + " files.");
}); });
} }
} }
@ -261,34 +245,34 @@ namespace Unity_Studio
bool optionBuildHierarchyMenuItem = !dontBuildHierarchyMenuItem.Checked; bool optionBuildHierarchyMenuItem = !dontBuildHierarchyMenuItem.Checked;
bool optionBuildClassStructuresMenuItem = buildClassStructuresMenuItem.Checked; bool optionBuildClassStructuresMenuItem = buildClassStructuresMenuItem.Checked;
ustudio.BuildAssetStructures(optionLoadAssetsMenuItem, optionDisplayAll, optionBuildHierarchyMenuItem, optionBuildClassStructuresMenuItem); BuildAssetStructures(optionLoadAssetsMenuItem, optionDisplayAll, optionBuildHierarchyMenuItem, optionBuildClassStructuresMenuItem);
BeginInvoke(new Action(() => BeginInvoke(new Action(() =>
{ {
if (ustudio.productName != "") if (productName != "")
{ {
this.Text = "Unity Studio - " + ustudio.productName + " - " + ustudio.assetsfileList[0].m_Version + " - " + ustudio.assetsfileList[0].platformStr; this.Text = "Unity Studio - " + productName + " - " + assetsfileList[0].m_Version + " - " + assetsfileList[0].platformStr;
} }
else if (ustudio.assetsfileList.Count > 0) else if (assetsfileList.Count > 0)
{ {
this.Text = "Unity Studio - no productName - " + ustudio.assetsfileList[0].m_Version + " - " + ustudio.assetsfileList[0].platformStr; this.Text = "Unity Studio - no productName - " + assetsfileList[0].m_Version + " - " + assetsfileList[0].platformStr;
} }
if (!dontLoadAssetsMenuItem.Checked) if (!dontLoadAssetsMenuItem.Checked)
{ {
assetListView.VirtualListSize = ustudio.visibleAssets.Count; assetListView.VirtualListSize = visibleAssets.Count;
resizeAssetListColumns(); resizeAssetListColumns();
} }
if (!dontBuildHierarchyMenuItem.Checked) if (!dontBuildHierarchyMenuItem.Checked)
{ {
sceneTreeView.BeginUpdate(); sceneTreeView.BeginUpdate();
sceneTreeView.Nodes.AddRange(ustudio.fileNodes.ToArray()); sceneTreeView.Nodes.AddRange(fileNodes.ToArray());
ustudio.fileNodes.Clear(); fileNodes.Clear();
sceneTreeView.EndUpdate(); sceneTreeView.EndUpdate();
} }
if (buildClassStructuresMenuItem.Checked) if (buildClassStructuresMenuItem.Checked)
{ {
classesListView.BeginUpdate(); classesListView.BeginUpdate();
foreach (var version in ustudio.AllClassStructures) foreach (var version in AllClassStructures)
{ {
ListViewGroup versionGroup = new ListViewGroup(version.Key); ListViewGroup versionGroup = new ListViewGroup(version.Key);
classesListView.Groups.Add(versionGroup); classesListView.Groups.Add(versionGroup);
@ -301,9 +285,9 @@ namespace Unity_Studio
} }
classesListView.EndUpdate(); classesListView.EndUpdate();
} }
StatusStripUpdate("Finished loading " + ustudio.assetsfileList.Count.ToString() + " files with " + (assetListView.Items.Count + sceneTreeView.Nodes.Count).ToString() + " exportable assets."); StatusStripUpdate("Finished loading " + assetsfileList.Count + " files with " + (assetListView.Items.Count + sceneTreeView.Nodes.Count) + " exportable assets.");
treeSearch.Select(); treeSearch.Select();
saveFolderDialog1.InitialDirectory = ustudio.mainPath; saveFolderDialog1.InitialDirectory = mainPath;
})); }));
} }
@ -332,18 +316,18 @@ namespace Unity_Studio
private void exportClassStructuresMenuItem_Click(object sender, EventArgs e) private void exportClassStructuresMenuItem_Click(object sender, EventArgs e)
{ {
if (ustudio.AllClassStructures.Count > 0) if (AllClassStructures.Count > 0)
{ {
if (saveFolderDialog1.ShowDialog() == DialogResult.OK) if (saveFolderDialog1.ShowDialog() == DialogResult.OK)
{ {
progressBar1.Value = 0; progressBar1.Value = 0;
progressBar1.Maximum = ustudio.AllClassStructures.Count; progressBar1.Maximum = AllClassStructures.Count;
var savePath = saveFolderDialog1.FileName; var savePath = saveFolderDialog1.FileName;
if (Path.GetFileName(savePath) == "Select folder or write folder name to create") if (Path.GetFileName(savePath) == "Select folder or write folder name to create")
{ savePath = Path.GetDirectoryName(saveFolderDialog1.FileName); } { savePath = Path.GetDirectoryName(saveFolderDialog1.FileName); }
foreach (var version in ustudio.AllClassStructures) foreach (var version in AllClassStructures)
{ {
if (version.Value.Count > 0) if (version.Value.Count > 0)
{ {
@ -468,7 +452,7 @@ namespace Unity_Studio
private void assetListView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) private void assetListView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{ {
e.Item = ustudio.visibleAssets[e.ItemIndex]; e.Item = visibleAssets[e.ItemIndex];
} }
private void tabPageSelected(object sender, TabControlEventArgs e) private void tabPageSelected(object sender, TabControlEventArgs e)
@ -537,7 +521,7 @@ namespace Unity_Studio
{ {
if (treeSrcResults.Count == 0) if (treeSrcResults.Count == 0)
{ {
foreach (var aFile in ustudio.assetsfileList) foreach (var aFile in assetsfileList)
{ {
foreach (var GObject in aFile.GameObjectList.Values) foreach (var GObject in aFile.GameObjectList.Values)
{ {
@ -583,7 +567,7 @@ namespace Unity_Studio
assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent); assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
var vscrollwidth = SystemInformation.VerticalScrollBarWidth; var vscrollwidth = SystemInformation.VerticalScrollBarWidth;
var hasvscroll = ((float)ustudio.visibleAssets.Count / (float)assetListView.Height) > 0.0567f; var hasvscroll = (visibleAssets.Count / (float)assetListView.Height) > 0.0567f;
columnHeaderName.Width = assetListView.Width - columnHeaderType.Width - columnHeaderSize.Width - (hasvscroll ? (5 + vscrollwidth) : 5); columnHeaderName.Width = assetListView.Width - columnHeaderType.Width - columnHeaderSize.Width - (hasvscroll ? (5 + vscrollwidth) : 5);
} }
@ -635,8 +619,8 @@ namespace Unity_Studio
assetListView.BeginUpdate(); assetListView.BeginUpdate();
assetListView.SelectedIndices.Clear(); assetListView.SelectedIndices.Clear();
//visibleListAssets = exportableAssets.FindAll(ListAsset => ListAsset.Text.StartsWith(ListSearch.Text, System.StringComparison.CurrentCultureIgnoreCase)); //visibleListAssets = exportableAssets.FindAll(ListAsset => ListAsset.Text.StartsWith(ListSearch.Text, System.StringComparison.CurrentCultureIgnoreCase));
ustudio.visibleAssets = ustudio.exportableAssets.FindAll(ListAsset => ListAsset.Text.IndexOf(listSearch.Text, System.StringComparison.CurrentCultureIgnoreCase) >= 0); visibleAssets = exportableAssets.FindAll(ListAsset => ListAsset.Text.IndexOf(listSearch.Text, System.StringComparison.CurrentCultureIgnoreCase) >= 0);
assetListView.VirtualListSize = ustudio.visibleAssets.Count; assetListView.VirtualListSize = visibleAssets.Count;
assetListView.EndUpdate(); assetListView.EndUpdate();
} }
} }
@ -657,7 +641,7 @@ namespace Unity_Studio
switch (e.Column) switch (e.Column)
{ {
case 0: case 0:
ustudio.visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b) visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b)
{ {
int xdiff = reverseSort ? b.Text.CompareTo(a.Text) : a.Text.CompareTo(b.Text); int xdiff = reverseSort ? b.Text.CompareTo(a.Text) : a.Text.CompareTo(b.Text);
if (xdiff != 0) return xdiff; if (xdiff != 0) return xdiff;
@ -665,7 +649,7 @@ namespace Unity_Studio
}); });
break; break;
case 1: case 1:
ustudio.visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b) visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b)
{ {
int xdiff = reverseSort ? b.TypeString.CompareTo(a.TypeString) : a.TypeString.CompareTo(b.TypeString); int xdiff = reverseSort ? b.TypeString.CompareTo(a.TypeString) : a.TypeString.CompareTo(b.TypeString);
if (xdiff != 0) return xdiff; if (xdiff != 0) return xdiff;
@ -673,7 +657,7 @@ namespace Unity_Studio
}); });
break; break;
case 2: case 2:
ustudio.visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b) visibleAssets.Sort(delegate (AssetPreloadData a, AssetPreloadData b)
{ {
int xdiff = reverseSort ? b.Size.CompareTo(a.Size) : a.Size.CompareTo(b.Size); int xdiff = reverseSort ? b.Size.CompareTo(a.Size) : a.Size.CompareTo(b.Size);
if (xdiff != 0) return xdiff; if (xdiff != 0) return xdiff;
@ -783,7 +767,7 @@ namespace Unity_Studio
result = channel.getFrequency(out FMODfrequency); result = channel.getFrequency(out FMODfrequency);
if (ERRCHECK(result)) { break; } if (ERRCHECK(result)) { break; }
FMODinfoLabel.Text = FMODfrequency.ToString() + " Hz"; FMODinfoLabel.Text = FMODfrequency + " Hz";
FMODtimerLabel.Text = "0:0.0 / " + (FMODlenms / 1000 / 60) + ":" + (FMODlenms / 1000 % 60) + "." + (FMODlenms / 10 % 100); FMODtimerLabel.Text = "0:0.0 / " + (FMODlenms / 1000 / 60) + ":" + (FMODlenms / 1000 % 60) + "." + (FMODlenms / 10 % 100);
break; break;
} }
@ -1234,7 +1218,7 @@ namespace Unity_Studio
//选中它和它的子节点 //选中它和它的子节点
sceneTreeView.Invoke(new Action(() => j.Checked = true)); sceneTreeView.Invoke(new Action(() => j.Checked = true));
//导出FBX //导出FBX
ustudio.WriteFBX(savePath + filename + ".fbx", false); WriteFBX(savePath + filename + ".fbx", false);
//取消选中 //取消选中
sceneTreeView.Invoke(new Action(() => j.Checked = false)); sceneTreeView.Invoke(new Action(() => j.Checked = false));
} }
@ -1262,7 +1246,7 @@ namespace Unity_Studio
var timestamp = DateTime.Now; var timestamp = DateTime.Now;
saveFileDialog1.FileName = ustudio.productName + timestamp.ToString("_yy_MM_dd__HH_mm_ss"); saveFileDialog1.FileName = productName + timestamp.ToString("_yy_MM_dd__HH_mm_ss");
//extension will be added by the file save dialog //extension will be added by the file save dialog
if (saveFileDialog1.ShowDialog() == DialogResult.OK) if (saveFileDialog1.ShowDialog() == DialogResult.OK)
@ -1277,7 +1261,7 @@ namespace Unity_Studio
switch (saveFileDialog1.FilterIndex) switch (saveFileDialog1.FilterIndex)
{ {
case 1: case 1:
ustudio.WriteFBX(saveFileDialog1.FileName, exportSwitch); WriteFBX(saveFileDialog1.FileName, exportSwitch);
break; break;
case 2: case 2:
break; break;
@ -1294,17 +1278,17 @@ namespace Unity_Studio
private void ExportAssets_Click(object sender, EventArgs e) private void ExportAssets_Click(object sender, EventArgs e)
{ {
if (ustudio.exportableAssets.Count > 0 && saveFolderDialog1.ShowDialog() == DialogResult.OK) if (exportableAssets.Count > 0 && saveFolderDialog1.ShowDialog() == DialogResult.OK)
{ {
timer.Stop(); timer.Stop();
List<AssetPreloadData> toExportAssets = null; List<AssetPreloadData> toExportAssets = null;
if (((ToolStripItem)sender).Name == "exportAllAssetsMenuItem") if (((ToolStripItem)sender).Name == "exportAllAssetsMenuItem")
{ {
toExportAssets = ustudio.exportableAssets; toExportAssets = exportableAssets;
} }
else if (((ToolStripItem)sender).Name == "exportFilteredAssetsMenuItem") else if (((ToolStripItem)sender).Name == "exportFilteredAssetsMenuItem")
{ {
toExportAssets = ustudio.visibleAssets; toExportAssets = visibleAssets;
} }
else if (((ToolStripItem)sender).Name == "exportSelectedAssetsMenuItem") else if (((ToolStripItem)sender).Name == "exportSelectedAssetsMenuItem")
{ {
@ -1334,58 +1318,58 @@ namespace Unity_Studio
string exportpath = savePath + "\\"; string exportpath = savePath + "\\";
if (assetGroupSelectedIndex == 1) { exportpath += Path.GetFileNameWithoutExtension(asset.sourceFile.filePath) + "_export\\"; } if (assetGroupSelectedIndex == 1) { exportpath += Path.GetFileNameWithoutExtension(asset.sourceFile.filePath) + "_export\\"; }
else if (assetGroupSelectedIndex == 0) { exportpath = savePath + "\\" + asset.TypeString + "\\"; } else if (assetGroupSelectedIndex == 0) { exportpath = savePath + "\\" + asset.TypeString + "\\"; }
StatusStripUpdate("Exporting " + asset.TypeString + ": " + asset.Text);
//AudioClip and Texture2D extensions are set when the list is built //AudioClip and Texture2D extensions are set when the list is built
//so their overwrite tests can be done without loading them again //so their overwrite tests can be done without loading them again
switch (asset.Type2) switch (asset.Type2)
{ {
case 28: case 28:
if (ustudio.ExportTexture(asset, exportpath, true)) if (ExportTexture(asset, exportpath, true))
{ {
exportedCount++; exportedCount++;
} }
break; break;
case 83: case 83:
if (ustudio.ExportAudioClip(asset, exportpath + asset.Text, asset.extension)) if (ExportAudioClip(asset, exportpath + asset.Text, asset.extension))
{ {
exportedCount++; exportedCount++;
} }
break; break;
case 48: case 48:
if (!ustudio.ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString)) if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
{ {
ustudio.ExportShader(new Shader(asset, true), exportpath + asset.Text + ".txt"); ExportShader(new Shader(asset, true), exportpath + asset.Text + ".txt");
exportedCount++; exportedCount++;
} }
break; break;
case 49: case 49:
TextAsset m_TextAsset = new TextAsset(asset, true); TextAsset m_TextAsset = new TextAsset(asset, true);
if (!ustudio.ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString)) if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
{ {
ustudio.ExportText(m_TextAsset, exportpath + asset.Text + asset.extension); ExportText(m_TextAsset, exportpath + asset.Text + asset.extension);
exportedCount++; exportedCount++;
} }
break; break;
case 114: case 114:
MonoBehaviour m_MonoBehaviour = new MonoBehaviour(asset, true); MonoBehaviour m_MonoBehaviour = new MonoBehaviour(asset, true);
if (!ustudio.ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString)) if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
{ {
ustudio.ExportMonoBehaviour(m_MonoBehaviour, exportpath + asset.Text + asset.extension); ExportMonoBehaviour(m_MonoBehaviour, exportpath + asset.Text + asset.extension);
exportedCount++; exportedCount++;
} }
break; break;
case 128: case 128:
unityFont m_Font = new unityFont(asset, true); unityFont m_Font = new unityFont(asset, true);
if (!ustudio.ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString)) if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
{ {
ustudio.ExportFont(m_Font, exportpath + asset.Text + asset.extension); ExportFont(m_Font, exportpath + asset.Text + asset.extension);
exportedCount++; exportedCount++;
} }
break; break;
default: default:
if (!ustudio.ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString)) if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
{ {
ustudio.ExportRawFile(asset, exportpath + asset.Text + asset.extension); ExportRawFile(asset, exportpath + asset.Text + asset.extension);
exportedCount++; exportedCount++;
} }
break; break;
@ -1400,11 +1384,11 @@ namespace Unity_Studio
statusText = "Nothing exported."; statusText = "Nothing exported.";
break; break;
default: default:
statusText = "Finished exporting " + exportedCount.ToString() + " assets."; statusText = "Finished exporting " + exportedCount + " assets.";
break; break;
} }
if (toExport > exportedCount) { statusText += " " + (toExport - exportedCount).ToString() + " assets skipped (not extractable or files already exist)"; } if (toExport > exportedCount) { statusText += " " + (toExport - exportedCount) + " assets skipped (not extractable or files already exist)"; }
StatusStripUpdate(statusText); StatusStripUpdate(statusText);
@ -1465,6 +1449,18 @@ namespace Unity_Studio
} }
} }
private void ProgressBarMaximumAdd(int value)
{
if (InvokeRequired)
{
BeginInvoke(new Action(() => { progressBar1.Maximum += value; }));
}
else
{
progressBar1.Maximum += value;
}
}
public UnityStudioForm() public UnityStudioForm()
{ {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
@ -1475,6 +1471,12 @@ namespace Unity_Studio
openAfterExport.Checked = (bool)Properties.Settings.Default["openAfterExport"]; openAfterExport.Checked = (bool)Properties.Settings.Default["openAfterExport"];
assetGroupOptions.SelectedIndex = (int)Properties.Settings.Default["assetGroupOption"]; assetGroupOptions.SelectedIndex = (int)Properties.Settings.Default["assetGroupOption"];
FMODinit(); FMODinit();
//UI
UnityStudio.SetProgressBarValue = SetProgressBarValue;
UnityStudio.SetProgressBarMaximum = SetProgressBarMaximum;
UnityStudio.ProgressBarPerformStep = ProgressBarPerformStep;
UnityStudio.StatusStripUpdate = StatusStripUpdate;
UnityStudio.ProgressBarMaximumAdd = ProgressBarMaximumAdd;
} }
private void resetForm() private void resetForm()
@ -1486,10 +1488,10 @@ namespace Unity_Studio
base.Text = "Unity Studio"; base.Text = "Unity Studio";
ustudio.unityFiles.Clear(); unityFiles.Clear();
ustudio.assetsfileList.Clear(); assetsfileList.Clear();
ustudio.exportableAssets.Clear(); exportableAssets.Clear();
ustudio.visibleAssets.Clear(); visibleAssets.Clear();
UnityStudio.assetsfileandstream.Clear(); UnityStudio.assetsfileandstream.Clear();
sceneTreeView.Nodes.Clear(); sceneTreeView.Nodes.Clear();
@ -1518,15 +1520,5 @@ namespace Unity_Studio
FMODreset(); FMODreset();
} }
private void UnityStudioForm_FormClosing(object sender, FormClosingEventArgs e)
{
/*Properties.Settings.Default["uniqueNames"] = uniqueNamesMenuItem.Checked;
Properties.Settings.Default["enablePreview"] = enablePreviewMenuItem.Checked;
Properties.Settings.Default["displayInfo"] = displayAssetInfoMenuItem.Checked;
Properties.Settings.Default.Save();
foreach (var assetsFile in assetsfileList) { assetsFile.a_Stream.Dispose(); } //is this needed?*/
}
} }
} }