Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit44c43c1

Browse files
committed
add NavMeshFileExtractor
1 parent587c90d commit44c43c1

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
usingUnityEditor;
2+
usingUnityEngine;
3+
usingSystem.IO;
4+
usingSystem.IO.Compression;
5+
usingSystem.Collections.Generic;
6+
7+
namespaceSanAndreasUnity.Editor
8+
{
9+
[InitializeOnLoad]
10+
publicclassNavMeshFileExtractor
11+
{
12+
privateconststringNavMeshesFolderPath="NavMeshes/";
13+
privateconststringNavMeshesArchiveFileName="NavMeshes.zip";
14+
15+
16+
staticNavMeshFileExtractor()
17+
{
18+
stringfullFolderPath=Path.Combine(Application.dataPath,NavMeshesFolderPath);
19+
20+
if(!Directory.Exists(fullFolderPath))
21+
{
22+
Debug.LogError("Failed to extract nav mesh files: folder with nav meshes not found");
23+
return;
24+
}
25+
26+
stringzipFilePath=Path.Combine(fullFolderPath,NavMeshesArchiveFileName);
27+
if(!File.Exists(zipFilePath))
28+
return;
29+
30+
Debug.Log("Attempting to extract nav mesh files");
31+
32+
varextractedFileNames=newList<string>();
33+
longtotalFileSizeExtracted=0;
34+
35+
usingvarzipArchive=newZipArchive(File.OpenRead(zipFilePath),ZipArchiveMode.Read);
36+
foreach(varentryinzipArchive.Entries)
37+
{
38+
if(string.IsNullOrWhiteSpace(entry.Name))
39+
continue;
40+
41+
usingvarwriteStream=File.OpenWrite(Path.Combine(fullFolderPath,entry.Name));
42+
usingvarentryStream=entry.Open();
43+
entryStream.CopyTo(writeStream,4*1024*1024);
44+
writeStream.Flush(true);
45+
46+
writeStream.Dispose();
47+
entryStream.Dispose();
48+
49+
extractedFileNames.Add(entry.Name);
50+
totalFileSizeExtracted+=entry.Length;
51+
}
52+
53+
// close archive so it can be deleted
54+
zipArchive.Dispose();
55+
56+
// delete zip file to reduce size of project, and to prevent it from being extracted again
57+
File.Delete(zipFilePath);
58+
59+
// also delete it's meta file
60+
stringmetaFilePath=zipFilePath+".meta";
61+
if(File.Exists(metaFilePath))
62+
File.Delete(metaFilePath);
63+
64+
AssetDatabase.Refresh();
65+
66+
Debug.Log($"Successfully extracted nav mesh files, total extracted files' size{totalFileSizeExtracted}, "+
67+
$"files extracted:\n{string.Join("\n",extractedFileNames)}");
68+
}
69+
}
70+
}

‎Assets/Scripts/Editor/NavMeshFileExtractor.cs.meta‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp