2023-09-08 13:05:43 +00:00
|
|
|
|
using UnityEngine;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
|
|
|
|
|
public class SceneBlockContainer : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float sceneSize = 10f;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
public GameObject environmentObj;
|
2023-10-08 14:56:11 +00:00
|
|
|
|
public GameObject parameterContainerObj;
|
2023-08-22 17:58:50 +00:00
|
|
|
|
public GameObject hudObj;
|
2023-09-14 11:13:53 +00:00
|
|
|
|
|
2023-08-22 17:58:50 +00:00
|
|
|
|
// public GameObject[] attackBlockPrefabs = new GameObject[1];
|
|
|
|
|
// public GameObject[] goBlockPrefabs = new GameObject[1];
|
|
|
|
|
// public GameObject[] defencePrefabs = new GameObject[1];
|
2022-11-28 22:54:08 +00:00
|
|
|
|
|
2023-08-22 17:58:50 +00:00
|
|
|
|
public SceneBlock nowBlock;
|
2023-10-08 14:56:11 +00:00
|
|
|
|
private GameObject nowBlockObj;
|
|
|
|
|
private ParameterContainer paramCon;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
2023-10-08 14:56:11 +00:00
|
|
|
|
paramCon = parameterContainerObj.GetComponent<ParameterContainer>();
|
2022-11-28 22:54:08 +00:00
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
|
|
2023-09-08 13:05:43 +00:00
|
|
|
|
/// <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>
|
2023-08-22 17:58:50 +00:00
|
|
|
|
public void CreateNewBlock(Targets targetType, int level, int blockType, Vector3 blockPosition, string tag1 = "Player", string tag2 = "Enemy")
|
2022-11-28 22:54:08 +00:00
|
|
|
|
{
|
2023-08-22 17:58:50 +00:00
|
|
|
|
// check if nowBlock is deleted
|
|
|
|
|
if (nowBlockObj != null)
|
2022-11-28 22:54:08 +00:00
|
|
|
|
{
|
2023-08-22 17:58:50 +00:00
|
|
|
|
// delete nowBlock
|
|
|
|
|
// Debug.LogWarning("SceneBlockContainer.CreateNewBlock: Block not clear!");
|
2023-06-30 09:30:12 +00:00
|
|
|
|
DestroyBlock();
|
2022-11-28 22:54:08 +00:00
|
|
|
|
}
|
|
|
|
|
// choose target type
|
2023-10-08 14:56:11 +00:00
|
|
|
|
nowBlockObj = Instantiate(paramCon.scenePrefabSet.GetPrefab(level, blockType, targetType), blockPosition + environmentObj.transform.position, Quaternion.identity, transform);
|
2023-08-22 17:58:50 +00:00
|
|
|
|
nowBlock = nowBlockObj.GetComponent<SceneBlock>();
|
|
|
|
|
nowBlock.group1Tag = tag1;
|
|
|
|
|
nowBlock.group2Tag = tag2;
|
|
|
|
|
sceneSize = nowBlock.blockSize;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-22 17:58:50 +00:00
|
|
|
|
// delete nowBlock
|
2023-06-30 09:30:12 +00:00
|
|
|
|
public void DestroyBlock()
|
2022-11-28 22:54:08 +00:00
|
|
|
|
{
|
2023-08-22 17:58:50 +00:00
|
|
|
|
if (nowBlock != null)
|
2022-11-28 22:54:08 +00:00
|
|
|
|
{
|
2023-08-22 17:58:50 +00:00
|
|
|
|
nowBlock.DestroyMe();
|
2022-11-28 22:54:08 +00:00
|
|
|
|
}
|
2023-08-22 17:58:50 +00:00
|
|
|
|
nowBlockObj = null;
|
|
|
|
|
nowBlock = null;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 09:30:12 +00:00
|
|
|
|
public (float, int) GetAgentTargetDistanceAndInside(Vector3 agentPosition)
|
2022-11-28 22:54:08 +00:00
|
|
|
|
{
|
2023-08-22 17:58:50 +00:00
|
|
|
|
return nowBlock.GetDistInArea(agentPosition);
|
2022-11-28 22:54:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 09:30:12 +00:00
|
|
|
|
public void InitializeBlock(GameObject envObj)
|
2023-06-29 06:18:10 +00:00
|
|
|
|
{
|
2023-08-22 17:58:50 +00:00
|
|
|
|
nowBlock.InitBlock(envObj);
|
2023-06-29 06:18:10 +00:00
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
|
}
|