浏览代码

add tags, update controllers. working i think

/hh-develop-pushblockcollab
HH 4 年前
当前提交
af5e2e71
共有 6 个文件被更改,包括 194 次插入114 次删除
  1. 189
      Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockCollab.unity
  2. 16
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockEnvController.cs
  3. 30
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/CollisionCallbacks.cs
  4. 2
      Project/ProjectSettings/TagManager.asset
  5. 60
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/GoalDetectTrigger.cs
  6. 11
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/GoalDetectTrigger.cs.meta

189
Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockCollab.unity


m_EditorClassIdentifier:
m_SensorName: OffsetRayPerceptionSensor
m_DetectableTags:
- block
- wall
- wall
- blockLarge
- blockSmall
m_RaysPerDirection: 3
m_MaxRayDegrees: 90
m_SphereCastRadius: 0.5

m_EditorClassIdentifier:
m_SensorName: RayPerceptionSensor
m_DetectableTags:
- block
- wall
- wall
- blockLarge
- blockSmall
m_RaysPerDirection: 3
m_MaxRayDegrees: 90
m_SphereCastRadius: 0.5

- component: {fileID: 1102546559}
- component: {fileID: 1102546558}
- component: {fileID: 1102546557}
- component: {fileID: 1102546561}
- component: {fileID: 1102546556}
m_Name: Block_50
m_TagString: block
m_Name: Block_Small
m_TagString: blockSmall
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

m_Father: {fileID: 4006991767121726}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1102546556
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1102546554}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9dcea692df32b46b4a884cfcc150aef7, type: 3}
m_Name:
m_EditorClassIdentifier:
tagToDetect: goal
GoalValue: 2
onTriggerEnterEvent:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1125451440611343}
m_MethodName: ScoredAGoal
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
onTriggerStayEvent:
m_PersistentCalls:
m_Calls: []
onTriggerExitEvent:
m_PersistentCalls:
m_Calls: []
--- !u!54 &1102546557
Rigidbody:
m_ObjectHideFlags: 0

m_GameObject: {fileID: 1102546554}
serializedVersion: 2
m_Mass: 50
m_Mass: 25
m_Drag: 0.5
m_AngularDrag: 0.05
m_UseGravity: 1

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1102546554}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &1102546561
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1102546554}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3c8f113a8b8d94967b1b1782c549be81, type: 3}
m_Name:
m_EditorClassIdentifier:
tagToDetect: block
spawnRadius: 0
respawnIfTouched: 0
respawnIfFallsOffPlatform: 1
fallDistance: 5
onTriggerEnterEvent:
m_PersistentCalls:
m_Calls: []
onTriggerStayEvent:
m_PersistentCalls:
m_Calls: []
onTriggerExitEvent:
m_PersistentCalls:
m_Calls: []
onCollisionEnterEvent:
m_PersistentCalls:
m_Calls: []
onCollisionStayEvent:
m_PersistentCalls:
m_Calls: []
onCollisionExitEvent:
m_PersistentCalls:
m_Calls: []
--- !u!1001 &1132899702
PrefabInstance:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: ec51f47c5ed0478080c449c74fd9c154, type: 3}
m_Name:
m_EditorClassIdentifier:
gravityMultiplier: 2.5
gravityMultiplier: 1.5
fixedDeltaTime: 0.02
maximumDeltaTime: 0.33333334
solverIterations: 6

- component: {fileID: 1611021063}
- component: {fileID: 1611021062}
m_Layer: 0
m_Name: AgentCube_Blue
m_Name: AgentCube_Purple
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: c9fa44c2c3f8ce74ca39a3355ea42631, type: 2}
- {fileID: 2100000, guid: b0da1813c36914e678ba57f2790424e1, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0

m_Script: {fileID: 11500000, guid: 4bb2bb36bb51d452ab58d30a868dfab3, type: 3}
m_Name:
m_EditorClassIdentifier:
SmallBlockScoreValue: 2
BigBlockScoreValue: 3
areaBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}

- component: {fileID: 33257577519850892}
- component: {fileID: 23824899963671282}
- component: {fileID: 65797107524335970}
- component: {fileID: 1441514604925937}
m_Layer: 0
m_Name: Goal
m_TagString: goal

m_IsActive: 1
--- !u!114 &1441514604925937
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1441514604925936}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 506de7b261f374159a5cdfdb0ff48c0c, type: 3}
m_Name:
m_EditorClassIdentifier:
tagToDetect: block
onTriggerEnterEvent:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1125451440611343}
m_MethodName: ScoredAGoal
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
onTriggerStayEvent:
m_PersistentCalls:
m_Calls: []
onTriggerExitEvent:
m_PersistentCalls:
m_Calls: []
onCollisionEnterEvent:
m_PersistentCalls:
m_Calls: []
onCollisionStayEvent:
m_PersistentCalls:
m_Calls: []
onCollisionExitEvent:
m_PersistentCalls:
m_Calls: []
--- !u!1 &1461266933788148
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 65500236550660044}
- component: {fileID: 23965302191626844}
- component: {fileID: 54485095312058970}
- component: {fileID: 1831339105991535}
m_Name: Block_100
m_TagString: block
m_Name: Block_Large
m_TagString: blockLarge
--- !u!114 &1831339105991535
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1831339105991534}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9dcea692df32b46b4a884cfcc150aef7, type: 3}
m_Name:
m_EditorClassIdentifier:
tagToDetect: goal
GoalValue: 3
onTriggerEnterEvent:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1125451440611343}
m_MethodName: ScoredAGoal
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
onTriggerStayEvent:
m_PersistentCalls:
m_Calls: []
onTriggerExitEvent:
m_PersistentCalls:
m_Calls: []
--- !u!1 &1948184009346040
GameObject:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1831339105991534}
serializedVersion: 2
m_Mass: 100
m_Mass: 50
m_Drag: 0.5
m_AngularDrag: 0.05
m_UseGravity: 1

m_EditorClassIdentifier:
m_SensorName: OffsetRayPerceptionSensor
m_DetectableTags:
- block
- wall
- wall
- blockLarge
- blockSmall
m_RaysPerDirection: 3
m_MaxRayDegrees: 90
m_SphereCastRadius: 0.5

m_EditorClassIdentifier:
m_SensorName: RayPerceptionSensor
m_DetectableTags:
- block
- wall
- wall
- blockLarge
- blockSmall
m_RaysPerDirection: 3
m_MaxRayDegrees: 90
m_SphereCastRadius: 0.5

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


public Rigidbody Rb;
}
public float SmallBlockScoreValue = 2;
public float BigBlockScoreValue = 3;
/// <summary>
/// The area bounds.
/// </summary>

void Start()
{
m_NumberOfRemainingBlocks = BlocksList.Count;
// Get the ground's bounds
areaBounds = ground.GetComponent<Collider>().bounds;

/// <summary>
/// Called when the agent moves the block into the goal.
/// </summary>
public void ScoredAGoal(Collider col)
public void ScoredAGoal(Collider col, float score)
print(col.name);
col.gameObject.SetActive(false);
//Give Agent Rewards
foreach (var item in AgentsList)
{

void ResetScene()
{
//Random platform rot
area.transform.rotation = GetRandomRot();
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)

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;
}
}

30
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/CollisionCallbacks.cs


}
}
// private void OnTriggerStay(Collider col)
// {
// if (col.CompareTag(tagToDetect))
// {
// onTriggerStayEvent.Invoke(col);
// }
// }
//
// private void OnTriggerExit(Collider col)
// {
// if (col.CompareTag(tagToDetect))
// {
// onTriggerExitEvent.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);
}
}
}
}

2
Project/ProjectSettings/TagManager.asset


- symbol_O_Goal
- purpleAgent
- purpleGoal
- blockLarge
- blockSmall
layers:
- Default
- TransparentFX

60
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/GoalDetectTrigger.cs


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()
{
}
}

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


fileFormatVersion: 2
guid: 9dcea692df32b46b4a884cfcc150aef7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存