Game Development Reference
In-Depth Information
212 //Assign mesh to mesh filter
213 meshFilter.sharedMesh = mesh;
214 mesh.RecalculateBounds();
215
216 //Add a box collider component
217 plane.AddComponent(typeof(BoxCollider));
218 }
219
220 //------------------------------------------------
221 }
The following are the comments for code sample 9-2:
Line 004 : This sample is coded as an editor plugin. As a result, the
UnityEditor namespace is included. For more information on creating
editor plugins, refer to Chapter 8 , Customizing the Unity Editor .
Line 135 : The OnSelectionChanged event is called when the user changes
their selection, with the mouse or keyboard, in the Unity Editor. Here, the
GetAssetPath method is called to retrieve the currently open folder in the
Project panel.
Line 140 : The OnWizardCreate function is called to generate a Quad mesh in
script. This is created by filling a vertex and UV array and then populating
that inside a Mesh object created in line 196.
Line 204 : Critically, the mesh itself is saved, not as an object in a specific scene,
but as a general asset of the project from which many instances can be made
as prefab objects. This is achieved with the AssetDatabase class. This is
important to allow the mesh to be reusable across multiple scenes, if required,
and also to allow its changes and details to be persistent across scenes.
More information on the AssetDatabase class can be found online
in the Unity documentation at http://docs.unity3d.com/
ScriptReference/AssetDatabase.html .
 
Search WWH ::




Custom Search