码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Unity3D 打包发布时生成文件到打包目录


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

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

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

    3.脚本内容

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using UnityEditor;
    5. using UnityEditor.Callbacks;
    6. using UnityEngine;
    7. public class PostBuilds : MonoBehaviour
    8. {
    9. [PostProcessBuild]
    10. public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    11. {
    12. switch (buildTarget)
    13. {
    14. case BuildTarget.StandaloneWindows:
    15. BuildWindowsPlayer(path);
    16. break;
    17. case BuildTarget.StandaloneWindows64:
    18. BuildWindowsPlayer(path);
    19. break;
    20. case BuildTarget.StandaloneLinux:
    21. break;
    22. case BuildTarget.StandaloneLinux64:
    23. BuildLinuxPlayer64(path);
    24. break;
    25. case BuildTarget.StandaloneLinuxUniversal:
    26. break;
    27. case BuildTarget.iOS:
    28. break;
    29. }
    30. }
    31. static void BuildWindowsPlayer(string path)
    32. {
    33. string configSetting = Application.dataPath + "/Plugins/StartConfigurationTools/Win/configSetting.bat";
    34. string buildPath = Path.GetDirectoryName(path);
    35. CopyShellScript(configSetting, buildPath);
    36. }
    37. static void BuildLinuxPlayer64(string path)
    38. {
    39. string configSetting = Application.dataPath + "/Plugins/StartConfigurationTools/Linux64/configSetting.sh";
    40. string buildPath = Path.GetDirectoryName(path);
    41. CopyShellScript(configSetting, buildPath);
    42. }
    43. private static void CopyShellScript(string scriptPath, string targetPath)
    44. {
    45. string scriptName = Path.GetFileName(scriptPath);
    46. if (File.Exists(Path.Combine(targetPath, scriptName)))
    47. File.Delete(Path.Combine(targetPath, scriptName));
    48. File.Copy(scriptPath, Path.Combine(targetPath, scriptName), false);
    49. }
    50. }

    4、打包完成即可看到

  • 相关阅读:
    mysql多列索引(组合索引)特点和使用场景
    从一道经典的前端面试题---谈前端性能优化
    【RuoYi-Vue-Plus】学习笔记 34 - Redisson(九)RedissonMapCache 缓存流程分析(下)(Lua 脚本)
    软件测试进阶篇----自动化测试概述
    Linux文件的atime, mtime, ctime属性以及修改
    20:访问者模式
    【漏洞分析】KaoyaSwap 安全事件分析
    vue页面嵌入飞书网页组件,用于在类似ERP,OA等系统中展示在线文档
    基于PHP的预约看房管理系统
    [职场] 会计学专业学什么 #其他#知识分享#职场发展
  • 原文地址:https://blog.csdn.net/WenHuiJun_/article/details/134030552
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号