Unity 特殊文件夹

来源:互联网 发布:视频播放cms 编辑:程序博客网 时间:2024/05/16 11:30

Special Folder Names

For the most part, you can choose any names you like for the folders you create to organise your project. However, there are a number of folder names that Unity will interpret as an instruction that the folders’ contents should be treated in a special way. For example, editor scripts must be placed in a folder called Editor in order to work correctly. The full list of special folder names used by Unity is given below.

一般来说,你可以给你的工程里的文件夹其任何名字,但是有些文件夹的名字会被Unity理解为一种指令,文件夹里的内容会被特殊对待。例如,编辑器脚本放在叫Editor的文件夹里才能正确工作。下边列出这些特殊的文件夹。

Assets

The Assets folder is the main folder that contains the assets that can be used by a Unity project. The contents of the Project view correspond directly to the contents of the Assets folder. Most API functions assume that everything is located in the Assets folder and so they don’t require it to be mentioned explicitly. However, some functions do need to have the Assets folder included as part of a pathname (eg, certain functions in the AssetDatabase class).

Assets文件是Unity工程的根文件夹,包含其使用的资源。项目视图里的内容和Asset文件夹里的内容保持一致。大部分API函数假定所用的东西都是放在Asset文件夹里的,所以不需要明确的说明。但是有些函数却需要Asset文件夹作为路径的一部分(比如 AssetDatabase类里的特定函数)。

Editor

All scripts that are placed in a folder called Editor (or a sub-folder within it) will be treated as editor scripts rather than runtime scripts. Such scripts are designed to add functionality to Unity itself during development and are not available to the finished game at runtime. More than one Editor folder can be used in the project at once but note that the exact location of a given Editor folder affects the time at which its scripts will be compiled relative to other scripts. See the page onSpecial Folders and Script Compilation Order for a full description of this. Note: Unity will not allow components derived from MonoBehaviour to be assigned to GameObjects if the scripts are in the Editor folder.

所有放在叫做Editor文件夹里(或者里面的子文件夹)的脚本都会被认为是编辑器脚本而不是运行时脚本。这些脚本被设计出来增加开发过程Unity本身的功能而不是完成后运行的游戏。工程里可以有多个Editor文件夹,但是注意准确的文件夹位置会影响脚本相对于其他脚本的编译时机。具体请阅读Special Folders and Script Compilation Order。注意:如果脚本在Editor文件夹里,Unity是不允许继承自MonoBehaviour的组件分配给游戏物体的。

Editor Default Resources

Editor scripts can make use of asset files loaded on-demand using the EditorGUIUtility.Load function. This function will look for the asset files in a folder calledEditor Default Resources which should be placed directly within the Assets folder.

编辑器脚本可以通过 EditorGUIUtility.Load函数使用要求的资源文件。这个函数会去查找叫做Eitor Default Resources的文件夹,它应该直接放到Assets文件夹下。

Gizmos

Unity’s “Gizmos” allow you to add graphics to the scene view to help visualise design details that are otherwise invisible. The Gizmos.DrawIcon function places an icon in the scene to act as a marker for a special object or position. The image file used to draw this icon must be placed in a folder called Gizmos in order to be located by the DrawIcon function.

Unity的小工具可以允许你在场景视图里添加图像来帮助可视化设计细节。 Gizmos.DrawIcon函数可以在场景里放一个图标来当做特殊物体或位置的标记。这个图标文件必须放在叫做Gizmos的文件夹里以便函数定位。

Plugins

Unity lets you add Plugins to a project to extend the features available to Unity. Plugins are native DLLs that are typically written in C/C++. They can access third party code libraries, system calls and other things that are not provided by Unity out of the box. Plugins must be placed in a folder called Plugins to be detected by Unity and like the Editor folder, this affects the order in which scripts are compiled. See the page on Special Folders and Script Compilation Order for further details.

Unity可以让你为工程添加插件来增加unity的可用功能。插件通常是C/C++写的本地DLLs。它们可以获取unity没有提供的第三方的代码库、系统调用和其他的东西。就像Editor文件夹一样,插件必须放在叫做Plugins的文件夹以便被Unity发现,这会影响脚本的编译顺序。具体请看Special Folders and Script Compilation Order。

Resources

Generally, you create instances of assets in a scene to use them in gameplay but Unity also lets you load assets on demand from a script. You do this by placing the assets in a folder called Resources or a sub-folder (you can actually have any number of Resources folders and place them anywhere in the project). These assets can then be loaded using the Resources.Load function.

一般情况下,你会在场景里创建一个资源的实例,但是Unity也支持按需求从脚本里load资源。你可以通过把资源放到叫做Resources的文件夹或者子目录下(实际上你可以有任意数目的Resource文件夹,可以放在任何位置。)这些资源通过Resources.Load函数load。

Standard Assets

When you import a standard asset package (menu: Assets > Import Package) the assets are placed in a folder called Standard Assets. As well as containing the assets, these folders also have an effect on script compilation order; see the page on Special Folders and Script Compilation Order for further details.

当你加载一个标准资源包时,资源放在一个叫做Standard Assets的文件下。因为包含资源,所以这些文件夹也会影响脚本编译顺序,具体看Special Folders and Script Compilation Order

StreamingAssets

Most game assets are incorporated directly into the built player but there are some cases where you want the asset to be available as a separate file in its original format. For example, to play a video on iOS, you must access the video file from the filesystem rather than use it as a MovieTexture. If you place a file in a folder called StreamingAssets, it will be copied unchanged to the target machine where it will be available from a specific folder. See the page about Streaming Assetsfor further details.

大本分游戏资源会被直接纳入生成的播放器(不知道翻译是否正确),但是有些情况是有些资源是作为保持原有格式的单独文件使用的。例如你想在ios播放一个视频,你必须通过文件系统获得视频文件,而不是使用它当做视频纹理。如果你将文件放入叫做StreamingAsset的文件夹里,它将被原样复制到目标机器的特定文件夹里。你可以通过 Application.streamingAssetsPath的获得本地StreamingAssets文件夹,在不同的机器上的实际路径是

  • On a desktop computer (Mac OS or Windows) the location of the files can be obtained with the following code:

     path = Application.dataPath + "/StreamingAssets";
  • On iOS, you should use:

     path = Application.dataPath + "/Raw";
  • On Android, you should use:

     path = "jar:file://" + Application.dataPath + "!/assets/";
  • Note that on Android, the files are contained within a compressed .jar file (which is essentially the same format as standard zip-compressed files). This means that if you do not use Unity’s WWW class to retrieve the file then you will need to use additional software to see inside the .jar archive and obtain the file.
  • 注意在安卓系统,文件是被包含在.jar压缩文件(本质上是标准zip压缩文件)。这意味着如果你不使用Unity的WWW类来取回文件,那就必须用额外的软件来看.jar档案文件的内部来获取资源文件。

Special Folders and Script Compilation Order

The phases of compilation are as follows:

Phase 1: Runtime scripts in folders called Standard AssetsPro Standard Assets and Plugins.

Phase 2: Editor scripts in folders called Standard Assets/EditorPro Standard Assets/Editor and Plugins/Editor.

Phase 3: All other scripts that are not inside a folder called Editor.

Phase 4: All remaining scripts (ie, the ones that are inside a folder called Editor).

编译顺序的规律是 1、标准包和插件优先。2、非Editor文件夹优先。

0 0
原创粉丝点击