diff options
| author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 | 
|---|---|---|
| committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 | 
| commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
| tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/SpawnObjects.cs | |
+ init
Diffstat (limited to 'GameCode/SpawnObjects.cs')
| -rw-r--r-- | GameCode/SpawnObjects.cs | 83 | 
1 files changed, 83 insertions, 0 deletions
| diff --git a/GameCode/SpawnObjects.cs b/GameCode/SpawnObjects.cs new file mode 100644 index 0000000..8f00c7a --- /dev/null +++ b/GameCode/SpawnObjects.cs @@ -0,0 +1,83 @@ +using System; +using Photon.Pun; +using UnityEngine; + +public class SpawnObjects : MonoBehaviour +{ +	public enum SpawnRot +	{ +		Identity, +		TransformRotation +	} + +	public GameObject[] objectToSpawn; + +	public SpawnRot spawnRot; + +	public bool inheritScale; + +	public bool destroyObject; + +	public bool destroyRoot; + +	private PhotonView view; + +	public Action<GameObject> SpawnedAction; + +	[HideInInspector] +	public GameObject mostRecentlySpawnedObject; + +	private void ConfigureObject(GameObject go) +	{ +		SpawnedAttack spawnedAttack = go.GetComponent<SpawnedAttack>(); +		if (!spawnedAttack) +		{ +			spawnedAttack = go.AddComponent<SpawnedAttack>(); +		} +		spawnedAttack.spawner = base.transform.root.GetComponent<Player>(); +		if (!spawnedAttack.spawner) +		{ +			SpawnedAttack componentInParent = base.transform.GetComponentInParent<SpawnedAttack>(); +			if ((bool)componentInParent) +			{ +				componentInParent.CopySpawnedAttackTo(go); +			} +		} +		AttackLevel componentInParent2 = GetComponentInParent<AttackLevel>(); +		if ((bool)componentInParent2) +		{ +			spawnedAttack.attackLevel = componentInParent2.attackLevel; +		} +		if (inheritScale) +		{ +			go.transform.localScale *= base.transform.localScale.x; +		} +		if (SpawnedAction != null) +		{ +			SpawnedAction(go); +		} +	} + +	public void Spawn() +	{ +		for (int i = 0; i < objectToSpawn.Length; i++) +		{ +			Quaternion rotation = Quaternion.identity; +			if (spawnRot == SpawnRot.TransformRotation) +			{ +				rotation = base.transform.rotation; +			} +			GameObject go = UnityEngine.Object.Instantiate(objectToSpawn[i], base.transform.position, rotation); +			ConfigureObject(go); +			mostRecentlySpawnedObject = go; +		} +		if (destroyObject) +		{ +			UnityEngine.Object.Destroy(base.gameObject); +		} +		if (destroyRoot) +		{ +			UnityEngine.Object.Destroy(base.transform.root.gameObject); +		} +	} +} | 
