Skip to content

Develop one to one with component #2753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions UnitySDK/Assets/ML-Agents/Editor/AgentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ This code is meant to modify the behavior of the inspector on Agent Components.
[CanEditMultipleObjects]
public class AgentEditor : Editor
{
private const float k_TimeBetweenModelReloads = 2f;
// Time since the last reload of the model
private float m_TimeSinceModelReload;
// Whether or not the model needs to be reloaded
private bool m_RequireReload;

public override void OnInspectorGUI()
{
var serializedAgent = serializedObject;
Expand All @@ -35,29 +29,6 @@ public override void OnInspectorGUI()
var renderTextures = serializedAgent.FindProperty(
"agentParameters.agentRenderTextures");

// Drawing the Behavior Parameters
var brainParameters = serializedAgent.FindProperty("m_BrainParameters");
brainParameters.isExpanded = EditorGUILayout.Foldout(brainParameters.isExpanded, "Behavior Parameters");
if (brainParameters.isExpanded)
{
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedAgent.FindProperty("m_BehaviorName"));
EditorGUILayout.PropertyField(serializedAgent.FindProperty("m_BrainParameters"), true);
EditorGUILayout.PropertyField(serializedAgent.FindProperty("m_Model"), true);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedAgent.FindProperty("m_InferenceDevice"), true);
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(serializedAgent.FindProperty("m_UseHeuristic"));
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
m_RequireReload = true;
}
DisplayFailedModelChecks();
}
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);


if (cameras.arraySize > 0 && renderTextures.arraySize > 0)
{
Expand Down Expand Up @@ -137,38 +108,5 @@ public override void OnInspectorGUI()
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
base.OnInspectorGUI();
}

/// <summary>
/// Must be called within OnEditorGUI()
/// </summary>
private void DisplayFailedModelChecks()
{
if (m_RequireReload && m_TimeSinceModelReload > k_TimeBetweenModelReloads)
{
m_RequireReload = false;
m_TimeSinceModelReload = 0;
}
// Display all failed checks
D.logEnabled = false;
Model barracudaModel = null;
var model = (NNModel)serializedObject.FindProperty("m_Model").objectReferenceValue;
var brainParameters = ((Agent)target).brainParameters;
if (model != null)
{
barracudaModel = ModelLoader.Load(model.Value);
}
if (brainParameters != null)
{
var failedChecks = InferenceBrain.BarracudaModelParamLoader.CheckModel(
barracudaModel, brainParameters);
foreach (var check in failedChecks)
{
if (check != null)
{
EditorGUILayout.HelpBox(check, MessageType.Warning);
}
}
}
}
}
}
78 changes: 78 additions & 0 deletions UnitySDK/Assets/ML-Agents/Editor/BehaviorParametersEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using UnityEngine;
using UnityEditor;
using Barracuda;

namespace MLAgents
{
/*
This code is meant to modify the behavior of the inspector on Agent Components.
*/
[CustomEditor(typeof(BehaviorParameters))]
[CanEditMultipleObjects]
public class BehaviorParametersEditor : Editor
{
private const float k_TimeBetweenModelReloads = 2f;
// Time since the last reload of the model
private float m_TimeSinceModelReload;
// Whether or not the model needs to be reloaded
private bool m_RequireReload;

public override void OnInspectorGUI()
{
var serializedObject = base.serializedObject;
serializedObject.Update();

// Drawing the Behavior Parameters
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BehaviorName"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BrainParameters"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Model"), true);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_InferenceDevice"), true);
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_UseHeuristic"));
// EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Heuristic"), true);
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
m_RequireReload = true;
}
DisplayFailedModelChecks();
serializedObject.ApplyModifiedProperties();
}

/// <summary>
/// Must be called within OnEditorGUI()
/// </summary>
private void DisplayFailedModelChecks()
{
if (m_RequireReload && m_TimeSinceModelReload > k_TimeBetweenModelReloads)
{
m_RequireReload = false;
m_TimeSinceModelReload = 0;
}
// Display all failed checks
D.logEnabled = false;
Model barracudaModel = null;
var model = (NNModel)serializedObject.FindProperty("m_Model").objectReferenceValue;
var brainParameters = ((BehaviorParameters)target).brainParameters;
if (model != null)
{
barracudaModel = ModelLoader.Load(model.Value);
}
if (brainParameters != null)
{
var failedChecks = InferenceBrain.BarracudaModelParamLoader.CheckModel(
barracudaModel, brainParameters);
foreach (var check in failedChecks)
{
if (check != null)
{
EditorGUILayout.HelpBox(check, MessageType.Warning);
}
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions UnitySDK/Assets/ML-Agents/Examples/3DBall/Prefabs/3DBall.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ GameObject:
m_Component:
- component: {fileID: 4780098186595842}
- component: {fileID: 65010516625723872}
- component: {fileID: 114259948429386406}
- component: {fileID: 114368073295828880}
- component: {fileID: 114715123104194396}
m_Layer: 0
m_Name: Agent
m_TagString: Untagged
Expand Down Expand Up @@ -266,7 +267,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1321468028730240}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 9, y: 0, z: 5}
m_LocalPosition: {x: 0, y: 0, z: 5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4259352808153402}
Expand Down Expand Up @@ -597,15 +598,15 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &114259948429386406
--- !u!114 &114368073295828880
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1424713891854676}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aaba48bf82bee4751aa7b89569e57f73, type: 3}
m_Script: {fileID: 11500000, guid: 5d1c4e0b1822b495aa52bc52839ecb30, type: 3}
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
Expand All @@ -619,10 +620,21 @@ MonoBehaviour:
m_InferenceDevice: 0
m_UseHeuristic: 0
m_BehaviorName: 3DBall
--- !u!114 &114715123104194396
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1424713891854676}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aaba48bf82bee4751aa7b89569e57f73, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
agentCameras: []
agentRenderTextures: []
maxStep: 5000
maxStep: 100
resetOnDone: 1
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ GameObject:
m_Component:
- component: {fileID: 4895942152145390}
- component: {fileID: 65170961617201804}
- component: {fileID: 114284317994838100}
- component: {fileID: 114466000339026140}
m_Layer: 0
m_Name: Agent
Expand Down Expand Up @@ -597,15 +598,15 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &114466000339026140
--- !u!114 &114284317994838100
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1829721031899636}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: edf26e11cf4ed42eaa3ffb7b91bb4676, type: 3}
m_Script: {fileID: 11500000, guid: 5d1c4e0b1822b495aa52bc52839ecb30, type: 3}
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
Expand All @@ -619,6 +620,17 @@ MonoBehaviour:
m_InferenceDevice: 0
m_UseHeuristic: 0
m_BehaviorName: 3DBallHard
--- !u!114 &114466000339026140
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1829721031899636}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: edf26e11cf4ed42eaa3ffb7b91bb4676, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
agentCameras: []
agentRenderTextures: []
Expand Down
Loading