您的位置:首页 > 移动开发 > Unity3D

Unity 文件复制工具

2016-09-05 13:37 99 查看
using UnityEngine;

using System.Collections;

using UnityEditor;

using System.IO;

public class Builder {

    [MenuItem("Builder/CopyToServer")]

    public static void CopyToServer()

    {

        string folder = Application.streamingAssetsPath;

        DirectoryInfo streamingAsset = new DirectoryInfo(folder);

        GetDirectory(streamingAsset);

    }

    public static string serverPath = @"D:\www\StreamingAssets";

    public static void GetDirectory(DirectoryInfo direc)

    {

        string localFolderName = direc.FullName;

        string localFolder = localFolderName.Substring(localFolderName.LastIndexOf("StreamingAssets"));

        localFolder = localFolder.Replace("StreamingAssets", "");

        localFolder = serverPath + "/" + localFolder;

        if (!Directory.Exists(localFolder))

            Directory.CreateDirectory(localFolder);

        FileInfo[] fileInfos = direc.GetFiles();

        for (int i = 0; i < fileInfos.Length; i++)

        {

            string fileFullName = localFolder + "/" + fileInfos[i].Name;

            FileInfo file = new FileInfo(localFolder+"/"+fileInfos[i].Name);

            if (file.Exists) file.Delete();

            fileInfos[i].CopyTo(fileFullName);

            Debug.Log(fileFullName);

        }

        DirectoryInfo[] folders = direc.GetDirectories();

        foreach(DirectoryInfo info in folders)

        {

            GetDirectory(info);

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Unity class