2022-11-28 22:54:08 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class SceneBlockContainer : MonoBehaviour
|
|
|
|
{
|
2023-06-29 06:18:10 +00:00
|
|
|
public enum Targets { Free, Go, Attack, Defence, Stay, Num };// Num is use for get total target bumber
|
2022-11-28 22:54:08 +00:00
|
|
|
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
|
2023-04-09 14:35:38 +00:00
|
|
|
public void createNewBlock(Targets targetType, int blockType, Vector3 blockPosition,string tag1 = "Player", string tag2 = "Enemy")
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
// check if thisBlock is deleted
|
|
|
|
if (thisBlockObj != null)
|
|
|
|
{
|
|
|
|
// delete thisBlock
|
|
|
|
Debug.LogWarning("Block not clear!");
|
|
|
|
destroyBlock();
|
|
|
|
}
|
|
|
|
// choose target type
|
|
|
|
switch (targetType)
|
|
|
|
{
|
2023-04-09 14:35:38 +00:00
|
|
|
case Targets.Go:
|
2022-11-28 22:54:08 +00:00
|
|
|
// 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;
|
2023-04-09 14:35:38 +00:00
|
|
|
case Targets.Attack:
|
2022-11-28 22:54:08 +00:00
|
|
|
// 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;
|
2023-04-09 14:35:38 +00:00
|
|
|
case Targets.Defence:
|
2022-11-28 22:54:08 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete thisBlock
|
|
|
|
public void destroyBlock()
|
|
|
|
{
|
|
|
|
if (thisBlock != null)
|
|
|
|
{
|
|
|
|
thisBlock.destroyMe();
|
|
|
|
}
|
|
|
|
thisBlockObj = null;
|
|
|
|
thisBlock = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public (float, int) getAgentTargetDistanceAndInside(Vector3 agentPosition)
|
|
|
|
{
|
|
|
|
return thisBlock.getDist_inArea(agentPosition);
|
|
|
|
}
|
|
|
|
|
2023-06-29 06:18:10 +00:00
|
|
|
public void initializeBlock(GameObject envObj)
|
|
|
|
{
|
|
|
|
thisBlock.initBlock(envObj);
|
|
|
|
}
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|