太多了...总之能用了,就这样吧,也懒得用英文写了(;´Д`) ParameterContainer用于管理所有的Reward和Parameter. TargetController用于生成目标,然后再让SceneBlockContainer实际生成目标块,并且兼顾reward计算功能和目标观察结果的获取. EnemyContainer用于生成和删除敌人. SceneBlockContainer用于生成和删除目标块. States用于管理HP. SceneBlock用于管理目标块的...一堆东西,比如目标大小,目标区内人数等和目标所属状态等.
68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EnemyContainer : MonoBehaviour
|
|
{
|
|
public GameObject enemyPrefab;
|
|
public GameObject EnvironmentObj;
|
|
public GameObject TargetControllerObj;
|
|
|
|
private TargetController targetCon;
|
|
|
|
private void Start()
|
|
{
|
|
targetCon = TargetControllerObj.GetComponent<TargetController>();
|
|
}
|
|
|
|
|
|
// initialize enemy by random
|
|
public void randomInitEnemys(int EnemyNum)
|
|
{
|
|
for (int i = 0; i < EnemyNum; i++)
|
|
{
|
|
float randX = UnityEngine.Random.Range(targetCon.minEnemyAreaX, targetCon.maxEnemyAreaX);
|
|
float randZ = UnityEngine.Random.Range(targetCon.minEnemyAreaZ, targetCon.maxEnemyAreaZ);
|
|
int enemyY = 1;
|
|
initEnemyAtHere(new Vector3(randX, enemyY, randZ));
|
|
}
|
|
}
|
|
|
|
// initialize enemy by random but not in block area
|
|
public void randomInitEnemysExcept(int enemyNum,Vector3 blockPosition,float sceneSize)
|
|
{
|
|
float randX = 0f;
|
|
float randZ = 0f;
|
|
for (int i = 0; i < enemyNum; i++)
|
|
{
|
|
randX = UnityEngine.Random.Range(targetCon.minEnemyAreaX, targetCon.maxEnemyAreaX);
|
|
randZ = UnityEngine.Random.Range(targetCon.minEnemyAreaZ, targetCon.maxEnemyAreaZ);
|
|
while (Vector3.Distance(blockPosition, new Vector3(randX,0f,randZ)) < sceneSize/2)
|
|
{
|
|
// while in scene area then respawn
|
|
Debug.Log("spawn enemy in area, re:roll");
|
|
randX = UnityEngine.Random.Range(targetCon.minEnemyAreaX, targetCon.maxEnemyAreaX);
|
|
randZ = UnityEngine.Random.Range(targetCon.minEnemyAreaZ, targetCon.maxEnemyAreaZ);
|
|
}
|
|
|
|
int enemyY = 1;
|
|
initEnemyAtHere(new Vector3(randX, enemyY, randZ));
|
|
}
|
|
}
|
|
|
|
// initialize enemy to thisPosition
|
|
public void initEnemyAtHere(Vector3 thisPosition)
|
|
{
|
|
Instantiate(enemyPrefab, thisPosition + EnvironmentObj.transform.position, Quaternion.identity, this.transform);
|
|
}
|
|
|
|
// destroyEnemy delete enemyContainer's all enemy
|
|
public void destroyAllEnemys()
|
|
{
|
|
foreach (Transform childObj in this.transform)
|
|
{
|
|
childObj.GetComponent<states>().destroyMe();
|
|
}
|
|
}
|
|
}
|