Translator: Unity - UA-ScriptEase/scriptease GitHub Wiki
#ScriptEase to Unity Conceptual Dictionary
ScriptEase | Unity |
---|---|
GameModule | Project |
Area | Scene |
Game Object | Game Object |
Script | Component (Script subtype) |
#File Format Unity has two different styles of scene file formats. Its default setting is to use a binary proprietary format and the other (currently pro-version-only) is in YAML. The latter format is called the "Textual scene file format". A description of it can be read here: http://unity3d.com/support/documentation/Manual/FormatDescription.html.
Since the file format is YAML, we use SnakeYAML for input: http://code.google.com/p/snakeyaml/. YAML is a language for data description (sort of like XML), and is fully described at http://www.yaml.org/spec/1.2/spec.html. There's a handy YAML reference card here: http://www.yaml.org/refcard.html.
##Type IDS http://docs.unity3d.com/Manual/ClassIDReference.html
##Configure Unity to save in YAML format
- Go to Edit -> Project Settings -> Editor
- In the Inspector window, find the Version Control dropdown. Select Metafiles as its value. This will enable "External Version Control support".
- The .unity files should now be in YAML format.
- If your assets were saved in the old format, you may need to set Asset Serialization mode to Force Text in the same editor window as the previous setting. (I had to do this. -aschenk)
An example of unity YAML file format can be found here: http://unity3d.com/support/documentation/Manual/YAMLSceneExample.html.
##Scripting Unity accepts three scripting languages: Javascript, C# and something called Boo. There is a scripting reference at http://unity3d.com/support/documentation/ScriptReference/index.html. So far, we have done everything in Javascript, and we will continue to do so until another one becomes necessary. Hopefully not, though.
###Script Format We have our "Assets" folder, which contains a few files:
- .unity files are scenes that are saved in YAML as long as we have set up our project correctly.
- Game Objects are saved in these Unity Files
- Each Game Object has some attached files. This is explained below.
- .js files are script files. These are what we should generate in ScriptEase II.
- We will need to compile these script files.
- Each script file has an associated .js.meta file that has a "guid" in it.
The guid in the script meta files is what is attached to Game Objects to attach scripts. But it's kind of complicated, which is why I made this Wiki page.
Let's say we already have a script and a scene file with some objects.
One of these game objects is "Cube". We have a few YAML documents inside the scene file that start with "--- !u!1 &123456" as an example.
0-5 are file properties. These aren't really used by us (yet).
Instead, we use the ones that have many numbers, like 432623.
The rest of the scene file is actually just a list of these game objects. Each Game Object has a map inside called "m_component". m_Component is a listing of all of the other documents used by the Game Object. They are in the format: - (Type): {fileID: (documentNumber} e.g. - 4: {fileID: 4625332}
Luckily, the other objects all have a field "m_GameObject: {fileID: #####}", where ##### refers to the ID number of the game object they belong to. So we don't have to go over it twice.
If we have a script attached to the object, it is inside a "MonoBehaviour" document. It looks like this:
--- !u!114 &46252944
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 46252939}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2a76dec97013b7940a166640d74e6e8b, type: 1}
m_Name:
In the "m_script" field you can see that we have the guid from the script's attached "js.meta" file. There is also a fileID and type. These are usually 11500000 and 1 respectively for scripts we attach. This may be wrong, though.
###Compilation Everything is compiled to .NET DLLs that get JIT compiled to assembler when run. Compilation in Unity happens in three stages, and those stages affects the compile time and accessilibily of some things. Likely it won't be a problem for us, as I suspect we can dump everything in Group 3 and be done with it. The compilation process reference is here: http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html.
#Tags in YAML Scene Files The Unity scene files make use of Tags.
Tags are in format:
!u!typeId &XX
XX is the file ID. This is a unique ID (UID) that references that component throughout the file.
If a tag is giving you a "Invalid tag" exception, this might actually be just because it doesn't know how to resolve that tag, not that it's incorrectly formatted. This, for example, showed up when I was writing the I/O stuff for the first time and it didn't have anything registered yet.
#Resources Any resources that may be used in Scripts should be in a "Resources" folder. This is required by Unity to let us use the Resources.load command to load resources dynamically.