Ai
1 Star 0 Fork 1

renhong/MyToLua

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CopyAndUpdateMainApp.cs 5.13 KB
一键复制 编辑 原始数据 按行查看 历史
zhouzhanglin 提交于 2018-04-26 11:07 +08:00 . no message
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text.RegularExpressions;
/// <summary>
/// 用于在子App中,将主App的代码和资源复制到子App中
/// </summary>
public class CopyAndUpdateMainApp : MonoBehaviour {
private static string _MainAppFolder = "/../bsgmainapp-unity-lua/";
private static string[] _dirs = new string[]{
"Assets/Spine/","Assets/Sqlitekit/","LuaEncoder/",
"Assets/Lua/Comm/","Assets/LuaFramework/",
"Assets/Plugins/Android/","Assets/Plugins/iOS/","Assets/Assets/Plugins/x86/","Assets/Plugins/x86_64/","Assets/Plugins/tolua.bundle",
"Assets/StreamingAssets/mainapp","Assets/StreamingAssets/mainappraw"
};
private static string[] _files = new string[]
{
"Assets/Plugins/CString.dll","Assets/Plugins/Debugger.dll",
"ProjectSettings/TagManager.asset","ProjectSettings/TimeManager.asset",
"ProjectSettings/Physics2DSettings.asset"
};
[MenuItem("LuaFramework/Copy And Update MainApp", false, 250)]
static void Execute(){
//MainApp路径
string currProjPath = Application.dataPath.Substring(0,Application.dataPath.Length-7);
int count = Regex.Matches(_MainAppFolder,@"(\..)").Count;
string src = currProjPath;
DirectoryInfo dirInfo = new DirectoryInfo(src);
for (int i = 0; i < count; ++i)
{
dirInfo = dirInfo.Parent;
}
src = dirInfo.FullName + _MainAppFolder.Replace("../","");
//复制文件夹
foreach (string dir in _dirs)
{
string srcFolder = src + "/" + dir;
string destFolder = currProjPath + "/" + dir;
if (Directory.Exists(srcFolder))
{
if (Directory.Exists(destFolder))
{
Directory.Delete(destFolder,true);
}
Directory.CreateDirectory(destFolder);
CopyDirectory(srcFolder,destFolder,true);
}
if (File.Exists(srcFolder + ".meta"))
{
File.Copy(srcFolder + ".meta",destFolder + ".meta",true);
}
}
//复制文件
foreach (string file in _files)
{
string srcFolder = src + "/" + Path.GetDirectoryName(file) + "/";
string destFolder = currProjPath + "/" + Path.GetDirectoryName(file)+ "/";
if (!Directory.Exists(Path.GetDirectoryName(destFolder)))
{
Directory.CreateDirectory(destFolder);
}
string fileUrl = srcFolder + Path.GetFileName(file);
if (File.Exists(fileUrl))
{
Debug.LogError(fileUrl + " >> " +currProjPath + "/" + file );
File.Copy(fileUrl,currProjPath + "/" + file,true);
}
if (File.Exists(fileUrl+ ".meta"))
{
File.Copy(fileUrl + ".meta", currProjPath + "/" + file + ".meta",true);
}
}
AssetDatabase.Refresh();
}
[MenuItem("LuaFramework/Copy Export To Test", false, 251)]
static void Execute1(){
//MainApp路径
string currProjPath = Application.dataPath.Substring(0,Application.dataPath.Length-7);
int count = Regex.Matches(_MainAppFolder,@"(\..)").Count;
string dest = currProjPath;
DirectoryInfo dirInfo = new DirectoryInfo(dest);
for (int i = 0; i < count; ++i)
{
dirInfo = dirInfo.Parent;
}
dest = dirInfo.FullName + _MainAppFolder.Replace("../","");
string destFolder = dest + "/MainApp.app/Contents/Resources/Data/StreamingAssets";
string srcFolder = Application.streamingAssetsPath;
if (Directory.Exists(destFolder) && Directory.Exists(srcFolder))
{
if (Directory.Exists(destFolder))
{
Directory.Delete(destFolder,true);
}
Directory.CreateDirectory(destFolder);
CopyDirectory(srcFolder,destFolder,true);
}
}
static void CopyDirectory(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, true);
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
CopyDirectory(subdir.FullName, temppath, copySubDirs);
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/magicscience_admin/MyToLua.git
git@gitee.com:magicscience_admin/MyToLua.git
magicscience_admin
MyToLua
MyToLua
master

搜索帮助