{ "title": "Unity 游戏开发基础", "description": "本文档旨在介绍 Unity 游戏开发的基础知识,包括游戏物体、组件、属性、变量以及消息发送等。", "sections": [ { "title": "游戏物体(GameObject)", "content": [ { "type": "list", "items": [ { "text": "创建游戏物体:通过 `GameObject.CreatePrimitive(PrimitiveType.*)` 创建原始几何体;通过 `Instantiate(prefab)` 实例化预制件。" }, { "text": "添加组件:使用 `GameObject.AddComponent<ComponentName>()` 方法,可以添加自定义脚本或 Unity 内置的组件。" }, { "text": "属性和变量:包括 `activeInHierarchy`、`activeSelf`、`tag` 等,控制游戏物体的激活状态和标签。" } ] } ] }, { "title": "组件(Component)", "content": [ { "type": "paragraph", "text": "组件是附加到游戏物体上的脚本或 Unity 内置的模块,用于实现特定功能。常见的组件包括 `Transform`、`MeshFilter`、`Collider` 等。" } ] }, { "title": "属性和变量", "content": [ { "type": "list", "items": [ { "text": "`GameObject.activeInHierarchy`:游戏物体是否处于激活状态,与父类有关。" }, { "text": "`GameObject.activeSelf`:自身激活状态,与父类无关。" }, { "text": "`GameObject.tag`:游戏物体的标签,由程序员自定义设置。" }, { "text": "`GameObject.SetActive(false/true)`:通过参数控制游戏物体的激活状态。" } ] } ] }, { "title": "UnityObject 中的共有方法与变量", "content": [ { "type": "list", "items": [ { "text": "`name`:游戏物体的名字,可以通过 GameObject 或 Component 获取。" }, { "text": "`GameObject.Find(name)`:通过名字查找全场一个不是特定的物体,但不找隐藏的对象。" }, { "text": "`transform.Find(name)`:在当前物体的子物体下检索,不递归。" }, { "text": "`Destroy(gameObject)`:删除游戏物体,进行回收等待确定没对象使用时再删除。" }, { "text": "`DontDestroyOnLoad(gameObject)`:加载新场景时不删除该物体。" }, { "text": "`FindObjectOfType<ComponentType>()`:通过类型查找单个组件。" }, { "text": "`FindObjectsOfType<ComponentType>()`:全局查找所有指定类型的组件。" }, { "text": "`FindGameObjectWithTag(tag)`:根据标签查找第一个游戏物体。" }, { "text": "`FindGameObjectsWithTag(tag)`:返回查找到的所有游戏物体。" } ] } ] }, { "title": "消息的发送", "content": [ { "type": "list", "items": [ { "text": "`BroadcastMessage(methodName, parameter)`:向所有子对象广播发送方法调用。" }, { "text": "`SendMessage(methodName, parameter)`:向当前游戏物体发送方法调用,不递归。" } ] } ] } ] }