using UnityEngine; public class SceneBlockContainer : MonoBehaviour { public float sceneSize = 10f; public GameObject environmentObj; public GameObject hudObj; // public GameObject[] attackBlockPrefabs = new GameObject[1]; // public GameObject[] goBlockPrefabs = new GameObject[1]; // public GameObject[] defencePrefabs = new GameObject[1]; public SceneBlocksSet scenePrefabSet; private GameObject nowBlockObj; public SceneBlock nowBlock; private void Start() { // initialize scene prefab set scenePrefabSet.InitializeSceneBlocksSet(hudObj); } /// <summary> /// Creates a specified block at a specified position. /// 在指定位置创建指定类型的场景块。 /// </summary> /// <param name="targetType">The target type.</param> /// <param name="level">The level.</param> /// <param name="blockType">The block type.</param> /// <param name="blockPosition">The block position.</param> /// <param name="tag1">Tag 1 (optional, default is "Player").</param> /// <param name="tag2">Tag 2 (optional, default is "Enemy").</param> public void CreateNewBlock(Targets targetType, int level, int blockType, Vector3 blockPosition, string tag1 = "Player", string tag2 = "Enemy") { // check if nowBlock is deleted if (nowBlockObj != null) { // delete nowBlock // Debug.LogWarning("SceneBlockContainer.CreateNewBlock: Block not clear!"); DestroyBlock(); } // choose target type nowBlockObj = Instantiate(scenePrefabSet.GetPrefab(level, blockType, targetType), blockPosition + environmentObj.transform.position, Quaternion.identity, transform); nowBlock = nowBlockObj.GetComponent<SceneBlock>(); nowBlock.group1Tag = tag1; nowBlock.group2Tag = tag2; sceneSize = nowBlock.blockSize; } // delete nowBlock public void DestroyBlock() { if (nowBlock != null) { nowBlock.DestroyMe(); } nowBlockObj = null; nowBlock = null; } public (float, int) GetAgentTargetDistanceAndInside(Vector3 agentPosition) { return nowBlock.GetDistInArea(agentPosition); } public void InitializeBlock(GameObject envObj) { nowBlock.InitBlock(envObj); } }