78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class SceneBlockContainer : MonoBehaviour
|
||
|
{
|
||
|
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(int targetType, int blockType, Vector3 blockPosition,string tag1,string tag2)
|
||
|
{
|
||
|
// check if thisBlock is deleted
|
||
|
if (thisBlockObj != null)
|
||
|
{
|
||
|
// delete thisBlock
|
||
|
Debug.LogWarning("Block not clear!");
|
||
|
destroyBlock();
|
||
|
}
|
||
|
// choose target type
|
||
|
switch (targetType)
|
||
|
{
|
||
|
case (int)TargetController.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 (int)TargetController.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 (int)TargetController.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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 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);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|