using UnityEngine; public class SceneBlockContainer : MonoBehaviour { public enum Targets { Free, Go, Attack, Defence, Stay, Num };// Num is use for get total target bumber 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); } // create appointed block at appointed position 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(targetType, level, blockType), blockPosition + environmentObj.transform.position, Quaternion.identity, transform); nowBlock = nowBlockObj.GetComponent(); 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); } }