unetweaverunity error cs1061unity 什么情况

优化Unity项目编译速度 - 推酷
优化Unity项目编译速度
这个是最近一段时间带着子川一起做的一个小东西:如何优化大项目C#编译速度。这个idea主要是因为使用了slua之后,每次修改C#部分编译实在是太慢了… 下面将介绍两个不同的思路,心急的朋友可以直接看第二个解决方案及实战,因为这个说穿了其实就一句话,
写第一部分只不过是因为折腾了非常久的
MonoImporter/PluginImporter/MonoScript 结果发现没用上而不爽(逃
我使用的是之前比较lua解决方案里的slua工程,引擎版本Unity 5.3.6f1(其他设备信息跳过因为都是在同一台电脑上…)。在测试之前还需要写一个脚本来统计编译时间,这里简单粗暴的写了一个小脚本去不断刷新 EditorApplication.isCompiling 即可;顺便因为每次编译完成之后重新加载dll会导致 static bool compiling 丢失,因此保存一下。
[InitializeOnLoad]
public class FinishCompiling
const string compilingKey = &Compiling&;
static FinishCompiling()
compiling = EditorPrefs.GetBool(compilingKey, false);
EditorApplication.update += U
static void Update()
if(compiling && !EditorApplication.isCompiling)
Debug.Log(string.Format(&Compiling DONE {0}&, DateTime.Now));
compiling =
EditorPrefs.SetBool(compilingKey, false);
else if (!compiling && EditorApplication.isCompiling)
Debug.Log(string.Format(&Compiling START {0}&, DateTime.Now));
compiling =
EditorPrefs.SetBool(compilingKey, true);
测试的时候随便右键一个脚本-Reimport即可,这里我们要记下第一条数据: 原始版本slua 编译时间大概在20s左右 。
Solution 1: 打包DLL
为了优化编译速度,我的第一反应就是把部分代码打包成dll,就像DOTween这种插件直接提供了dll一样。动手之前上网搜了下,论坛上已经有人这么干了
,而且效果非常好
顺便吐槽下论坛这个帖子的作者一开始是用的UnityScript,改成C#之后就已经好很多了…
Overall, using all 3 methods above, my script compile times are now down from 15 seconds every time I update a script to just 2 seconds. That’s a 7.5X performance increase!
这部分官方文档里的
介绍了如何打包,但是文档里建立Visual Studio工程还是挺麻烦,所以分析了编辑器的Editor.log之后,我选择了自己生成命令行编译:
&C:/Program Files/Unity/Editor/Data/MonoBleedingEdge/lib/mono/4.5/mcs& @compile2dll.txt
其中compile2dll.txt的文件内容如下
/target:library
/out:&LuaObject-Player.dll&
/define:&UNITY_5_3_OR_NEWER;UNITY_5_3;UNITY_5;...&
/r:&C:/Program Files/Unity/Editor/Data/Managed/UnityEngine....&
&Assets/Slua/LuaObject/Custom/BindCustom.cs&
这里必须使用文件来传递参数而不是直接在控制台传递过去的原因是Windows有一个奇葩限制
编译的时候我是根据文件夹去分Player/Editor两个版本的dll,搭配不同的宏和DLL引用。这里比较麻烦的是DLL部分,一方面要引入引擎相关的,此外还要引入项目里的 Library/ScriptAssemblies/Assembly-CSharp.dll 及其他非native的Plugin。编译完成之后删掉原来的cs文件导入新的dll就行了。
在这里还需要稍微修改下Slua的注入部分
if (System.IO.File.Exists(&Assets/Slua/LuaObject/LuaObject-Player.dll&))
assembly = Assembly.Load(&LuaObject-Player&);
list.AddRange(getBindList(assembly, &SLua.BindUnity&));
list.AddRange(getBindList(assembly, &SLua.BindUnityUI&));
list.AddRange(getBindList(assembly, &SLua.BindDll&));
list.AddRange(getBindList(assembly, &SLua.BindCustom&));
搞定之后试了下原来场景能够正常运行,就可以记下第二条数据: dll版本的slua 编译时间大概在4s左右 。
是不是很激动人心?然后要来自己给自己泼冷水了…我使用这个工具去尝试打包
的时候发现,这种解决方案有两个非常大的硬伤:
无法处理代码里有 UNITY_ANDROID UNITY_EDITOR 等宏
无法处理 MonoBehaivor
前面一种其实硬要做也是可以的:针对每个平台及是否是编辑器编译一份dll进行使用。但是第二个问题非常难搞不定。根据我的分析,Unity在序列化prefab/scene的时候:
m_Script: {fileID: , guid: d69a744a6d, type: 3}
guid 是对应的DLL文件, fileID 是里面的C#脚本,如果要在用不同版本DLL的时候自己根据映射去切换太尴尬了。
后来还想了一个鸡贼的办法,和前面提到的论坛帖子里方法类似:把原来的类改名,譬如 SgLuaMonoBehavior 改成 SgLuaMonoBehavior_ 编译到dll里面去,然后在外面写一个空的类 public class SgLuaMonoBehavior : SgLuaMonoBehavior_ 来继承。测试了下发现编辑器部分的 [CustomEditor(typeof(SgLuaMonoBehavior_))] 不认子类,还有很多 CreateMenu 也要重写,工作量简直尴尬而且可维护性太差…
再后来还YY过一个工程编译出两个partial dll,以及extension写法等,发现没一个走的通。
ps. 我比较好奇UGUI这种dll是如何在升级版本的时候保证一致的,我猜测是一方面通过工程里Assembly-Info里的 GUID d4f464c7-9b15-460d-b4bc-2cacd1c1df73 配合引擎内部的guidmapper实现。这方面如果有了解的希望不吝赐教~
Solution 2: 利用Unity多阶段编译
上面那个解决方案限制太多实用性其实不高,然后某天偶然发现了这个插件
,根据其描述瞬间打开了新世界的大门:官方文档
表示引擎默认就会分四步编译,那么只要将不常修改的代码放到特定文件夹就完事儿了其实…这里我选择的是 Standard Assets 文件夹,因为我司有一套切换SDK的脚本会覆盖 Plugins 内容(见
)。同样也要修改下slua的载入部分:
//var assemblyName = &Assembly-CSharp&;
var assemblyName = &Assembly-CSharp-firstpass&;
Assembly assembly = Assembly.Load(assemblyName);
list.AddRange(getBindList(assembly,&SLua.BindUnity&));
list.AddRange(getBindList(assembly,&SLua.BindUnityUI&));
list.AddRange(getBindList(assembly,&SLua.BindDll&));
list.AddRange(getBindList(assembly,&SLua.BindCustom&));
然后把Slua拖到Standard Assets下,一运行就报错了…蜜汁尴尬
UNetWeaver error: Exception :System.ArgumentException: An element with the same key already exists in the dictionary. at System.Collections.Generic.Dictionary`2[System.UInt32,System.UInt32].Add (UInt32 key, UInt32 value) [0x0007e] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404 at Mono.Cecil.MetadataSystem.SetReverseNestedTypeMapping (UInt32 nested, UInt32 declaring) [0x00000] in
:0 at Mono.Cecil.MetadataReader.AddNestedMapping (UInt32 declaring, UInt32 nested) [0x00000] in
上搜到了相关信息,偷懒起见直接用了
。这下第三条数据到手: Plugin版本的slua 编译时间大概在5s左右 。
ps. 这里由于引入了CSharp 6.0 Support,多了脚本+换了个编译器,因此我重测了下原始版本slua+这个的编译时间大概15s左右
这只能说明老mono早该换了
pss. 这里只是测试偷懒换了编译器,但是我个人不建议在实际项目里这么干…
使用了手头在优化的一个项目:原版编译时间大概23s左右
新版本编译时间大概7s左右
没错…说穿了就是 把包括插件在内的基本不会修改的代码挪到Standard Assets里就完事儿了 ,经常修改的代码放在外面原地不动。这样唯一的一个限制是Standard Assets里的代码无法引用外面的代码,不过我这里全是放的插件,完全没有问题。
解决方案2完胜解决方案1(逃
ps. 后来发现雨松MONO之前在论坛也提过这个思路
pss. 其实解决方案1也不是完全一无是处,譬如对于slua这种奇怪的会撞编译器bug的代码,就可以考虑用命令行编译之后拷贝回来…
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致& UNITY 5.3.2
Unity新功能?
IMPROVEMENTS
Compute: Improved compute shader import times, particularly on Windows. Since 5.1 we were always compiling them for GL4.3+GLES3.1 too, while most people only need DX11. (706098)
Editor: Added link to learn more about Unity Cloud Build in the Build Player window.
Editor/Scenes: Add Scene.GetRootGameObjects() to return the root game objects of the scene.
Editor/Scenes: Add SceneManager.CreateScene() API to allow creating new empty scene at runtime.
GI: Light probes and ambient (everything with SH calculations) match ground truth more closely now. (754898)
IL2CPP: Optimize method prologues for code size and incremental builds.
iOS: Added bitcode support. (752178)
iOS/IL2CPP: Added support for Xcode 7.3 (don't use __declspec attributes).
Samsung TV: Added support for 2016 TVs.
Tizen: Now supports tizenstore URL protocol to open up Tizen store pages.
tvOS: Enable Dynamic GI.
VR: Applications that lost focus no longer throttle the CPU.
iOS: Enable bitcode support by default.
Editor/Scenes: Prevent calling some Editor mode only APIs on EditorSceneManager from play mode, including EditorSceneManager.OpenScene, EditorSceneManager.SaveScene etc.
Editor/Scenes: Prevent calling some play mode only APIs on SceneManager from Editor mode, including SceneManager.LoadLevel, SceneManager.LoadLevelAsync etc.
Android: Fixed crash when loading many asset bundles. (743739)
Android: Fixed crash in Cloth vertex buffer setup. (750362)
Android: Fixed NullReferenceException on x86 devices running Android 5.0 or newer.
Animation: Fixed an issue with stepped keys having the wrong value. (745139)
Animation: Fixed animation events not firing on the last frame of a looping animation. (745781)
Animation: Fixed crash when deleting all Euler keys in animation curve. (754373)
Animation: Fixed Crossfade called subsequently not properly interrupting transition. (753866)
API Updater: Fixed possible crashes in script updater when resolving types.
AssetBundles: Fixed AssetBundle.CreateFromFile retaining file descriptor. (715753)
AssetBundles: Fixed excessive memory usage when decompressing asset bundles with many objects inside.
AssetBundles: Fixed memory leak when loading asset bundles with LZMA compression.
AssetBundles: Fixed possible asset bundle caching error when starting multiple downloads with an empty cache.
AssetBundles: Fixed the asset bundle reading bug when compressed data could be read as uncompressed.
Core: '~' folders were no longer fixed. (687655)
DX11: Improved performance in GPU bound scenarios. (747492)
DX11: Fixed wrong VRAM detection on some Intel GPUs, resulting in shadows not being rendered.
DX11/XB1: Fixed FP16 static batched mesh vertex compression to actually work there, was always decompressing to FP32 before.
Editor: Display console platform doc items in the help menu, when console docs are present, but the main documentation is not installed. (754108)
Editor: Fixed MissingMethodException when using some APIs from UnityEngine.WSA namespace.
Editor: Make right and left arrow select next/previous parent for fast expand/collapse in hierarchy views. (752821)
Editor/Scenes: Fixed a crash when trying to get the root count on an invalid Scene. (752423)
Editor/Scenes: Fixed loading new unsaved scene during playmode using Application.LoadLevel(index) or SceneManager.LoadScene(index). (751923)
Editor/Scenes: Fixed the issue that script association was lost when another scene was loaded. (748904)
Editor/Scenes: Fixed the issue that the unloaded scenes would be removed from the hierarchy when entering playmode, if they were first in the hierarchy.
Editor/Scenes: Now make sure inspector in ActiveEditorTracker for MonoBehaviours are not garbage collected. The ActiveEditorTracked manages the objects itself. (753550)
Editor/Scenes: Throw null reference exception if SerializedObject has been disposed. (752599)
Global Illumination: E fixed an issue where Unity crashed if scene was unloaded before it got a chance to fully load. (7666)
Global Illumination: Fixed light probes / skybox ambient being wrong in some cases, 5.3 regression. (754898)
Graphics: More consistency between editor & player when setting up color space sRGB write modes. (754487)
Graphics: Fixed an issue where enabling vertex compression for positions could result in geometry not being rendered. (754928)
Graphics: Realtime reflection probes in some cases did not have trilinear filtering
fixed. (752879)
Graphics: Fixed crash when setting shader properties.
IL2CPP: Do not incorrectly free blittable arrays marshaled as [In,Out] parameters. (760943)
IL2CPP: Ensure that the header file for a type defined in a different assembly is included when that type is used for a method parameter. (755088)
IL2CPP: Ensure thread ID is valid for all threads. (691038)
IL2CPP: Fixed an issue that caused a crash in Class::IsSubclassOf. (752737), (751428)
IL2CPP: Fixed double.Parse with InvariantCulture. (752197)
IL2CPP: Fixed ExecutionEngineException being thrown on System.Reflection.MonoProperty::GetterAdapterFrame. (737529)
IL2CPP: Fixed StateMachineBehaviour messages not being executed if stripping is enabled. (753610)
IL2CPP: Forward declare a type and marshaled type in the method declarations header for marshaling methods so that the order of includes does not matter. (756447)
IL2CPP: Implemented out marshaling for arrays correctly. (752153)
IL2CPP: Implemented support for MetadataToken property on the following types: FieldInfo, EventInfo, MethodInfo, ConstructorInfo, PropertyInfo, Type, and Module. (670027)
IL2CPP: Implemented the Thread::Abort and Thread::ResetAbort methods. This should allow a Socket to be closed properly while another thread is waiting in a call to Accept or Connect on that socket. (746822)
IL2CPP: Prevent a NotImplementedException exception from occurring in il2cpp.exe when the Unbox opcode is used with certain generics. This usually occurs when an assembly is built with Visual Studio. (758926)
IL2CPP: Properly cleanup when a native thread is cancelled rather than exiting normally. (3609)
IL2CPP: Provide a proper argument for instance methods on value types invoked via a delegate. (750153)
IL2CPP: Removed an unnecessary Box used to null check before calling a virtual method.
iOS: Added font containing Lao characters to the fallback list. (750357)
iOS: Added Xcode 7.2 to iOS plugin compatibility list. (750311)
iOS: Duplicate another image layer when not all are defined. (749289)
iOS: Fixed Apple Pencil position reporting on iPad Pro.
iOS: Hindi characters are displayed now. (725558)
iOS/IL2CPP: Correct stack traces in exception messages, which could sometimes miss managed frames. (754539)
iOS/IL2CPP: Fire all GC profiler events. Fixed GC data in internal profiler.
iOS/tvOS: Build all object files with correct SDK. (755365)
Linux: Fixed a corner case where tearing would occur on some window managers even with VSync enabled.
Mecanim: Fixed a bug where Euler rotations would be retained in scene after scrubbing animation. (754562)
Mecanim: Fixed a bug where Euler rotations would not work in Legacy Animations. (752955)
Mecanim: Fixed a bug where lights would not be animated in Legacy mode. (753595)
Mecanim: Fixed a bug where RectTransform couldn't be animated in Legacy. (752847)
Metal: Wrongly claimed to support DXT1/DXT5 texture formats on iOS, and ETC on Mac.
Mono: Preserve non-volatile XMM registers across calls on 64-bit Windows during JIT compilation. (691466)
Networking: Added a 'connecting' state and cancel button to NetworkManagerHUD UI to prevent multiple attempts to connect at the same time. (748936)
Networking: Fixed 'recursion depth exceeded' error for complex NetworkBehaviour scripts. (757766)
Networking: Fixed ClientScene object list being wrong after host migration. (746011)
Networking: Fixed NetworkAnimator not working for non-player objects (755391)
Networking: Fixed NetworkServer.SendToAll sends the message to the host twice. (756153)
Networking: Fixed SyncEvent regression issue. (755450)
Networking: Fixed SyncList updates don't use a configurable network channel. (745795)
Networking: Fixed UI that allowed host migration to be enabled for WebGl platform where it is not supported. (744002)
Networking: OnStopAuthority called on server when it should not be. (751239)
Networking: Prevent [Command] functions from accepting NetworkConnection objects as parameters, which causes a UNetWeaver error. (729157)
Networking: Prevent NetworkIdentity objects from being server-only and local-player-authority at the same time, as this is not a valid configuration. (749338)
OpenGL Core: Fixed a crash with AMD and NVIDIA on Windows when using RenderTexture with recent drivers.
OpenGL Core: Fixed a crash with Intel GPUs on Linux.
OpenGL Core: Fixed shaders with multiple constant arrays.
OpenGL Core: Fixed text rendering with AMD GPUs on OSX 10.9.
OpenGL ES: Fixed crashes with new Samsung firmware. (6754)
OpenGL ES: Fixed mipmap generation for render textures. (751743)
OpenGL: Fixed binary shader cache, cache was always disabled. (742591)
OpenGL (legacy): Added work around buffer state tracking failure.
Particles: Fixed error message spam on particle systems that have no particles (5.3.1 regression). (755423)
Physics: Fixed memory corruption/crash when deactivating a collider from inside of OnTriggerStay. (744007)
Physics: PlatformEffector2D now supports negative scaling on parent Transform. (755612)
Profiler: Fixed excessive memory usage in development players.
Samsung TV: Fixed the smarthub button problem.
Samsung TV: Fixed wrong JPG library access problem.
Scripting: UnusedByteCodeStripper2 will show a better error message when processing assemblies, so it will be easier to identify offending assembly. (750266)
Shaders: During surface shader generation, do not initialise non-vector type members of the Input struct i.e. a struct/int/matrix as a member variable of the Input struct. (759336)
Shaders: Fixed a bug in Standard shader GGX specular term, introduced in 5.3.
Shaders: More proper environment reflection in Standard shader for very rough surfaces.
Substance: Fixed a crash when checking/unchecking 'Generate all outputs' or 'Generate mipmaps' on OSX. (752039)
Substance: Fixed a crash when reimporting SBSARs with multiple material instances on OSX. (751300)
Substance: Fixed a rare crash that could happen around the destruction of animated ProceduralMaterials. (750442)
Substance: Fixed console spam about unavailable material properties.
Substance: Fixed editor stutter when using RebuildTextures on OSX. (663236)
Substance: Fixed emission color being set to opaque white when resetting a ProceduralMaterial.
Substance: Fixed textures not properly generated on player awake when affected only by constant inputs. (754556)
Substance: Output textures from ProceduralMaterials without any input are now always generated.
tvOS: Fixed missing symbols for simulator builds. (756044)
tvOS: Fixed rendering path selector in player settings. (753925)
tvOS: Fixed UnityEngine.Apple.TV.Remote API access in editor.
UI: Added fix so that the placeholder text is enabled when the InputField is deactivated and the text is empty.
UI: Fixed crash in some cases after deleting world space Canvas. (740782)
UI: Removed remaining uses of multiple display system (temporary fix while non-native resolutions are not supported). (741751)
VR: Fixed Lines & T was offset for one eye. (754068)
VR: Fixed Render Scale not reverting after being edited in play mode. (731324)
VR: Fixed VRDevice.isPresent reporting true on first frame if Device was not connected at start. (732236)
VR: Stereo Cameras correctly respect camera depth when rendering to the game view and HMD. (753256)
WebGL: Fixed a crash when setting Application.runInBackground, if Strip Engine Code is enabled. (758120)
WebGL: Prevent browser from processing Arrow Keys. (740182)
WebGL: Prevent browser from processing Backspace and Tab key presses. (747236)
Windows Store: Fixed incorrect display of Korean characters on Windows 10 (if Korean language pack is not installed) and Windows Phone 10, Unity will now fallback to &Malgun Gothic& font.
Windows Store: Fixed Directory.CreateDirectory() for forward slashes. (752546)
Windows Store: Populate autorotation settings to screen manager. (751207)
Windows Store: Fixed a build failure (rrw failure) when calling methods with System.Numerics.Matrix4x4 as parameter. (754533)
Windows Store: Fixed AccessViolationException when initializing matchmaking in UNet. (747549)
Windows Store: Fixed player crashing on startup on .NET scripting backend. (746301)
Windows Store: Fixed Screen.SetResolution when upscaling lower resolution to fullscreen, previously you would see a corrupt image on the screen. (756086)
Windows Store: Fixed TouchScreenKeyboard crashes when it's members are used immediately after Open(). (755473)
Windows Store: Fixed WheelCollider on x64 (NullReferenceException occurring). (730289)
Windows Store: RunInBackground option will be respected when application window looses focus, and if enabled, the application will keep updating. Note: if application window is minimized it will be still paused, because OS suspends the application. (759166)
Revision: e87ab445ead0
5小时前337阅1天前249阅2天前324阅2天前205阅2天前279阅2天前109阅2天前231阅2天前304阅2天前461阅3天前130阅
CentOS专题
5683阅7271阅8230阅4042阅878阅2272阅9831阅2188阅2580阅1845阅
5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!
按 Ctrl+D 键,
把本文加入收藏夹
12345678910
12345678910
12345678910

我要回帖

更多关于 unity error cs0117 的文章

 

随机推荐