From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/SpawnObjects.cs | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 GameCode/SpawnObjects.cs (limited to 'GameCode/SpawnObjects.cs') 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 SpawnedAction; + + [HideInInspector] + public GameObject mostRecentlySpawnedObject; + + private void ConfigureObject(GameObject go) + { + SpawnedAttack spawnedAttack = go.GetComponent(); + if (!spawnedAttack) + { + spawnedAttack = go.AddComponent(); + } + spawnedAttack.spawner = base.transform.root.GetComponent(); + if (!spawnedAttack.spawner) + { + SpawnedAttack componentInParent = base.transform.GetComponentInParent(); + if ((bool)componentInParent) + { + componentInParent.CopySpawnedAttackTo(go); + } + } + AttackLevel componentInParent2 = GetComponentInParent(); + 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); + } + } +} -- cgit v1.1-26-g67d0