Skip to content

Commit fe4c539

Browse files
committed
修复打包路径相对路径的一些问题
1 parent 668dbb9 commit fe4c539

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

Assets/Game/Scripts/State/CheckResourceState.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public override void OnEnter(params object[] parameters)
6060
GameMode.Event.AddListener<DownloadProgressEventArgs>(OnDownloadProgress);
6161

6262
_localVersion=LoadLocalVersion();
63+
64+
//从StreamingAsset复制到读写路径下
65+
if (_localVersion == null)
66+
{
67+
MoveFiles(Application.streamingAssetsPath, Application.persistentDataPath);
68+
_localVersion = LoadLocalVersion();
69+
}
70+
6371
LoadRemoteVersion();
6472
}
6573

@@ -256,7 +264,34 @@ private string GetPlatformName()
256264
#endif
257265
return platformName.ToLower();
258266
}
259-
#endregion
267+
268+
//获取文件
269+
private string[] GetFiles(string path)
270+
{
271+
List<string> files = new List<string>();
272+
files.AddRange(Directory.GetFiles(path));
273+
foreach (var item in Directory.GetDirectories(path))
274+
{
275+
files.AddRange(GetFiles(item));
276+
}
277+
return files.ToArray();
278+
}
279+
280+
//移动物体
281+
private void MoveFiles(string srcPath, string dstPath)
282+
{
283+
string[] files = GetFiles(srcPath);
284+
foreach (var item in files)
285+
{
286+
string targetPath = item.Replace(srcPath, dstPath);
287+
string dirPath = Path.GetDirectoryName(targetPath);
288+
if (!Directory.Exists(dirPath))
289+
Directory.CreateDirectory(dirPath);
290+
File.Copy(item, targetPath, true);
291+
}
292+
}
293+
294+
#endregion
260295

261296
}
262297
}

Assets/GameFramework/Editor/AssetBundleEditor/AssetBundleBuildEditor.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public class AssetBundleBuildEditor :EditorWindow {
2828
[MenuItem("Tools/AssetBundles Options %#O")]
2929
public static void AssetBundilesOptions()
3030
{
31-
_rootPath=Path.GetDirectoryName(Application.dataPath);
31+
_rootPath = Path.GetDirectoryName(Path.GetFullPath(Application.dataPath));
3232

33-
LoadConfig();
33+
LoadConfig();
3434

35-
BuildTarget[] allTargets= (BuildTarget[])Enum.GetValues(typeof(BuildTarget));
36-
//_allTargets
37-
foreach (var item in allTargets)
35+
BuildTarget[] allTargets = (BuildTarget[])Enum.GetValues(typeof(BuildTarget));
36+
//_allTargets
37+
foreach (var item in allTargets)
3838
{
3939
int index=(int)item;
4040
if(_config.BuildTargets.Contains(index))
@@ -115,9 +115,10 @@ void OnGUI()
115115
path=EditorUtility.OpenFolderPanel("Build Path",path,"");
116116
if(!string.IsNullOrEmpty(path))
117117
{
118-
if(path.Contains(_rootPath))
119-
{
120-
path=path.Replace(_rootPath,"");
118+
path = Path.GetFullPath(path);
119+
if (path.Contains(_rootPath))
120+
{
121+
path = path.Replace(_rootPath, "").Replace("\\", "/");
121122
if(path.IndexOf("/")==0)
122123
{
123124
path= path.Substring(1,path.Length-1);

0 commit comments

Comments
 (0)