Skip to content

Commit

Permalink
修改perfab导出bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjgameer committed Jun 28, 2023
1 parent 9265d8c commit d93f77c
Show file tree
Hide file tree
Showing 14 changed files with 406 additions and 795 deletions.
14 changes: 3 additions & 11 deletions Export/filter/AnimationClipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@

internal class AnimationClipFile : FileData
{
private string outUrl;
private AnimationClip m_clip;
private GameObject m_root;
override public string outPath
{
get
{
return ExportConfig.SavePath() + "/" + this.outUrl;
}
}
public AnimationClipFile(AnimationClip clip,GameObject root):base(null)
{
this.m_clip = clip;
this.m_root = root;
string path = AssetsUtil.GetAnimationClipPath(clip);
this.updatePath(path);
this.outUrl = path;
this.updatePath(AssetsUtil.GetAnimationClipPath(clip));
}


public override void SaveFile(Dictionary<string, FileData> exportFiles)
{
base.saveMeta();
Expand Down
11 changes: 7 additions & 4 deletions Export/filter/FileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal class FileData
public ResoureMap resoureMap;
protected string m_path;
private string m_uuid;

protected string m_outPath;
protected JSONObject m_metaData;
public string metaPath
{
Expand All @@ -28,7 +28,7 @@ virtual public string outPath
{
get
{
return ExportConfig.SavePath() + "/" + this.m_path;
return ExportConfig.SavePath() + "/" + this.m_outPath;
}
}

Expand All @@ -51,7 +51,7 @@ protected void updatePath(string path)
return;
}
this.m_path = path;

this.m_outPath = this.getOutFilePath(path);
if (File.Exists(metaPath))
{
JSONObject customMap = this.m_metaData = JSONObject.Create(File.ReadAllText(metaPath));
Expand All @@ -64,7 +64,10 @@ protected void updatePath(string path)
this.m_metaData.SetField("uuid", this.m_uuid);
}
}

virtual protected string getOutFilePath(string path)
{
return path;
}
public JSONObject metaData()
{
return this.m_metaData;
Expand Down
14 changes: 9 additions & 5 deletions Export/filter/HierarchyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public HierarchyFile()
}
continue;
}
perfabList.Add(rt, perfabRoot);//增加到列表中
perfabList.Add(rt, perfabRoot);//增加到列表中=
}
this.resouremap = new ResoureMap(perfabList);
this.nodeMap = this.resouremap.addNodeMap(2);
this.nodeMap = this.resouremap.AddNodeMap(2);

GameObject[] gameObjects = SceneManager.GetActiveScene().GetRootGameObjects();

Expand All @@ -51,6 +51,10 @@ private void getGameObjectData(GameObject gameObject)
if (this.notPerfabNodes.Contains(gameObject))
{
JSONObject nodeData = JsonUtils.GetGameObject(gameObject);
if(!gameObject.activeInHierarchy&& ExportConfig.IgnoreNotActiveGameObject)
{
return;
}
this.nodeMap.addNodeMap(gameObject, nodeData, gameObject == PerfabFile.getPerfabObject(gameObject));
}
if (gameObject.transform.childCount > 0)
Expand Down Expand Up @@ -78,7 +82,7 @@ public void saveAllFile(bool isScene)
}
}

this.resouremap.saveAllFile();
this.resouremap.SaveAllFile();
}

private void getSceneNode()
Expand Down Expand Up @@ -106,7 +110,7 @@ private void getSceneNode()
{
JSONObject skyRender = new JSONObject(JSONObject.Type.OBJECT);
skyRender.AddField("meshType", "dome");
JSONObject filedata = this.resouremap.getMaterialData(skyBoxMaterial);
JSONObject filedata = this.resouremap.GetMaterialData(skyBoxMaterial);
skyRender.AddField("material", filedata);
scene3dNode.AddField("skyRenderer", skyRender);
}
Expand All @@ -125,7 +129,7 @@ private void getSceneNode()
ambientProbe.AddField("_$type", "Float32Array");
JSONObject ambientValue = new JSONObject(JSONObject.Type.ARRAY);
ambientProbe.AddField("value", ambientValue);
this.resouremap.getSHOrigin(ambientValue);
this.resouremap.GetSHOrigin(ambientValue);
scene3dNode.AddField("ambientSphericalHarmonicsIntensity", RenderSettings.ambientIntensity);
}
else
Expand Down
17 changes: 6 additions & 11 deletions Export/filter/MaterialFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@

internal class MaterialFile : JsonFile
{
private string outUrl;
private Material m_material;
override public string outPath
{
get
{
return ExportConfig.SavePath() + "/" + this.outUrl;
}
}
public MaterialFile(ResoureMap map, Material material) : base(null,new JSONObject(JSONObject.Type.OBJECT))
{
this.resoureMap = map;
string materialPath = AssetsUtil.GetMaterialPath(material);
this.updatePath(materialPath);
this.outUrl = GameObjectUitls.cleanIllegalChar(materialPath.Split('.')[0], false) + ".lmat";
this.updatePath(AssetsUtil.GetMaterialPath(material));
this.m_material = material;
if(material.shader.name == "Skybox/6 Sided")
{
Expand All @@ -33,6 +23,11 @@ public MaterialFile(ResoureMap map, Material material) : base(null,new JSONObjec

}

protected override string getOutFilePath(string path)
{
return GameObjectUitls.cleanIllegalChar(path.Split('.')[0], false) + ".lmat";
}

public override void SaveFile(Dictionary<string, FileData> exportFiles)
{
base.saveMeta();
Expand Down
11 changes: 1 addition & 10 deletions Export/filter/MeshFile.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@

using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

internal class MeshFile : FileData
{
private Mesh m_mesh;
private string outUrl;
private Renderer render;
override public string outPath
{
get
{
return ExportConfig.SavePath() + "/" + this.outUrl;
}
}

public MeshFile(Mesh mesh,Renderer render) :base(null)
{
string path = AssetsUtil.GetMeshPath(mesh);
this.updatePath(path);
this.outUrl = path;
this.m_mesh = mesh;
this.render = render;
}
Expand Down
11 changes: 3 additions & 8 deletions Export/filter/PerfabFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@ public static GameObject getPrefabInstanceRoot(GameObject gameObject)
{
return null;
}
//return PrefabUtility.FindValidUploadPrefabInstanceRoot(gameObject);//物体的Prefab根节点
return PrefabUtility.GetOutermostPrefabInstanceRoot(gameObject);//物体的Prefab根节点
}

private GameObject gameObject;
private NodeMap _nodeMap;
private string outUrl;
public PerfabFile(NodeMap nodeMap,string perfabPath) : base(perfabPath)
{
this.outUrl = perfabPath.Replace(".prefab", ".lh");
this.gameObject = PrefabUtility.LoadPrefabContents(perfabPath) as GameObject;
this._nodeMap = nodeMap;
this.getGameObjectData(this.gameObject,true);
Expand All @@ -73,12 +70,10 @@ public NodeMap nodeMap
return this._nodeMap;
}
}
override public string outPath

override protected string getOutFilePath(string path)
{
get
{
return ExportConfig.SavePath() + "/" + this.outUrl;
}
return path.Replace(".prefab", ".lh");
}

private JSONObject getGameObjectData(GameObject gameObject, bool isperfab = false)
Expand Down
105 changes: 43 additions & 62 deletions Export/filter/TextureFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static void init()
ConvertOriginalTextureTypeList.Add(".HDR");
}
public static string LOGHEAD = "LayaAir3D UnityPlugin: ";
private string _originPath;
private Texture2D _texture;
private JSONObject _constructParams;
private JSONObject _propertyParams;
Expand All @@ -51,61 +50,14 @@ public static void init()
public TextureFile(string originPath, Texture2D texture, bool isNormal) : base(null)
{
this._texture = texture;
this._originPath = originPath;
this._isNormal = isNormal;
this.getTexureInfo();
this.updatePath(originPath);
this.getTextureInfo();
}

override public string filePath
{
get
{
return this._originPath;
}
}
private int getFormat()
{
switch (this._texture.format)
{
case TextureFormat.DXT1:
return 3;
case TextureFormat.DXT5:
return 5;
case TextureFormat.RGB24:
return 0;
default:
return 1;
}
}
private void getTexureInfo()
private void getTextureInfo()
{
Texture2D texture = this._texture;
if (this._texture == null)
{
return;
}

this._format = this.getFormat();

var origpath = this._originPath;
string ext = Path.GetExtension(origpath).ToLower();
this._isCopy = ConvertOriginalTextureTypeList.IndexOf(ext) != -1;
string savePath = origpath.Substring(0, origpath.LastIndexOf("."));
this._rgbmEncoding = ext == ".hdr" || ext == ".exr";
if (this._rgbmEncoding)
{
savePath += ConvertOriginalTextureTypeList.IndexOf(ext) == -1 ? ".hdr" : ext;
}
else if (this._format == 0)
{
savePath += ConvertOriginalTextureTypeList.IndexOf(ext) == -1 ? ".jpg" : ext;
}
else
{
savePath += ConvertOriginalTextureTypeList.IndexOf(ext) == -1 ? ".png" : ext;
}
this.updatePath(savePath);

this._constructParams = new JSONObject(JSONObject.Type.ARRAY);
this._propertyParams = new JSONObject(JSONObject.Type.ARRAY);

Expand All @@ -115,7 +67,6 @@ private void getTexureInfo()
{
FileUtil.setStatuse(false);
Debug.LogError(LOGHEAD + path + " can't export You should check the texture file format");
return;
}
else
{
Expand Down Expand Up @@ -216,9 +167,43 @@ private void getTexureInfo()
this._propertyParams.AddField("wrapModeV", 0);
}


this._propertyParams.AddField("anisoLevel", anisoLevel);
}

private int getFormat()
{
switch (this._texture.format)
{
case TextureFormat.DXT1:
return 3;
case TextureFormat.DXT5:
return 5;
case TextureFormat.RGB24:
return 0;
default:
return 1;
}
}
override protected string getOutFilePath(string origpath)
{
this._format = this.getFormat();
string ext = Path.GetExtension(origpath).ToLower();
this._isCopy = ConvertOriginalTextureTypeList.IndexOf(ext) != -1;
string savePath = origpath.Substring(0, origpath.LastIndexOf("."));
this._rgbmEncoding = ext == ".hdr" || ext == ".exr";
if (this._rgbmEncoding)
{
savePath += ConvertOriginalTextureTypeList.IndexOf(ext) == -1 ? ".hdr" : ext;
}
else if (this._format == 0)
{
savePath += ConvertOriginalTextureTypeList.IndexOf(ext) == -1 ? ".jpg" : ext;
}
else
{
savePath += ConvertOriginalTextureTypeList.IndexOf(ext) == -1 ? ".png" : ext;
}
return savePath;
}

public JSONObject jsonObject(string name)
Expand Down Expand Up @@ -345,15 +330,11 @@ public void gammaColorsToLinear(Color[] gColor)
}
public override void SaveFile(Dictionary<string, FileData> exportFiles)
{
string filePath = outPath;
string folder = Path.GetDirectoryName(filePath);
if (!Directory.Exists(folder))
Directory.CreateDirectory(folder);
base.saveMeta();
string path = AssetDatabase.GetAssetPath(this._texture.GetInstanceID());
string filePath = this.filePath;
if (this._isCopy)
{
File.Copy(path, filePath, true);
File.Copy(filePath, this.outPath, true);
}
else{
if (this._rgbmEncoding)
Expand All @@ -364,17 +345,17 @@ public override void SaveFile(Dictionary<string, FileData> exportFiles)
Debug.Log("Current color space is gamma.. Your Img will change to Linear Space");
gammaColorsToLinear(pixels);
}
this.exportHDRFile(filePath, pixels, this._texture.height, this._texture.width);
this.exportHDRFile(this.outPath, pixels, this._texture.height, this._texture.width);
}
else if (this._format == 1)
{
byte[] bytes = this._texture.EncodeToPNG();
File.WriteAllBytes(filePath, bytes);
File.WriteAllBytes(this.outPath, bytes);
}
else if (this._format == 0)
{
byte[] bytes = this._texture.EncodeToJPG();
File.WriteAllBytes(filePath, bytes);
File.WriteAllBytes(this.outPath, bytes);
}
}
}
Expand Down
Loading

0 comments on commit d93f77c

Please sign in to comment.