UnityEditorUnity编辑器开发分享Unity技术分享

UnityEditor Unity的模块

2017-10-20  本文已影响76人  梁先生呀

有时写了点编辑器工具,希望在每个项目中都用到,但是又不希望每次都把脚本拷贝一下。这时,就可以用到这个功能,让脚本成为Unity的“一部分”,任何项目可用。

比如平时用VsCode作为Unity的编辑器时,经常需要用到VsCode这个插件,下面以Vscode为例,让Unity打开所有项目时,都自带VsCode插件。

Step1.

在Unity的安装目录 Unity5.4.3\Editor\Data\UnityExtensions\Unity (我的版本是5.4.3)下,有一些Unity自带的模块,比如 Networking、GUISystem等,所有的模块根目录都有一个ivy.xml文件。如:

<?xml version="1.0" encoding="utf-8"?>
<ivy-module version="2.0">
  <info version="5.4.3" organisation="Unity" module="UNetHLAPI" e:packageType="UnityExtension" e:unityVersion="5.4.3f1" xmlns:e="http://ant.apache.org/ivy/extra" />
  <publications xmlns:e="http://ant.apache.org/ivy/extra">
    <artifact name="UnityEngine.Networking" type="dll" ext="dll" e:guid="870353891bb340e2b2a9c8707e7419ba" />
    <artifact name="Editor/UnityEditor.Networking" type="dll" ext="dll" e:guid="5f32cd94baa94578a686d4b9d6b660f7" />
  </publications>
</ivy-module>

其中:version、unityVersion均为当前Unity的版本号;artifact name 标签为我们的DLL文件的相对路径。这两项是需要我们修改的(在Step3)。

Step2. 生成dll

打开Visual Studio 新建一个Dll类库。

文件 - 新建 - 项目 - Visual C# - 类库(.NET Framework)

dll
TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly '...

由于我们需要用到Unity的一些Api,所以还需要为Vs项目引用两个Dll,UnityEngine.dll和UnityEditor.dll。

vscode

参考:http://homans.nhlrebel.com/2014/12/09/unity-4-6-and-modules/

Unity VsCode插件:https://github.com/dotBunny/VSCode

本文示例工程:https://github.com/liangddyy/UnityDemos/tree/master/VSCodeModule

上一篇下一篇

猜你喜欢

热点阅读