Skip to content

Commit

Permalink
use list to store objects in their original order
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Mar 28, 2020
1 parent c4270e1 commit e1dc54d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
5 changes: 2 additions & 3 deletions AssetStudio/AssetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ private void ReadAssets()
Progress.Reset();
foreach (var assetsFile in assetsFileList)
{
assetsFile.Objects = new Dictionary<long, Object>(assetsFile.m_Objects.Count);
foreach (var objectInfo in assetsFile.m_Objects)
{
var objectReader = new ObjectReader(assetsFile.reader, assetsFile, objectInfo);
Expand Down Expand Up @@ -338,7 +337,7 @@ private void ReadAssets()
obj = new Object(objectReader);
break;
}
assetsFile.Objects.Add(objectInfo.m_PathID, obj);
assetsFile.AddObject(obj);
}
catch (Exception e)
{
Expand All @@ -362,7 +361,7 @@ private void ProcessAssets()

foreach (var assetsFile in assetsFileList)
{
foreach (var obj in assetsFile.Objects.Values)
foreach (var obj in assetsFile.Objects)
{
if (obj is GameObject m_GameObject)
{
Expand Down
4 changes: 2 additions & 2 deletions AssetStudio/Classes/PPtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public bool TryGet(out T result)
{
if (TryGetAssetsFile(out var sourceFile))
{
if (sourceFile.Objects.TryGetValue(m_PathID, out var obj))
if (sourceFile.ObjectsDic.TryGetValue(m_PathID, out var obj))
{
if (obj is T variable)
{
Expand All @@ -75,7 +75,7 @@ public bool TryGet<T2>(out T2 result) where T2 : Object
{
if (TryGetAssetsFile(out var sourceFile))
{
if (sourceFile.Objects.TryGetValue(m_PathID, out var obj))
if (sourceFile.ObjectsDic.TryGetValue(m_PathID, out var obj))
{
if (obj is T2 variable)
{
Expand Down
11 changes: 10 additions & 1 deletion AssetStudio/SerializedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class SerializedFile
public string fileName;
public int[] version = { 0, 0, 0, 0 };
public BuildType buildType;
public Dictionary<long, Object> Objects;
public List<Object> Objects;
public Dictionary<long, Object> ObjectsDic;

public SerializedFileHeader header;
private EndianType m_FileEndianess;
Expand Down Expand Up @@ -100,6 +101,8 @@ public SerializedFile(AssetsManager assetsManager, string fullName, EndianBinary
//ReadObjects
int objectCount = reader.ReadInt32();
m_Objects = new List<ObjectInfo>(objectCount);
Objects = new List<Object>(objectCount);
ObjectsDic = new Dictionary<long, Object>(objectCount);
for (int i = 0; i < objectCount; i++)
{
var objectInfo = new ObjectInfo();
Expand Down Expand Up @@ -331,6 +334,12 @@ string ReadString(BinaryReader stringBufferReader, uint value)
}
}

public void AddObject(Object obj)
{
Objects.Add(obj);
ObjectsDic.Add(obj.m_PathID, obj);
}

public static bool IsSerializedFile(EndianBinaryReader reader)
{
var fileSize = reader.BaseStream.Length;
Expand Down
4 changes: 2 additions & 2 deletions AssetStudioGUI/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static (string, List<TreeNode>) BuildAssetData()
{
var tempExportableAssets = new List<AssetItem>();
Dictionary<long, string> containers = null;
foreach (var asset in assetsFile.Objects.Values)
foreach (var asset in assetsFile.Objects)
{
var assetItem = new AssetItem(asset);
objectAssetItemDic.Add(asset, assetItem);
Expand Down Expand Up @@ -230,7 +230,7 @@ public static (string, List<TreeNode>) BuildAssetData()
{
var fileNode = new GameObjectTreeNode(assetsFile.fileName); //RootNode

foreach (var obj in assetsFile.Objects.Values)
foreach (var obj in assetsFile.Objects)
{
if (obj is GameObject m_GameObject)
{
Expand Down

0 comments on commit e1dc54d

Please sign in to comment.