using UnityEngine;
public class SceneBlockContainer : MonoBehaviour
{
[SerializeField]
private float sceneSize = 10f;
[SerializeField]
private GameObject environmentObj;
[SerializeField]
private GameObject hudObj;
// public GameObject[] attackBlockPrefabs = new GameObject[1];
// public GameObject[] goBlockPrefabs = new GameObject[1];
// public GameObject[] defencePrefabs = new GameObject[1];
public SceneBlock nowBlock;
private GameObject nowBlockObj;
private CommonParameterContainer commonParamCon;
private void Start()
{
commonParamCon = CommonParameterContainer.Instance;
}
///
/// Creates a specified block at a specified position.
/// 在指定位置创建指定类型的场景块。
///
/// The target type.
/// The level.
/// The block type.
/// The block position.
/// Tag 1 (optional, default is "Player").
/// Tag 2 (optional, default is "Enemy").
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(commonParamCon.scenePrefabSet.GetPrefab(level, blockType, targetType), 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);
}
}