Skip to content

Commit

Permalink
修复perfab导出bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjgameer committed Jul 4, 2023
1 parent d93f77c commit c800c36
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
11 changes: 4 additions & 7 deletions Export/filter/PerfabFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ internal class PerfabFile :FileData
{
private static bool isPerfabAsset(GameObject gameObject)
{
var isprefab = PrefabUtility.GetPrefabType(gameObject);//物体的PrefabType
if (isprefab != PrefabType.PrefabInstance)//不是Prefab实例
return false;
PrefabAssetType type = PrefabUtility.GetPrefabAssetType(gameObject);//物体的PrefabType
if (type == PrefabAssetType.Regular|| type == PrefabAssetType.Variant)//不是Prefab实例
return true;

var prefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
if (prefab == null)
return false;
return true;
return false;
}
/**
*获得对象所在perfab资源的路径
Expand Down
39 changes: 33 additions & 6 deletions Export/resoure/NodeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void createRootPartner(GameObject gameObject)
}
}

private List<string> getRefectIndex(GameObject gameObject)
private List<string> getRefectIndex(GameObject gameObject,bool contentRoot = false)
{
GameObject root = PerfabFile.getPrefabInstanceRoot(gameObject);
List<OriderIndex> nodeList = new List<OriderIndex>();
Expand All @@ -141,6 +141,10 @@ private List<string> getRefectIndex(GameObject gameObject)
foundObject = foundObject.transform.parent.gameObject;
}
List<string> outIndex = new List<string>();
if (contentRoot)
{
outIndex.Add(this.getGameObjectId(root));
}
if (this.refMap.ContainsKey(root))
{
OriderIndex oriderIndex = new OriderIndex();
Expand Down Expand Up @@ -202,7 +206,20 @@ public string getGameObjectId(GameObject gameObject)
public JSONObject getRefNodeIdObjet(GameObject gameObject)
{
JSONObject data = new JSONObject(JSONObject.Type.OBJECT);
data.AddField("_$ref",this.getGameObjectId(gameObject));
if (this.nodeIdMaps.ContainsKey(gameObject)){
data.AddField("_$ref", this.getGameObjectId(gameObject));
}
else
{
List<string> outIndex = this.getRefectIndex(gameObject,true);
JSONObject overrideIndex = new JSONObject(JSONObject.Type.ARRAY);
foreach (var index in outIndex)
{
overrideIndex.Add(index);
}
data.AddField("_$ref", overrideIndex);
}

return data;
}

Expand Down Expand Up @@ -254,11 +271,11 @@ public JSONObject getJsonObject(GameObject gameObject)
private JSONObject getOverrideObject(GameObject gameObject,GameObject root)
{
JSONObject childdata;
if (!this.overrideMaps.TryGetValue(gameObject, out childdata))
if (gameObject != root)
{
childdata = new JSONObject(JSONObject.Type.OBJECT);
if(gameObject != root)
if (!this.overrideMaps.TryGetValue(gameObject, out childdata))
{
childdata = new JSONObject(JSONObject.Type.OBJECT);
List<string> outIndex = this.getRefectIndex(gameObject);
JSONObject overrideIndex = new JSONObject(JSONObject.Type.ARRAY);
foreach (var index in outIndex)
Expand All @@ -270,6 +287,11 @@ private JSONObject getOverrideObject(GameObject gameObject,GameObject root)
this.addChildToPartner(childdata, this.getJsonObject(root));
}
}
else
{
childdata = this.getJsonObject(gameObject);
}


return childdata;
}
Expand All @@ -289,7 +311,12 @@ public void writeCompoent()
{
foreach (var node in this.nodeMaps)
{
this._resoureMap.getComponentsData(node.Key, node.Value, this);
GameObject gameObject = node.Key;
if(gameObject != PerfabFile.getPerfabObject(gameObject))
{
this._resoureMap.getComponentsData(node.Key, node.Value, this);
}

}

foreach (var remap in this.refMap)
Expand Down

0 comments on commit c800c36

Please sign in to comment.