name | 游戏对象的名称。 |
types | 创建时要添加到游戏对象的可选类型。 |
scene | Scene where the GameObject should be created. |
hideFlags | HideFlags to assign to the GameObject. |
GameObject Returns the GameObject that was created.
创建一个新的游戏对象。
using UnityEngine; using UnityEditor;
public class CreateComponentExample { [MenuItem("ObjectFactoryExample/Create Camera GameObject")] public void CreateCameraEditor() { Selection.activeGameObject = ObjectFactory.CreateGameObject("Camera", typeof(Camera)); } }