The document contains code for several classes related to building a Unity game hierarchy and importing assets. Key points:
- The Hierarchy class contains code for displaying foldout headers to organize game objects in a hierarchy.
- The BuildRoot method builds a tree structure containing animal category names and species for display in a hierarchy.
- The CubeImporter script imports cube assets from JSON files, setting the cube position from the file data.
- Editors are created for the CubeImporter and Object classes to customize their properties in the inspector.
- The E03_StyleSheet class applies a style sheet to container elements for visual formatting.
20.
class MyCustomBuildProcessor : IPreprocessBuild
{
public void OnPreprocessBuild(BuildTarget target, string path)
{
Debug.Log(“ ”);
}
}
21.
22. [ScriptedImporter(1, "cube")]
public class CubeImporter : ScriptedImporter
{
public float m_Scale = 1;
public override void OnImportAsset(AssetImportContext ctx)
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
var text = File.ReadAllText(ctx.assetPath);
var position = JsonUtility.FromJson<Vector3>(text);
cube.transform.position = position;
}
}
24.
[CustomEditor(typeof(Object))]
public class ObjectEditor : Editor
{
public ObjectEditor ()
{
if (extension == ".zip") {
editor = Editor.CreateEditor (Selection.activeObject,
typeof(ZipEditor));
} else if (string.IsNullOrEmpty (extension)) {
editor = Editor.CreateEditor (Selection.activeObject,
typeof(FolderEditor));
} else {
editor = null;
}
}
25.
26. public class E03_StyleSheet : EditorWindow
{
public void OnEnable()
{
var root = this.GetRootVisualContainer();
root.AddStyleSheetPath("styles");
// Here we just take all layout properties and other to extract them in USS!
var boxes = new VisualContainer() { name = "boxesContainer" };
boxes.AddToClassList("horizontalContainer");
root.Add(boxes);
}