Unity3D 打包发布时生成文件到打包目录

编程入门 行业动态 更新时间:2024-10-15 14:17:52

Unity3D 打包发布时生成<a href=https://www.elefans.com/category/jswz/34/1771438.html style=文件到打包目录"/>

Unity3D 打包发布时生成文件到打包目录

有时候需要自己创建批处理文件或日志文件,在启动程序的同级目录使用,减少手动操作的时间和错误率。主要使用到的是OnPostprocessBuild方法。

1、在工程中的Editor文件夹下创建脚本

2、将文件放入Plugins的相关目录

3.脚本内容

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;public class PostBuilds : MonoBehaviour
{[PostProcessBuild]public static void OnPostprocessBuild(BuildTarget buildTarget, string path){switch (buildTarget){case BuildTarget.StandaloneWindows:BuildWindowsPlayer(path);break;case BuildTarget.StandaloneWindows64:BuildWindowsPlayer(path);break;case BuildTarget.StandaloneLinux:break;case BuildTarget.StandaloneLinux64:BuildLinuxPlayer64(path);break;case BuildTarget.StandaloneLinuxUniversal:break;case BuildTarget.iOS:break;}}static void BuildWindowsPlayer(string path){string configSetting = Application.dataPath + "/Plugins/StartConfigurationTools/Win/configSetting.bat";string buildPath = Path.GetDirectoryName(path);CopyShellScript(configSetting, buildPath);}static void BuildLinuxPlayer64(string path){string configSetting = Application.dataPath + "/Plugins/StartConfigurationTools/Linux64/configSetting.sh";string buildPath = Path.GetDirectoryName(path);CopyShellScript(configSetting, buildPath);}private static void CopyShellScript(string scriptPath, string targetPath){string scriptName = Path.GetFileName(scriptPath);if (File.Exists(Path.Combine(targetPath, scriptName)))File.Delete(Path.Combine(targetPath, scriptName));File.Copy(scriptPath, Path.Combine(targetPath, scriptName), false);}
}

4、打包完成即可看到

更多推荐

Unity3D 打包发布时生成文件到打包目录

本文发布于:2023-12-03 16:44:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1656714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   目录   Unity3D

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!