Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

54 行
1.5 KiB

using UnityEngine;
using MLAgentsExamples;
public class PyramidArea : Area
{
public GameObject pyramid;
public GameObject stonePyramid;
public GameObject[] spawnAreas;
public int numPyra;
public float range;
public void CreatePyramid(int numObjects, int spawnAreaIndex)
{
CreateObject(numObjects, pyramid, spawnAreaIndex);
}
public void CreateStonePyramid(int numObjects, int spawnAreaIndex)
{
CreateObject(numObjects, stonePyramid, spawnAreaIndex);
}
void CreateObject(int numObjects, GameObject desiredObject, int spawnAreaIndex)
{
for (var i = 0; i < numObjects; i++)
{
var newObject = Instantiate(desiredObject, Vector3.zero,
Quaternion.Euler(0f, 0f, 0f), transform);
PlaceObject(newObject, spawnAreaIndex);
}
}
public void PlaceObject(GameObject objectToPlace, int spawnAreaIndex)
{
var spawnTransform = spawnAreas[spawnAreaIndex].transform;
var xRange = spawnTransform.localScale.x / 2.1f;
var zRange = spawnTransform.localScale.z / 2.1f;
objectToPlace.transform.position = new Vector3(Random.Range(-xRange, xRange), 2f, Random.Range(-zRange, zRange))
+ spawnTransform.position;
}
public void CleanPyramidArea()
{
foreach (Transform child in transform)
if (child.CompareTag("pyramid"))
{
Destroy(child.gameObject);
}
}
public override void ResetArea()
{
}
}