public void Parse(EndianStream stream) { switch (UnityType) { case ClassIDType.GameObject: Object = new GameObject(AssetInfo); break; case ClassIDType.Transform: Object = new Transform(AssetInfo); break; case ClassIDType.Material: Object = new Material(AssetInfo); break; case ClassIDType.MeshRenderer: Object = new MeshRenderer(AssetInfo); break; case ClassIDType.MeshFilter: Object = new MeshFilter(AssetInfo); break; case ClassIDType.Mesh: Object = new Mesh(AssetInfo); break; case ClassIDType.Shader: if (SShader.IsSerialized(AssetInfo.AssetFile.Version)) { Object = new SShader(AssetInfo); } else { Object = new Shader(AssetInfo); } break; case ClassIDType.TextAsset: Object = new TextAsset(AssetInfo); break; case ClassIDType.AnimationClip: Object = new AnimationClip(AssetInfo); break; case ClassIDType.Avatar: Object = new Avatar(AssetInfo); break; case ClassIDType.AnimatorController: Object = new AnimatorController(AssetInfo); break; case ClassIDType.Animator: Object = new Animator(AssetInfo); break; case ClassIDType.Animation: Object = new Animation(AssetInfo); break; case ClassIDType.MonoScript: Object = new MonoScript(AssetInfo); break; case ClassIDType.SkinnedMeshRenderer: Object = new SkinnedMeshRenderer(AssetInfo); break; case ClassIDType.BuildSettings: Object = new BuildSettings(AssetInfo); break; case ClassIDType.AssetBundle: Object = new AssetBundle(AssetInfo); break; case ClassIDType.AnimatorOverrideController: Object = new AnimatorOverrideController(AssetInfo); break; case ClassIDType.RectTransform: Object = new RectTransform(AssetInfo); break; default: return; } stream.BaseStream.Position = m_offset; if (Config.IsGenerateGUIDByContent) { if (m_length > int.MaxValue) { throw new Exception($"Can't read enough data {m_length}"); } byte[] data = stream.ReadBytes((int)m_length); Object.Read(data); } else { stream.StartPosition = m_offset; Object.Read(stream); long read = stream.BaseStream.Position - m_offset; if (read != m_length) { throw new Exception($"Read {read} but expected {m_length}"); } } }
private void Test(AssetsFile file) { foreach (AssetPreloadData preload in file.PreloadData) { switch (preload.UnityType) { case ClassIDType.SkinnedMeshRenderer: //SkinnedMeshRenderer skin = (SkinnedMeshRenderer)preload.RetreaveObject(preload.AssetInfo); //Exporter.Export(skin, "D:\\Test\\1\\"); break; case ClassIDType.Mesh: //Mesh mesh = (Mesh)preload.RetreaveObject(preload.AssetInfo); //string mpath = Path.Combine("D:\\Test\\Mesh\\", mesh.Name); //mpath = $"{mpath}.{mesh.ExportExtension}"; //YAMLExporter.Export(mesh, mpath); break; case ClassIDType.AnimationClip: //AnimationClip clip = (AnimationClip)preload.RetreaveObject(preload.AssetInfo); //string cpath = Path.Combine("D:\\Test\\AnimationClip\\", clip.Name); //cpath = $"{cpath}.{clip.ExportExtension}"; //YAMLExporter.Export(clip, cpath); break; case ClassIDType.Material: //Material mat = (Material)preload.RetreaveObject(preload.AssetInfo); //string matpath = Path.Combine("D:\\Test\\Material\\", mat.Name); //matpath = $"{matpath}.{mat.ExportExtension}"; //YAMLExporter.Export(mat, matpath); break; case ClassIDType.Shader: if (SShader.IsSerialized(file.Version)) { //SShader shader = (SShader)preload.RetreaveObject(preload.AssetInfo); } else { /*Shader shader = (Shader)preload.RetreaveObject(preload.AssetInfo); * string shaderpath = Path.Combine("D:\\Test\\Shader\\", shader.Name); * shaderpath = $"{shaderpath}.{shader.ExportExtension}"; * using (FileStream fileStream = File.Open(shaderpath, FileMode.Create, FileAccess.Write)) * { * byte[] content = shader.ExportBinary(); * fileStream.Write(content, 0, content.Length); * }*/ } break; case ClassIDType.TextAsset: /*TextAsset text = (TextAsset)preload.RetreaveObject(preload.AssetInfo); * string textpath = Path.Combine("D:\\Test\\Text\\", text.Name); * textpath = $"{textpath}.{text.ExportExtension}"; * using (FileStream fileStream = File.Open(textpath, FileMode.Create, FileAccess.Write)) * { * byte[] content = text.ExportBinary(); * fileStream.Write(content, 0, content.Length); * }*/ break; default: //preload.RetreaveObject(preload.AssetInfo); break; } } }