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 ...
随机推荐
- Unity中的RegisterPlugins:深入解析与实用案例
Unity中的RegisterPlugins:深入解析与实用案例 在Unity游戏开发中,我们经常需要使用第三方插件来实现一些特定的功能.为了让这些插件能够在Unity中正常工作,我们需要对它们进行注 ...
- 园子的商业化努力:欢迎参加DataFun联合行行AI举办的数据智能创新与实践人工智能大会
大家好,今年是园子商业化生死攸关的一年,正在艰难而努力地向前推进,今天在首页发布一篇大会推广博文,望谅解. DataFun联合行行AI举办第四届"数据智能创新与实践人工智能大会", ...
- 【2020GET】即构科技蒋宁波:教育行业客户需求的核心是什么?
11月24日,由即构科技主办的2020GET大会教育科技分论坛在北京成功召开,来自叮咚课堂.小冰.360OS.蕃茄田艺术.即构科技的6位资深教育/科技大咖,在论坛上进行深度分享. 以下为即构科技联合创 ...
- 解决phpMyAdmin点击"结构"列页面失去响应的问题
最后更新时间 2017-12-05. 我的环境: phpMyAdmin:4.0.4.1 PHP:5.6.11 第一步 关闭自动更新 打开 ./libraries 目录下的 vendor_config. ...
- 【持续更新】C++ 并不完全是 C 的超集!
一些容易被忽略的 C 与 C++ 的不兼容特性 头文件和命名空间 C 标准库头文件名在 C++ 中通常去除扩展名,并加上 c 前缀,如: stdio.h -> cstdio stdlib.h - ...
- Linux 使用grep过滤字符串中的指定内容
命令示例:echo port 1234 123 | grep -oP 'port\s+\K\d+' 返回: 1234 这条命令使用 grep 工具来在文本中查找 "Port " 后 ...
- 在langchain中使用带简短知识内容的prompt template
简介 langchain中有个比较有意思的prompt template叫做FewShotPromptTemplate. 他是这句话的简写:"Prompt template that con ...
- EntityCleanFramework
EF几乎是按照领域的概念诞生,它可以和Clean结合(ECF是我新想出的名字).ECF 是为了统一业务架构开发方式,也可以说成在 微服务架构 中服务的通用开发方式.当有了统一开发方式后,协作将更上一层 ...
- 痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU启动那些事(10.A)- FlexSPI NAND启动时间(RT1170)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是恩智浦i.MX RT1170 FlexSPI NAND启动时间. 本篇是 i.MXRT1170 启动时间评测第四弹,前三篇分别给大家评测 ...
- Cilium系列-13-启用XDP加速及Cilium性能调优总结
系列文章 Cilium 系列文章 前言 将 Kubernetes 的 CNI 从其他组件切换为 Cilium, 已经可以有效地提升网络的性能. 但是通过对 Cilium 不同模式的切换/功能的启用, ...