Ervin Teng
4 年前
当前提交
844b5955
共有 35 个文件被更改,包括 22 次插入 和 8172 次删除
-
9com.unity.ml-agents.extensions/Runtime/Teams.meta
-
12com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs.meta
-
12config/ppo/PushBlock.yaml
-
60Project/Assets/ML-Agents/Examples/PushBlock/Scripts/GoalDetectTrigger.cs
-
11Project/Assets/ML-Agents/Examples/PushBlock/Scripts/GoalDetectTrigger.cs.meta
-
241Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockEnvController.cs
-
11Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockEnvController.cs.meta
-
45Project/Assets/ML-Agents/Examples/PushBlock/Scripts/SimpleNPC.cs
-
11Project/Assets/ML-Agents/Examples/PushBlock/Scripts/SimpleNPC.cs.meta
-
1001Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockCC.onnx
-
14Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockCC.onnx.meta
-
1001Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockCollab.onnx
-
14Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockCollab.onnx.meta
-
1001Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockMaster.onnx
-
14Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockMaster.onnx.meta
-
1001Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockSuperNoEgo.onnx
-
143Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/CollisionCallbacks.cs
-
11Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/CollisionCallbacks.cs.meta
-
7Project/Assets/ML-Agents/Examples/WallJump/Prefabs/WallJumpCollabArea.prefab.meta
-
1001Project/Assets/ML-Agents/Examples/WallJump/Prefabs/WallJumpCollabArea.prefab
-
7Project/Assets/ML-Agents/Examples/WallJump/Scenes/WallJumpCollab.unity.meta
-
1001Project/Assets/ML-Agents/Examples/WallJump/Scenes/WallJumpCollab.unity
-
50Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallAreaScoring.cs
-
11Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallAreaScoring.cs.meta
-
11Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpCollabAgent.cs.meta
-
67Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpCollabAgent.cs
-
419Project/Packages/packages-lock.json
-
10Project/ProjectSettings/XRSettings.asset
-
907Project/Recordings/superpushnoego.mp4
-
26config/ppo/HallwayCollab.yaml
-
65config/ppo/CubeWarsV3.yaml
|
|||
fileFormatVersion: 2 |
|||
fileFormatVersion: 2 |
|||
timeCreated: 1610064454 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
fileFormatVersion: 2 |
|||
timeCreated: 1610064493 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Events; |
|||
|
|||
public class GoalDetectTrigger : MonoBehaviour |
|||
{ |
|||
|
|||
[Header("Trigger Collider Tag To Detect")] |
|||
public string tagToDetect = "goal"; //collider tag to detect
|
|||
|
|||
[Header("Goal Value")] |
|||
public float GoalValue = 1; |
|||
|
|||
private Collider m_col; |
|||
[System.Serializable] |
|||
public class TriggerEvent : UnityEvent<Collider, float> |
|||
{ |
|||
} |
|||
|
|||
[Header("Trigger Callbacks")] |
|||
public TriggerEvent onTriggerEnterEvent = new TriggerEvent(); |
|||
public TriggerEvent onTriggerStayEvent = new TriggerEvent(); |
|||
public TriggerEvent onTriggerExitEvent = new TriggerEvent(); |
|||
|
|||
private void OnTriggerEnter(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerEnterEvent.Invoke(m_col, GoalValue); |
|||
} |
|||
} |
|||
|
|||
private void OnTriggerStay(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerStayEvent.Invoke(m_col, GoalValue); |
|||
} |
|||
} |
|||
|
|||
private void OnTriggerExit(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerExitEvent.Invoke(m_col, GoalValue); |
|||
} |
|||
} |
|||
// Start is called before the first frame update
|
|||
void Awake() |
|||
{ |
|||
m_col = GetComponent<Collider>(); |
|||
} |
|||
|
|||
// Update is called once per frame
|
|||
void Update() |
|||
{ |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9dcea692df32b46b4a884cfcc150aef7 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using Unity.MLAgents; |
|||
using UnityEngine; |
|||
|
|||
public class PushBlockEnvController : MonoBehaviour |
|||
{ |
|||
[System.Serializable] |
|||
public class AgentInfo |
|||
{ |
|||
public PushAgentCollab Agent; |
|||
[HideInInspector] |
|||
public Vector3 StartingPos; |
|||
[HideInInspector] |
|||
public Quaternion StartingRot; |
|||
[HideInInspector] |
|||
public Rigidbody Rb; |
|||
|
|||
} |
|||
|
|||
[System.Serializable] |
|||
public class BlockInfo |
|||
{ |
|||
public Transform T; |
|||
[HideInInspector] |
|||
public Vector3 StartingPos; |
|||
[HideInInspector] |
|||
public Quaternion StartingRot; |
|||
[HideInInspector] |
|||
public Rigidbody Rb; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Max Academy steps before this platform resets
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
[Header("Max Environment Steps")] public int MaxEnvironmentSteps = 25000; |
|||
private int m_ResetTimer; |
|||
|
|||
/// <summary>
|
|||
/// The area bounds.
|
|||
/// </summary>
|
|||
[HideInInspector] |
|||
public Bounds areaBounds; |
|||
/// <summary>
|
|||
/// The ground. The bounds are used to spawn the elements.
|
|||
/// </summary>
|
|||
public GameObject ground; |
|||
|
|||
public GameObject area; |
|||
|
|||
Material m_GroundMaterial; //cached on Awake()
|
|||
|
|||
/// <summary>
|
|||
/// We will be changing the ground material based on success/failue
|
|||
/// </summary>
|
|||
Renderer m_GroundRenderer; |
|||
|
|||
public List<AgentInfo> AgentsList = new List<AgentInfo>(); |
|||
public List<BlockInfo> BlocksList = new List<BlockInfo>(); |
|||
|
|||
public bool UseRandomAgentRotation = true; |
|||
public bool UseRandomAgentPosition = true; |
|||
public bool UseRandomBlockRotation = true; |
|||
public bool UseRandomBlockPosition = true; |
|||
PushBlockSettings m_PushBlockSettings; |
|||
|
|||
private int m_NumberOfRemainingBlocks; |
|||
|
|||
private PushBlockTeamManager m_TeamManager; |
|||
|
|||
void Start() |
|||
{ |
|||
|
|||
// Get the ground's bounds
|
|||
areaBounds = ground.GetComponent<Collider>().bounds; |
|||
// Get the ground renderer so we can change the material when a goal is scored
|
|||
m_GroundRenderer = ground.GetComponent<Renderer>(); |
|||
// Starting material
|
|||
m_GroundMaterial = m_GroundRenderer.material; |
|||
m_PushBlockSettings = FindObjectOfType<PushBlockSettings>(); |
|||
foreach (var item in BlocksList) |
|||
{ |
|||
item.StartingPos = item.T.transform.position; |
|||
item.StartingRot = item.T.transform.rotation; |
|||
item.Rb = item.T.GetComponent<Rigidbody>(); |
|||
} |
|||
// Initialize TeamManager
|
|||
m_TeamManager = new PushBlockTeamManager(); |
|||
foreach (var item in AgentsList) |
|||
{ |
|||
item.StartingPos = item.Agent.transform.position; |
|||
item.StartingRot = item.Agent.transform.rotation; |
|||
item.Rb = item.Agent.GetComponent<Rigidbody>(); |
|||
item.Agent.SetTeamManager(m_TeamManager); |
|||
} |
|||
|
|||
ResetScene(); |
|||
|
|||
} |
|||
|
|||
// 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>
|
|||
public Vector3 GetRandomSpawnPos() |
|||
{ |
|||
var foundNewSpawnLocation = false; |
|||
var randomSpawnPos = Vector3.zero; |
|||
while (foundNewSpawnLocation == false) |
|||
{ |
|||
var randomPosX = Random.Range(-areaBounds.extents.x * m_PushBlockSettings.spawnAreaMarginMultiplier, |
|||
areaBounds.extents.x * m_PushBlockSettings.spawnAreaMarginMultiplier); |
|||
|
|||
var randomPosZ = Random.Range(-areaBounds.extents.z * m_PushBlockSettings.spawnAreaMarginMultiplier, |
|||
areaBounds.extents.z * m_PushBlockSettings.spawnAreaMarginMultiplier); |
|||
randomSpawnPos = ground.transform.position + new Vector3(randomPosX, 1f, randomPosZ); |
|||
if (Physics.CheckBox(randomSpawnPos, new Vector3(2.5f, 0.01f, 2.5f)) == false) |
|||
{ |
|||
foundNewSpawnLocation = true; |
|||
} |
|||
} |
|||
return randomSpawnPos; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Resets the block position and velocities.
|
|||
/// </summary>
|
|||
void ResetBlock(BlockInfo block) |
|||
{ |
|||
// Get a random position for the block.
|
|||
block.T.position = GetRandomSpawnPos(); |
|||
|
|||
// Reset block velocity back to zero.
|
|||
block.Rb.velocity = Vector3.zero; |
|||
|
|||
// Reset block angularVelocity back to zero.
|
|||
block.Rb.angularVelocity = Vector3.zero; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Swap ground material, wait time seconds, then swap back to the regular material.
|
|||
/// </summary>
|
|||
IEnumerator GoalScoredSwapGroundMaterial(Material mat, float time) |
|||
{ |
|||
m_GroundRenderer.material = mat; |
|||
yield return new WaitForSeconds(time); // Wait for 2 sec
|
|||
m_GroundRenderer.material = m_GroundMaterial; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Called when the agent moves the block into the goal.
|
|||
/// </summary>
|
|||
public void ScoredAGoal(Collider col, float score) |
|||
{ |
|||
//Decrement the counter
|
|||
m_NumberOfRemainingBlocks--; |
|||
|
|||
//Are we done?
|
|||
bool done = m_NumberOfRemainingBlocks == 0; |
|||
|
|||
//Disable the block
|
|||
col.gameObject.SetActive(false); |
|||
|
|||
//Give Agent Rewards
|
|||
foreach (var item in AgentsList) |
|||
{ |
|||
item.Agent.AddReward(score); |
|||
} |
|||
|
|||
// Swap ground material for a bit to indicate we scored.
|
|||
StartCoroutine(GoalScoredSwapGroundMaterial(m_PushBlockSettings.goalScoredMaterial, 0.5f)); |
|||
|
|||
if (done) |
|||
{ |
|||
//Reset assets
|
|||
ResetScene(); |
|||
} |
|||
} |
|||
|
|||
Quaternion GetRandomRot() |
|||
{ |
|||
return Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0); |
|||
} |
|||
|
|||
void ResetScene() |
|||
{ |
|||
m_ResetTimer = 0; |
|||
|
|||
//Random platform rot
|
|||
var rotation = Random.Range(0, 4); |
|||
var rotationAngle = rotation * 90f; |
|||
area.transform.Rotate(new Vector3(0f, rotationAngle, 0f)); |
|||
|
|||
//End Episode
|
|||
foreach (var item in AgentsList) |
|||
{ |
|||
if (!item.Agent) |
|||
{ |
|||
return; |
|||
} |
|||
item.Agent.EndEpisode(); |
|||
} |
|||
//Reset Agents
|
|||
foreach (var item in AgentsList) |
|||
{ |
|||
var pos = UseRandomAgentPosition ? GetRandomSpawnPos() : item.StartingPos; |
|||
var rot = UseRandomAgentRotation ? GetRandomRot() : item.StartingRot; |
|||
|
|||
item.Agent.transform.SetPositionAndRotation(pos, rot); |
|||
item.Rb.velocity = Vector3.zero; |
|||
item.Rb.angularVelocity = Vector3.zero; |
|||
} |
|||
|
|||
//Reset Blocks
|
|||
foreach (var item in BlocksList) |
|||
{ |
|||
var pos = UseRandomBlockPosition ? GetRandomSpawnPos() : item.StartingPos; |
|||
var rot = UseRandomBlockRotation ? GetRandomRot() : item.StartingRot; |
|||
|
|||
item.T.transform.SetPositionAndRotation(pos, rot); |
|||
item.Rb.velocity = Vector3.zero; |
|||
item.Rb.angularVelocity = Vector3.zero; |
|||
item.T.gameObject.SetActive(true); |
|||
} |
|||
|
|||
//Reset counter
|
|||
m_NumberOfRemainingBlocks = BlocksList.Count; |
|||
// m_NumberOfRemainingBlocks = 2;
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4bb2bb36bb51d452ab58d30a868dfab3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// using System;
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class SimpleNPC : MonoBehaviour |
|||
{ |
|||
|
|||
public Transform target; |
|||
|
|||
private Rigidbody rb; |
|||
|
|||
public float walkSpeed = 1; |
|||
// public ForceMode walkForceMode;
|
|||
private Vector3 dirToGo; |
|||
|
|||
// private Vector3 m_StartingPos;
|
|||
// Start is called before the first frame update
|
|||
void Awake() |
|||
{ |
|||
rb = GetComponent<Rigidbody>(); |
|||
// m_StartingPos = transform.position;
|
|||
} |
|||
|
|||
// Update is called once per frame
|
|||
void Update() |
|||
{ |
|||
} |
|||
|
|||
void FixedUpdate() |
|||
{ |
|||
dirToGo = target.position - transform.position; |
|||
dirToGo.y = 0; |
|||
rb.rotation = Quaternion.LookRotation(dirToGo); |
|||
// rb.AddForce(dirToGo.normalized * walkSpeed * Time.fixedDeltaTime, walkForceMode);
|
|||
// rb.MovePosition(rb.transform.TransformDirection(Vector3.forward * walkSpeed * Time.deltaTime));
|
|||
// rb.MovePosition(rb.transform.TransformVector() (Vector3.forward * walkSpeed * Time.deltaTime));
|
|||
rb.MovePosition(transform.position + transform.forward * walkSpeed * Time.deltaTime); |
|||
} |
|||
|
|||
public void SetRandomWalkSpeed() |
|||
{ |
|||
walkSpeed = Random.Range(6f, 7f); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9685bac759362440ea71765cdece3305 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockCC.onnx
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 9a4ea4894b7fb49859cfa9c16652b207 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: main obj |
|||
11400002: model data |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3} |
|||
optimizeModel: 1 |
|||
forceArbitraryBatchSize: 1 |
|||
treatErrorsAsWarnings: 0 |
1001
Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockCollab.onnx
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: a051c5abff78d40c586086c42e713e18 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: main obj |
|||
11400002: model data |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3} |
|||
optimizeModel: 1 |
|||
forceArbitraryBatchSize: 1 |
|||
treatErrorsAsWarnings: 0 |
1001
Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockMaster.onnx
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 76af036f6a9b94e3c988951e6315dab4 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: main obj |
|||
11400002: model data |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3} |
|||
optimizeModel: 1 |
|||
forceArbitraryBatchSize: 1 |
|||
treatErrorsAsWarnings: 0 |
1001
Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockSuperNoEgo.onnx
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using UnityEngine; |
|||
using Random = UnityEngine.Random; |
|||
using Unity.MLAgents; |
|||
using UnityEngine.Events; |
|||
|
|||
namespace Unity.MLAgentsExamples |
|||
{ |
|||
/// <summary>
|
|||
/// Utility class to allow target placement and collision detection with an agent
|
|||
/// Add this script to the target you want the agent to touch.
|
|||
/// Callbacks will be triggered any time the target is touched with a collider tagged as 'tagToDetect'
|
|||
/// </summary>
|
|||
public class CollisionCallbacks : MonoBehaviour |
|||
{ |
|||
// [System.Serializable] public class BoolEvent : UnityEvent<bool> { }
|
|||
// [SerializeField] BoolEvent boolEvent = new BoolEvent();
|
|||
// public void OnBoolEvent(bool value)
|
|||
// {
|
|||
// Debug.Log($"OnBoolEvent {value}");
|
|||
// }
|
|||
|
|||
|
|||
[Header("Collider Tag To Detect")] |
|||
public string tagToDetect = "agent"; //collider tag to detect
|
|||
|
|||
// [Header("Target Placement")]
|
|||
// public float spawnRadius; //The radius in which a target can be randomly spawned.
|
|||
// public bool respawnIfTouched; //Should the target respawn to a different position when touched
|
|||
//
|
|||
// [Header("Target Fell Protection")]
|
|||
// public bool respawnIfFallsOffPlatform = true; //If the target falls off the platform, reset the position.
|
|||
// public float fallDistance = 5; //distance below the starting height that will trigger a respawn
|
|||
//
|
|||
//
|
|||
// private Vector3 m_startingPos; //the starting position of the target
|
|||
// private Agent m_agentTouching; //the agent currently touching the target
|
|||
|
|||
[System.Serializable] |
|||
// public class TriggerEvent : UnityEvent<string>
|
|||
public class TriggerEvent : UnityEvent<Collider> |
|||
{ |
|||
} |
|||
|
|||
[Header("Trigger Callbacks")] |
|||
public TriggerEvent onTriggerEnterEvent = new TriggerEvent(); |
|||
public TriggerEvent onTriggerStayEvent = new TriggerEvent(); |
|||
public TriggerEvent onTriggerExitEvent = new TriggerEvent(); |
|||
|
|||
[System.Serializable] |
|||
public class CollisionEvent : UnityEvent<Collision, Transform> |
|||
{ |
|||
} |
|||
|
|||
[Header("Collision Callbacks")] |
|||
public CollisionEvent onCollisionEnterEvent = new CollisionEvent(); |
|||
public CollisionEvent onCollisionStayEvent = new CollisionEvent(); |
|||
public CollisionEvent onCollisionExitEvent = new CollisionEvent(); |
|||
|
|||
// // Start is called before the first frame update
|
|||
// void OnEnable()
|
|||
// {
|
|||
// m_startingPos = transform.position;
|
|||
// if (respawnIfTouched)
|
|||
// {
|
|||
// MoveTargetToRandomPosition();
|
|||
// }
|
|||
// }
|
|||
|
|||
// void Update()
|
|||
// {
|
|||
// if (respawnIfFallsOffPlatform)
|
|||
// {
|
|||
// if (transform.position.y < m_startingPos.y - fallDistance)
|
|||
// {
|
|||
// Debug.Log($"{transform.name} Fell Off Platform");
|
|||
// MoveTargetToRandomPosition();
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// Moves target to a random position within specified radius.
|
|||
// /// </summary>
|
|||
// public void MoveTargetToRandomPosition()
|
|||
// {
|
|||
// var newTargetPos = m_startingPos + (Random.insideUnitSphere * spawnRadius);
|
|||
// newTargetPos.y = m_startingPos.y;
|
|||
// transform.position = newTargetPos;
|
|||
// }
|
|||
|
|||
private void OnCollisionEnter(Collision col) |
|||
{ |
|||
if (col.transform.CompareTag(tagToDetect)) |
|||
{ |
|||
onCollisionEnterEvent.Invoke(col, transform); |
|||
// if (respawnIfTouched)
|
|||
// {
|
|||
// MoveTargetToRandomPosition();
|
|||
// }
|
|||
} |
|||
} |
|||
|
|||
private void OnCollisionStay(Collision col) |
|||
{ |
|||
if (col.transform.CompareTag(tagToDetect)) |
|||
{ |
|||
onCollisionStayEvent.Invoke(col, transform); |
|||
} |
|||
} |
|||
|
|||
private void OnCollisionExit(Collision col) |
|||
{ |
|||
if (col.transform.CompareTag(tagToDetect)) |
|||
{ |
|||
onCollisionExitEvent.Invoke(col, transform); |
|||
} |
|||
} |
|||
|
|||
private void OnTriggerEnter(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerEnterEvent.Invoke(col); |
|||
} |
|||
} |
|||
|
|||
private void OnTriggerStay(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerStayEvent.Invoke(col); |
|||
} |
|||
} |
|||
|
|||
private void OnTriggerExit(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerExitEvent.Invoke(col); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 506de7b261f374159a5cdfdb0ff48c0c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ff1a5743be49d43f08378dcd76451821 |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/WallJump/Prefabs/WallJumpCollabArea.prefab
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 136090e065a8f48bfb97ea3083893d8a |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/WallJump/Scenes/WallJumpCollab.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class WallAreaScoring : MonoBehaviour |
|||
{ |
|||
public GameObject[] agents; |
|||
WallJumpSettings m_WallJumpSettings; |
|||
Renderer m_GroundRenderer; |
|||
Material m_GroundMaterial; |
|||
|
|||
protected IEnumerator GoalScoredSwapGroundMaterial(Material mat, float time) |
|||
{ |
|||
m_GroundRenderer.material = mat; |
|||
yield return new WaitForSeconds(time); //wait for 2 sec
|
|||
m_GroundRenderer.material = m_GroundMaterial; |
|||
} |
|||
|
|||
public void Start() |
|||
{ |
|||
m_WallJumpSettings = FindObjectOfType<WallJumpSettings>(); |
|||
m_GroundRenderer = GetComponent<Renderer>(); |
|||
m_GroundMaterial = m_GroundRenderer.material; |
|||
} |
|||
|
|||
public void WinCondition() |
|||
{ |
|||
foreach (var agent in agents) |
|||
{ |
|||
WallJumpCollabAgent agentScript = agent.GetComponent<WallJumpCollabAgent>(); |
|||
agentScript.SetReward(1f); |
|||
agentScript.EndEpisode(); |
|||
} |
|||
StartCoroutine( |
|||
GoalScoredSwapGroundMaterial(m_WallJumpSettings.goalScoredMaterial, 1f)); |
|||
} |
|||
|
|||
public void LoseCondition() |
|||
{ |
|||
foreach (var agent in agents) |
|||
{ |
|||
WallJumpCollabAgent agentScript = agent.GetComponent<WallJumpCollabAgent>(); |
|||
agentScript.SetReward(-1f); |
|||
agentScript.EndEpisode(); |
|||
|
|||
} |
|||
StartCoroutine( |
|||
GoalScoredSwapGroundMaterial(m_WallJumpSettings.failMaterial, .2f)); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ad7213222795741f5b6ca2b332f16da9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 2cdbc0d9a64fe4b12a3ed4b81a151117 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
//Put this script on your blue cube.
|
|||
|
|||
using System.Collections; |
|||
using UnityEngine; |
|||
using Unity.MLAgents; |
|||
using Unity.Barracuda; |
|||
using Unity.MLAgents.Actuators; |
|||
using Unity.MLAgents.Sensors; |
|||
using Unity.MLAgentsExamples; |
|||
|
|||
public class WallJumpCollabAgent : WallJumpAgent |
|||
{ |
|||
Vector3 m_InitialPosition; |
|||
|
|||
WallAreaScoring m_Scoring; |
|||
public override void Initialize() |
|||
{ |
|||
m_WallJumpSettings = FindObjectOfType<WallJumpSettings>(); |
|||
m_Scoring = ground.GetComponent<WallAreaScoring>(); |
|||
m_Configuration = 5; |
|||
|
|||
m_AgentRb = GetComponent<Rigidbody>(); |
|||
// m_ShortBlockRb = shortBlock.GetComponent<Rigidbody>();
|
|||
m_SpawnAreaBounds = spawnArea.GetComponent<Collider>().bounds; |
|||
m_GroundRenderer = ground.GetComponent<Renderer>(); |
|||
m_GroundMaterial = m_GroundRenderer.material; |
|||
m_InitialPosition = transform.localPosition; |
|||
spawnArea.SetActive(false); |
|||
|
|||
m_ResetParams = Academy.Instance.EnvironmentParameters; |
|||
} |
|||
public override void OnEpisodeBegin() |
|||
{ |
|||
transform.localPosition = m_InitialPosition; |
|||
m_Configuration = 5; |
|||
m_AgentRb.velocity = default(Vector3); |
|||
} |
|||
|
|||
public override void OnActionReceived(ActionBuffers actionBuffers) |
|||
{ |
|||
MoveAgent(actionBuffers.DiscreteActions); |
|||
if (!Physics.Raycast(m_AgentRb.position, Vector3.down, 20)) |
|||
{ |
|||
m_Scoring.LoseCondition(); |
|||
} |
|||
} |
|||
|
|||
protected override void ConfigureAgent(int config) |
|||
{ |
|||
var localScale = wall.transform.localScale; |
|||
var height = m_ResetParams.GetWithDefault("big_wall_height", 9); |
|||
localScale = new Vector3( |
|||
localScale.x, |
|||
height, |
|||
localScale.z); |
|||
wall.transform.localScale = localScale; |
|||
} |
|||
|
|||
// Detect when the agent hits the goal
|
|||
protected override void OnTriggerStay(Collider col) |
|||
{ |
|||
if (col.gameObject.CompareTag("goal") && DoGroundCheck(true)) |
|||
{ |
|||
m_Scoring.WinCondition(); |
|||
} |
|||
} |
|||
} |
|
|||
{ |
|||
"dependencies": { |
|||
"com.unity.2d.sprite": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.2d.tilemap": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.ads": { |
|||
"version": "3.4.7", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": { |
|||
"com.unity.ugui": "1.0.0" |
|||
}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.analytics": { |
|||
"version": "3.3.5", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": { |
|||
"com.unity.ugui": "1.0.0" |
|||
}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.barracuda": { |
|||
"version": "1.2.1-preview", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": { |
|||
"com.unity.burst": "1.3.4", |
|||
"com.unity.modules.jsonserialize": "1.0.0", |
|||
"com.unity.modules.imageconversion": "1.0.0" |
|||
}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.burst": { |
|||
"version": "1.3.4", |
|||
"depth": 1, |
|||
"source": "registry", |
|||
"dependencies": { |
|||
"com.unity.mathematics": "1.2.1" |
|||
}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.collab-proxy": { |
|||
"version": "1.2.16", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": {}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.ext.nunit": { |
|||
"version": "1.0.0", |
|||
"depth": 1, |
|||
"source": "registry", |
|||
"dependencies": {}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.ide.rider": { |
|||
"version": "1.1.4", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": { |
|||
"com.unity.test-framework": "1.1.1" |
|||
}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.ide.vscode": { |
|||
"version": "1.2.1", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": {}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.mathematics": { |
|||
"version": "1.2.1", |
|||
"depth": 2, |
|||
"source": "registry", |
|||
"dependencies": {}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.ml-agents": { |
|||
"version": "file:../../com.unity.ml-agents", |
|||
"depth": 0, |
|||
"source": "local", |
|||
"dependencies": { |
|||
"com.unity.barracuda": "1.2.1-preview", |
|||
"com.unity.modules.imageconversion": "1.0.0", |
|||
"com.unity.modules.jsonserialize": "1.0.0", |
|||
"com.unity.modules.physics": "1.0.0", |
|||
"com.unity.modules.physics2d": "1.0.0", |
|||
"com.unity.modules.unityanalytics": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.ml-agents.extensions": { |
|||
"version": "file:../../com.unity.ml-agents.extensions", |
|||
"depth": 0, |
|||
"source": "local", |
|||
"dependencies": { |
|||
"com.unity.ml-agents": "1.7.2-preview" |
|||
} |
|||
}, |
|||
"com.unity.multiplayer-hlapi": { |
|||
"version": "1.0.6", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": { |
|||
"nuget.mono-cecil": "0.1.6-preview" |
|||
}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.purchasing": { |
|||
"version": "2.0.6", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": {}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.test-framework": { |
|||
"version": "1.1.14", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": { |
|||
"com.unity.ext.nunit": "1.0.0", |
|||
"com.unity.modules.imgui": "1.0.0", |
|||
"com.unity.modules.jsonserialize": "1.0.0" |
|||
}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.textmeshpro": { |
|||
"version": "2.0.1", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": { |
|||
"com.unity.ugui": "1.0.0" |
|||
}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.timeline": { |
|||
"version": "1.2.6", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": {}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.ugui": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.ui": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.xr.legacyinputhelpers": { |
|||
"version": "2.1.4", |
|||
"depth": 0, |
|||
"source": "registry", |
|||
"dependencies": {}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"nuget.mono-cecil": { |
|||
"version": "0.1.6-preview", |
|||
"depth": 1, |
|||
"source": "registry", |
|||
"dependencies": {}, |
|||
"url": "https://packages.unity.com" |
|||
}, |
|||
"com.unity.modules.ai": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.androidjni": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.animation": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.assetbundle": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.audio": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.cloth": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.physics": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.director": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.audio": "1.0.0", |
|||
"com.unity.modules.animation": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.imageconversion": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.imgui": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.jsonserialize": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.particlesystem": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.physics": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.physics2d": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.screencapture": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.imageconversion": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.subsystems": { |
|||
"version": "1.0.0", |
|||
"depth": 1, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.jsonserialize": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.terrain": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.terrainphysics": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.physics": "1.0.0", |
|||
"com.unity.modules.terrain": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.tilemap": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.physics2d": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.ui": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.uielements": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.imgui": "1.0.0", |
|||
"com.unity.modules.jsonserialize": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.umbra": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.unityanalytics": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.unitywebrequest": "1.0.0", |
|||
"com.unity.modules.jsonserialize": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.unitywebrequest": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.unitywebrequestassetbundle": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.assetbundle": "1.0.0", |
|||
"com.unity.modules.unitywebrequest": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.unitywebrequestaudio": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.unitywebrequest": "1.0.0", |
|||
"com.unity.modules.audio": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.unitywebrequesttexture": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.unitywebrequest": "1.0.0", |
|||
"com.unity.modules.imageconversion": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.unitywebrequestwww": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.unitywebrequest": "1.0.0", |
|||
"com.unity.modules.unitywebrequestassetbundle": "1.0.0", |
|||
"com.unity.modules.unitywebrequestaudio": "1.0.0", |
|||
"com.unity.modules.audio": "1.0.0", |
|||
"com.unity.modules.assetbundle": "1.0.0", |
|||
"com.unity.modules.imageconversion": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.vehicles": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.physics": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.video": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.audio": "1.0.0", |
|||
"com.unity.modules.ui": "1.0.0", |
|||
"com.unity.modules.unitywebrequest": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.vr": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.jsonserialize": "1.0.0", |
|||
"com.unity.modules.physics": "1.0.0", |
|||
"com.unity.modules.xr": "1.0.0" |
|||
} |
|||
}, |
|||
"com.unity.modules.wind": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": {} |
|||
}, |
|||
"com.unity.modules.xr": { |
|||
"version": "1.0.0", |
|||
"depth": 0, |
|||
"source": "builtin", |
|||
"dependencies": { |
|||
"com.unity.modules.physics": "1.0.0", |
|||
"com.unity.modules.jsonserialize": "1.0.0", |
|||
"com.unity.modules.subsystems": "1.0.0" |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
{ |
|||
"m_SettingKeys": [ |
|||
"VR Device Disabled", |
|||
"VR Device User Alert" |
|||
], |
|||
"m_SettingValues": [ |
|||
"False", |
|||
"False" |
|||
] |
|||
} |
|
|||
|