Aimbot-ParallelEnv/Assets/Script/GameScript/SceneBlockContainer.cs

74 lines
2.5 KiB
C#
Raw Normal View History

using UnityEngine;
public class SceneBlockContainer : MonoBehaviour
{
[SerializeField]
private float sceneSize = 10f;
[SerializeField]
private GameObject environmentObj;
[SerializeField]
private GameObject commonParameterContainerObj;
[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 = commonParameterContainerObj.GetComponent<CommonParameterContainer>();
}
/// <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(commonParamCon.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);
}
}