|
|
|
|
|
|
All |
|
|
|
} |
|
|
|
|
|
|
|
public enum SpawnLocation |
|
|
|
{ |
|
|
|
Default, |
|
|
|
SameSceneAsTarget, |
|
|
|
ChildOfTarget, |
|
|
|
DontDestroyOnLoad |
|
|
|
} |
|
|
|
|
|
|
|
[ReorderableList, NonNullCheck] |
|
|
|
public GameObject[] FactoryBlueprints; |
|
|
|
[NonNullCheck] |
|
|
|
|
|
|
|
|
|
|
public bool RespawnTarget = true; |
|
|
|
public bool AttachToTarget = true; |
|
|
|
public SpawnLocation spawnLocation = SpawnLocation.SameSceneAsTarget; |
|
|
|
public bool ReapInstancesOnDestroy = true; |
|
|
|
|
|
|
|
[Min(1), SerializeField] |
|
|
|
private int MaxInstances = 1; |
|
|
|
|
|
|
|
|
|
|
List<GameObject> m_Instances; |
|
|
|
|
|
|
|
private void OnDestroy() |
|
|
|
{ |
|
|
|
if(ReapInstancesOnDestroy) |
|
|
|
{ |
|
|
|
foreach(var instance in m_Instances) |
|
|
|
{ |
|
|
|
if (instance != null) |
|
|
|
Destroy(instance); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void Spawn() |
|
|
|
{ |
|
|
|
if(SpawnTarget == null || FactoryBlueprints == null || FactoryBlueprints.Length == 0) |
|
|
|
|
|
|
if (m_Instances.Count <= MaxInstances) |
|
|
|
{ |
|
|
|
GameObject newInstance = Spawn(SelectBlueprint(), SpawnTarget); |
|
|
|
if (AttachToTarget) |
|
|
|
newInstance.transform.parent = SpawnTarget.transform; |
|
|
|
|
|
|
|
switch(spawnLocation) |
|
|
|
{ |
|
|
|
case SpawnLocation.Default: |
|
|
|
break; |
|
|
|
case SpawnLocation.SameSceneAsTarget: |
|
|
|
UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene( newInstance, SpawnTarget.scene); |
|
|
|
break; |
|
|
|
case SpawnLocation.ChildOfTarget: |
|
|
|
newInstance.transform.parent = SpawnTarget.transform; |
|
|
|
break; |
|
|
|
case SpawnLocation.DontDestroyOnLoad: |
|
|
|
DontDestroyOnLoad(newInstance); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
m_Instances.Add(newInstance); |
|
|
|
|
|
|
|