浏览代码

update PushBlockTeamManager

/develop/superpush/int
Ruo-Ping Dong 4 年前
当前提交
c8ac489e
共有 3 个文件被更改,包括 25 次插入29 次删除
  1. 39
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockEnvController.cs
  2. 11
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockTeamManager.cs
  3. 4
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs

39
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockEnvController.cs


using System.Collections;
using System.Collections.Generic;
using Unity.MLAgents;
using Unity.MLAgents.Extensions.Teams;
using UnityEngine;
public class PushBlockEnvController : MonoBehaviour

/// </summary>
/// <returns></returns>
[Header("Max Environment Steps")] public int MaxEnvironmentSteps = 25000;
private int m_ResetTimer;
// private int m_ResetTimer;
/// <summary>
/// The area bounds.

item.Rb = item.T.GetComponent<Rigidbody>();
}
// Initialize TeamManager
m_TeamManager = new PushBlockTeamManager();
m_TeamManager = new PushBlockTeamManager(this);
m_TeamManager.SetTeamMaxStep(MaxEnvironmentSteps);
foreach (var item in AgentsList)
{
item.StartingPos = item.Agent.transform.position;

}
// Update is called once per frame
void FixedUpdate()
{
m_ResetTimer += 1;
if (m_ResetTimer > MaxEnvironmentSteps)
{
ResetScene();
}
}
/// <summary>
/// Use the ground's bounds to pick a random spawn position.
/// </summary>

if (done)
{
//Reset assets
ResetScene();
m_TeamManager.EndTeamEpisode();
}
}

}
void ResetScene()
public void ResetScene()
m_ResetTimer = 0;
// m_ResetTimer = 0;
//Random platform rot
var rotation = Random.Range(0, 4);

//End Episode
foreach (var item in AgentsList)
{
if (!item.Agent)
{
return;
}
item.Agent.EndEpisode();
}
// foreach (var item in AgentsList)
// {
// if (!item.Agent)
// {
// return;
// }
// item.Agent.EndEpisode();
// }
//Reset Agents
foreach (var item in AgentsList)
{

11
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockTeamManager.cs


public class PushBlockTeamManager : BaseTeamManager
{
List<Agent> m_AgentList = new List<Agent> { };
PushBlockEnvController m_envController;
public override void RegisterAgent(Agent agent)
public PushBlockTeamManager(PushBlockEnvController envController)
{
m_envController = envController;
}
public override void OnTeamEpisodeBegin()
m_AgentList.Add(agent);
m_envController.ResetScene();
}
}

4
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs


item.Rb = item.T.GetComponent<Rigidbody>();
}
// Initialize TeamManager
m_TeamManager = new PushBlockTeamManager();
// m_TeamManager = new PushBlockTeamManager();
foreach (var item in AgentsList)
{
item.StartingPos = item.Agent.transform.position;

// Add to team manager
item.Agent.SetTeamManager(m_TeamManager);
// item.Agent.SetTeamManager(m_TeamManager);
}
foreach (var item in ZombiesList)
{

正在加载...
取消
保存