基于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#自动编译的更多相关文章

  1. 使用ant自动编译安卓项目并签名

     准备阶段: 1.下载ant,jdk,android sdk        ant下载地址:ant.apache.org/bindownload.cgi 2. 设置环境变量      ANT_HO ...

  2. Entity Framework 6 Recipes 2nd Edition(13-6)译 -> 自动编译的LINQ查询

    问题 你想为多次用到的查询提高性能,而且你不想添加额外的编码或配置. 解决方案 假设你有如Figure 13-8 所示的模型 Figure 13-8. A model with an Associat ...

  3. [CI] 使用Jenkins自动编译部署web应用

    写在前面 初步接触持续集成自动化过程,本篇主要介绍基于Jenkins实现持续集成的方式,通过案例介绍线上自动编译及部署的配置过程 持续集成 持续集成是一种软件开发实践,即团队开发成员经常集成它们的工作 ...

  4. 【Android】Eclipse自动编译NDK/JNI的三种方法

    [Android]Eclipse自动编译NDK/JNI的三种方法 SkySeraph Sep. 18th  2014 Email:skyseraph00@163.com 更多精彩请直接访问SkySer ...

  5. gulp之压缩合并MD5清空替换加前缀以及自动编译自动刷新浏览器大全

    gulp是基于流的前端构件化工具.目前比较火的前端构建化工具还是挺多的,grunt gulp fis3等等. 这个鬼东西有什么用?请参考https://www.zhihu.com/question/3 ...

  6. Eclipse不自动编译java文件的终极解决方案

    最近我的eclipse经常犯傻,项目中总是有很多,启动项目也是没有启动类.查了下项目中生成的class文件,我靠竟然没有,或者还是以前的.原来是eclipse犯傻了,它没帮我自动编译java文件.一般 ...

  7. Eclipse下无法自动编译,或者WEB-INF/classes目录下没文件,编译失败的解决办法(转载)

    文章来源:http://www.cnblogs.com/xfiver/archive/2010/07/07/1772764.html 1.  IOException parsing XML docum ...

  8. TypeScript 自动编译

    安装Typescript npm install -g typescript 手动编译 tsc greeter.ts 自动编译 tsc -w greeter.ts

  9. Eclipse不能自动编译 java文件

      在网上的解决方法 方法参考如下: (1) Window-->Preferences-->General-->Workspace  有个"Build automatica ...

  10. WebStorm 9 自动编译 SCSS 产出 CSS 和 source maps

    1.  上一节我们学习了Windows下搭建Ruby开发环境,也为这一节的学习做了铺垫.因为本节需要在Ruby环境下安装SASS.详细请见:http://www.cnblogs.com/wind128 ...

随机推荐

  1. NoSuchMethodError: Closure call with mismatched arguments:

    原因:某个方法的参数中,回调函数写的有问题,

  2. jar包、war包项目部署

    部署 部署 jar包 部署 war包 部署 jar包 环境准备 JDK Tomcat Linux 环境 1.将jar文件上传至服务器 2.编写脚本 启动脚本放在跟jar 一起的路径下,如果不放在同一路 ...

  3. 基于ClickHouse解决活动海量数据问题

    1.背景 魔笛活动平台要记录每个活动的用户行为数据,帮助客服.运营.产品.研发等快速处理客诉.解决线上问题并进行相关数据分析和报警.可以预见到需要存储和分析海量数据,预估至少几十亿甚至上百亿的数据量, ...

  4. nginx配置文件内容(1)

    nginx.conf内容 在Nginx服务器的主配置文件nginx.conf中,包括全局配置.I/O事件配置.HTTP配置这三大块内容,配置语句的格式为"关键字  值:"(末尾以分 ...

  5. Nginx配置网站默认https

    Nginx配置网站默认https 一.安装Nginx yum install nginx -y 二.修改nginx.conf vim /etc/nginx/nginx.conf 配置80转443 配置 ...

  6. Blazor中如何呈现富文本/HTML

    将需要显示字符串转换成MarkupString类型 @((MarkupString)htmlString) 参考文献 https://stackoverflow.com/questions/60167 ...

  7. JFrame一些基础小知识

    JFrame.setLocationRelativeTo方法 JFrame.setLocationRelativeTo()是一个Java Swing中的方法,它用于将窗口居中显示在屏幕上. 当你调用该 ...

  8. 查看UUID

    查看硬盘UUID: 1. ls -l /dev/disk/by-uuid 2. blkid /dev/sda5 修改硬盘UUID: 1.新建和改变分区的UUID sudo uuidgen | xarg ...

  9. PoW是什么?

    PoW是什么? 工作量证明(proof of work,PoW)是一种用于确认和验证区块链交易和新区块有效性的共识算法.区块链中常见的工作量证明算法包括比特币的SHA-256.以太坊的Ethash.莱 ...

  10. docker 安装 Redis环境

    一.Docker搜索redis镜像 命令:docker search <镜像名称> docker search redis 二.Docker拉取镜像 命令::docker pull < ...