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

87 lines
2.9 KiB
C#
Raw Normal View History

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[] attackBlockPrefabs = new GameObject[1];
public GameObject[] goBlockPrefabs = new GameObject[1];
public GameObject[] defencePrefabs = new GameObject[1];
private GameObject thisBlockObj;
public SceneBlock thisBlock;
private void Start()
{
}
// create block random
public void CreateNewBlock(Targets targetType, int blockType, Vector3 blockPosition, string tag1 = "Player", string tag2 = "Enemy")
{
// check if thisBlock is deleted
if (thisBlockObj != null)
{
// delete thisBlock
Debug.LogWarning("Block not clear!");
DestroyBlock();
}
// choose target type
switch (targetType)
{
case Targets.Go:
// goto
thisBlockObj = Instantiate(goBlockPrefabs[blockType], blockPosition + environmentObj.transform.position, Quaternion.identity, transform);
thisBlock = thisBlockObj.GetComponent<SceneBlock>();
thisBlock.group1Tag = tag1;
thisBlock.group2Tag = tag2;
sceneSize = thisBlock.blockSize;
break;
case Targets.Attack:
// attack
thisBlockObj = Instantiate(attackBlockPrefabs[blockType], blockPosition + environmentObj.transform.position, Quaternion.identity, transform);
thisBlock = thisBlockObj.GetComponent<SceneBlock>();
thisBlock.group1Tag = tag1;
thisBlock.group2Tag = tag2;
sceneSize = thisBlock.blockSize;
break;
case Targets.Defence:
// defence
thisBlockObj = Instantiate(defencePrefabs[blockType], blockPosition + environmentObj.transform.position, Quaternion.identity, transform);
thisBlock = thisBlockObj.GetComponent<SceneBlock>();
thisBlock.group1Tag = tag1;
thisBlock.group2Tag = tag2;
sceneSize = thisBlock.blockSize;
break;
default:
Debug.LogWarning("SceneBlock: CreateNewBlock: targetType not found!");
break;
}
}
// delete thisBlock
public void DestroyBlock()
{
if (thisBlock != null)
{
thisBlock.DestroyMe();
}
thisBlockObj = null;
thisBlock = null;
}
public (float, int) GetAgentTargetDistanceAndInside(Vector3 agentPosition)
{
return thisBlock.GetDistInArea(agentPosition);
}
public void InitializeBlock(GameObject envObj)
{
thisBlock.InitBlock(envObj);
}
}