unity 发布程序成功后执行方法
using System.IO; using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; public class PostBuildActions { [PostProcessBuild] public static void OnPostProcessBuild(BuildTarget target, string targetPath) { if(target== BuildTarget.StandaloneWindows64 || target == BuildTarget.StandaloneWindows) { int i = targetPath.LastIndexOf("/"); Debug.Log(targetPath.Substring(0,i)); } return; if (target != BuildTarget.WebGL) return; var path = Path.Combine(targetPath, "Build/UnityLoader.js"); var text = File.ReadAllText(path); text = text.Replace("UnityLoader.SystemInfo.mobile", "false"); text = text.Replace("[\"Edge\", \"Firefox\", \"Chrome\", \"Safari\"].indexOf(UnityLoader.SystemInfo.browser) == -1", "false"); File.WriteAllText(path, text); } //[PostProcessBuild] //public static void OnPostProcessBuild(BuildTarget target, string targetPath) //{ // if (target != BuildTarget.WebGL) // return; // var path = Path.Combine(targetPath, "Build/UnityLoader.js"); // var text = File.ReadAllText(path); // text = Regex.Replace(text, @"compatibilityCheck:function\(e,t,r\)\{.+,Blobs:\{\},loadCode", // "compatibilityCheck:function(e,t,r){t()},Blobs:{},loadCode"); // File.WriteAllText(path, text); //} }
脚本需要放在Editor 文件夹下