Unity禁止C#自动编译
基于unity2017\2020版本
using System;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class DisableAutoCompile
{
private const string _KEY = "DisableAutoCompile";
private static string s_RecoverValue = null;
static DisableAutoCompile()
{
UnityEditor.Compilation.CompilationPipeline.assemblyCompilationStarted += CompilationPipeline_assemblyCompilationStarted;
#if UNITY_2018_1_OR_NEWER
UnityEditor.Compilation.CompilationPipeline.compilationFinished += CompilationPipeline_compilationFinished;
#endif
}
private static void CompilationPipeline_assemblyCompilationStarted(string obj)
{
CheckAvoidCompile();
}
private static void CompilationPipeline_compilationFinished(object obj)
{
if (s_RecoverValue != null)
{
EditorPrefs.SetString(_KEY, s_RecoverValue);
s_RecoverValue = null;
}
}
private static void CheckAvoidCompile()
{
if (EditorPrefs.GetString(_KEY, "") == "true")
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
#if UNITY_2018_1_OR_NEWER
Assembly coreModule = assemblies.FirstOrDefault(x => x.FullName.StartsWith("UnityEditor.CoreModule,"));
#else
Assembly coreModule = assemblies.FirstOrDefault(x => x.FullName.StartsWith("UnityEditor,"));
#endif
Type t1 = coreModule.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface");
object editorCompilation = t1.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null, null);
Type t2 = coreModule.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilation");
MethodInfo StopAllCompilation = t2.GetMethod("StopAllCompilation", BindingFlags.Public | BindingFlags.Instance);
StopAllCompilation.Invoke(editorCompilation, null);
Debug.Log("forbid compile");
}
}
[MenuItem("C#编译/允许自动编译", true)]
public static bool CheckAllowCompile()
{
return EditorPrefs.GetString(_KEY, "") == "true";
}
[MenuItem("C#编译/允许自动编译")]
public static bool AllowCompile()
{
EditorPrefs.SetString(_KEY, "");
}
[MenuItem("C#编译/禁止自动编译", true)]
public static bool CheckForbidCompile()
{
return EditorPrefs.GetString(_KEY, "") != "true";
}
[MenuItem("C#编译/禁止自动编译", true)]
public static bool ForbidCompile()
{
EditorPrefs.SetString(_KEY, "true");
}
#if UNITY_2018_1_OR_NEWER
[MenuItem("C#编译/现在编译")]
public static bool CompileNow()
{
string oldValue = EditorPrefs.GetString(_KEY, "");
AllowCompile();
s_RecoverValue = oldValue;
UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation();
}
#else
[MenuItem("C#编译/现在编译(会允许自动编译)")]
public static bool CompileNow()
{
AllowCompile();
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Assembly coreModule = assemblies.FirstOrDefault(x => x.FullName.StartsWith("UnityEditor,"));
Type t1 = coreModule.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface");
object editorCompilation = t1.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null, null);
Type t2 = coreModule.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilation");
MethodInfo DirtyAllScripts = t2.GetMethod("DirtyAllScripts", BindingFlags.Public | BindingFlags.Instance);
DirtyAllScripts.Invoke(editorCompilation, null);
}
#endif
}
Unity禁止C#自动编译的更多相关文章
- 使用ant自动编译安卓项目并签名
准备阶段: 1.下载ant,jdk,android sdk ant下载地址:ant.apache.org/bindownload.cgi 2. 设置环境变量 ANT_HO ...
- Entity Framework 6 Recipes 2nd Edition(13-6)译 -> 自动编译的LINQ查询
问题 你想为多次用到的查询提高性能,而且你不想添加额外的编码或配置. 解决方案 假设你有如Figure 13-8 所示的模型 Figure 13-8. A model with an Associat ...
- [CI] 使用Jenkins自动编译部署web应用
写在前面 初步接触持续集成自动化过程,本篇主要介绍基于Jenkins实现持续集成的方式,通过案例介绍线上自动编译及部署的配置过程 持续集成 持续集成是一种软件开发实践,即团队开发成员经常集成它们的工作 ...
- 【Android】Eclipse自动编译NDK/JNI的三种方法
[Android]Eclipse自动编译NDK/JNI的三种方法 SkySeraph Sep. 18th 2014 Email:skyseraph00@163.com 更多精彩请直接访问SkySer ...
- gulp之压缩合并MD5清空替换加前缀以及自动编译自动刷新浏览器大全
gulp是基于流的前端构件化工具.目前比较火的前端构建化工具还是挺多的,grunt gulp fis3等等. 这个鬼东西有什么用?请参考https://www.zhihu.com/question/3 ...
- Eclipse不自动编译java文件的终极解决方案
最近我的eclipse经常犯傻,项目中总是有很多,启动项目也是没有启动类.查了下项目中生成的class文件,我靠竟然没有,或者还是以前的.原来是eclipse犯傻了,它没帮我自动编译java文件.一般 ...
- Eclipse下无法自动编译,或者WEB-INF/classes目录下没文件,编译失败的解决办法(转载)
文章来源:http://www.cnblogs.com/xfiver/archive/2010/07/07/1772764.html 1. IOException parsing XML docum ...
- TypeScript 自动编译
安装Typescript npm install -g typescript 手动编译 tsc greeter.ts 自动编译 tsc -w greeter.ts
- Eclipse不能自动编译 java文件
在网上的解决方法 方法参考如下: (1) Window-->Preferences-->General-->Workspace 有个"Build automatica ...
- WebStorm 9 自动编译 SCSS 产出 CSS 和 source maps
1. 上一节我们学习了Windows下搭建Ruby开发环境,也为这一节的学习做了铺垫.因为本节需要在Ruby环境下安装SASS.详细请见:http://www.cnblogs.com/wind128 ...
随机推荐
- 使用react-test-renderer/shallow写测试
我的项目是采用react + ts来写的,项目中要写单元测试,于是采用了Jest库, 主要用的package有 react-test-renderer react-test-renderer/sha ...
- c# 文件在线预览功能
using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using DocumentF ...
- netstat 某连接的 Recv-Q(接收队列)达到500多万字节的内核参数排查
思路: cat proc文件系统下的 sys/net 目录下所有文件,根据结果降序排序(如果打印前xx,可能会漏掉关键信息,在定位问题时需要注意,慎用过滤),根据结果使用 grep -rn xxx 找 ...
- git: 解决每次操作git时都要输入账户、密码
解决方案 $ git config --global credential.helper store 使用该命令即可解决问题
- 操作系统复习 MITS6.1810 lab util 记录
lab util sleep 介绍:主要用来熟悉下环境以及代码结构. See kernel/sysproc.c for the xv6 kernel code that implements the ...
- 基于C#的应用程序单例唯一运行的完美解决方案 - 开源研究系列文章
今次介绍一个应用程序单例唯一运行方案的代码. 我们知道,有些应用程序在操作系统中需要单例唯一运行,因为程序多开的话会对程序运行效果有影响,最基本的例子就是打印机,只能运行一个实例.这里将笔者单例运行的 ...
- DC-SDK 开发文档
https://resource.dvgis.cn/dc-docs/v2.x/zh/introduction/#%E5%BA%94%E7%94%A8%E9%85%8D%E7%BD%AE
- 基于 ASP.NET 的投票系统
OnlineVoting 基于 ASP.NET 的投票系统 功能页面 登录 注册 首页 投票广场 查看别人发布的投票. 个人中心 个人资料 换头像.修改密码和其他信息. 发布投票 项目地址:https ...
- Flutter 学习笔记(01)__从 0 开始创建一个 flutter 项目
最近发现有不少的公司已经跳出 uniapp 的坑坑,开始使用 flutter 开发app了,为了让自己不失业,赶紧卷起来!此篇文章教你从 0 基础开发一个 简单页面,文章篇幅较长,建议收藏!也可以直接 ...
- AI绘画| 迪士尼风格|可爱头像【附Midjourney提示词】
Midjourney案例分享 图片预览 迪士尼风格|可爱头像 高清原图及关键词Prompt已经放在文末网盘,需要的自取 在数字艺术的新时代,人工智能绘画已经迅速崭露头角.作为最先进的技术之一,AI绘画 ...