コード例 #1
0
            public override void OnInspectorGUI()
            {
                base.OnInspectorGUI();

                PrefabSpawner prefabSpawner = target as PrefabSpawner;

                if (GUILayout.Button($"Create {prefabSpawner.PrefabName}"))
                {
                    foreach (PrefabSpawner ps in targets)
                    {
                        Object spawned = Create(ps);
                        Selection.objects = new Object[] { spawned };
                    }
                }
            }
コード例 #2
0
            static Object Create(PrefabSpawner prefabSpawner)
            {
                if (!prefabSpawner.Prefab)
                {
                    Debug.Log($"[{prefabSpawner.name}] Error! Need a Prefab object.");
                    return(null);
                }

                Object spawned = prefabSpawner.Spawn();

                if (spawned)
                {
                    Undo.RegisterCreatedObjectUndo(spawned, $"Spawned {prefabSpawner.PrefabName}");
                }

                return(spawned);
            }
コード例 #3
0
            static Object[] CreateMany(PrefabSpawner prefabSpawner, int amount)
            {
                if (!prefabSpawner.Prefab)
                {
                    Debug.Log($"[{prefabSpawner.name}] Error! Need a Prefab object.");
                    return(null);
                }

                Undo.SetCurrentGroupName($"Spawned {amount} {prefabSpawner.PrefabName}s");

                Object[] spawned = new Object[amount];
                for (int i = 0; i < amount; i++)
                {
                    spawned[i] = Create(prefabSpawner);
                }

                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());

                return(spawned);
            }