太多了...总之能用了,就这样吧,也懒得用英文写了(;´Д`) ParameterContainer用于管理所有的Reward和Parameter. TargetController用于生成目标,然后再让SceneBlockContainer实际生成目标块,并且兼顾reward计算功能和目标观察结果的获取. EnemyContainer用于生成和删除敌人. SceneBlockContainer用于生成和删除目标块. States用于管理HP. SceneBlock用于管理目标块的...一堆东西,比如目标大小,目标区内人数等和目标所属状态等.
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);
|
|
}
|
|
|
|
|
|
}
|