浏览代码

Merge pull request #154 from Unity-Technologies/scenario_UI_tooltips_and_info

UI improvements for scenario inspector
/main
GitHub 4 年前
当前提交
ae42bbb4
共有 7 个文件被更改,包括 72 次插入31 次删除
  1. 43
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
  2. 12
      com.unity.perception/Editor/Randomization/Uss/Styles.uss
  3. 16
      com.unity.perception/Editor/Randomization/Uxml/Randomizer/RandomizerList.uxml
  4. 17
      com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml
  5. 3
      com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs
  6. 3
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioConstants.cs
  7. 9
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenarioConstants.cs

43
com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs


using UnityEditor;
using System.Collections;
using System.Linq;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
using UnityEngine.Experimental.Perception.Randomization.VisualElements;

[CustomEditor(typeof(ScenarioBase), true)]
class ScenarioBaseEditor : UnityEditor.Editor
{
bool m_HasConstantsField;
VisualElement m_ConstantsContainer;
VisualElement m_ConstantsListVisualContainer;
SerializedProperty m_ConstantsProperty;
public override VisualElement CreateInspectorGUI()
{

{
m_InspectorPropertiesContainer = m_Root.Q<VisualElement>("inspector-properties");
m_InspectorPropertiesContainer.Clear();
m_ConstantsListVisualContainer = m_Root.Q<VisualElement>("constants-list");
m_ConstantsListVisualContainer.Clear();
m_HasConstantsField = false;
if (iterator.NextVisible(true))
{
do

case "m_Script":
break;
case "constants":
m_ConstantsProperty = iterator.Copy();
break;
break;
case "constants":
m_HasConstantsField = true;
CreateConstantsFieldsWithToolTips(iterator.Copy());
break;
default:
{

void CheckIfConstantsExist()
{
m_ConstantsContainer = m_Root.Q<VisualElement>("constants-container");
if (m_ConstantsProperty == null)
m_ConstantsListVisualContainer = m_Root.Q<VisualElement>("constants-container");
if (!m_HasConstantsField)
m_ConstantsContainer.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
m_ConstantsListVisualContainer.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
}
void CreateConstantsFieldsWithToolTips(SerializedProperty constantsProperty)
{
constantsProperty.NextVisible(true);
do
{
var constantsPropertyField = new PropertyField(constantsProperty.Copy());
constantsPropertyField.Bind(m_SerializedObject);
var originalField = target.GetType().GetField("constants").FieldType.GetField(constantsProperty.name);
var tooltipAttribute = originalField.GetCustomAttributes(true).ToList().Find(att => att.GetType() == typeof(TooltipAttribute));
if (tooltipAttribute != null)
constantsPropertyField.tooltip = (tooltipAttribute as TooltipAttribute)?.tooltip;
m_ConstantsListVisualContainer.Add(constantsPropertyField);
} while (constantsProperty.NextVisible(true));
}
}
}

12
com.unity.perception/Editor/Randomization/Uss/Styles.uss


background-image: resource("Packages/com.unity.perception/Editor/Icons/ChevronRight.png");
}
/* Scenario classes */
.scenario__info-box {
border-width: 1px;

white-space: normal;
margin-top: 4px;
margin-bottom: 4px;
margin: 3px 3px 3px 3px;
}
.scenario__dark-viewport {

}
.scenario__title-label {
-unity-font-style: bold;
margin: 3px 3px 3px 3px;
color: #CACACA;
}
/* Randomizer classes */

min-width: auto;
margin-right: 4px;
}

16
com.unity.perception/Editor/Randomization/Uxml/Randomizer/RandomizerList.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement style="min-height: 132px;">
<VisualElement name="randomizers-container" class="scenario__dark-viewport" style="margin-top: 6px; min-height: 100px;"/>
<VisualElement style="flex-direction: row; align-items: center; justify-content: center; margin-top: 4px;">
<Button name="add-randomizer-button" text="Add Randomizer"/>
<Button name="expand-all" text="Expand All"/>
<Button name="collapse-all" text="Collapse All"/>
<VisualElement class="scenario__dark-viewport">
<TextElement text="Randomizers" class="scenario__title-label"/>
<TextElement
class="scenario__info-box"
text="Randomizers are executed in the order below. You can change the order by dragging Randomizers up or down using the handle bar to their left."/>
<VisualElement name="randomizers-container" style="margin-top: 3px; min-height: 100px;"/>
<VisualElement style="flex-direction: row; align-items: center; justify-content: center; margin-top: 2px;">
<Button name="add-randomizer-button" text="Add Randomizer"/>
<Button name="expand-all" text="Expand All"/>
<Button name="collapse-all" text="Collapse All"/>
</VisualElement>
</VisualElement>
</VisualElement>
</UXML>

17
com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml


<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
<VisualElement>
<Style src="../Uss/Styles.uss"/>
<TextElement
class="scenario__info-box"
text="Scenarios control the execution flow of your simulation by applying randomization parameters. Make sure to always have only one scenario active within your scene."/>
<VisualElement class="scenario__dark-viewport" style="padding-left: 16px">
<Toggle label="Quit On Complete" tooltip="Quit the application when the scenario completes" binding-path="quitOnComplete"/>
<VisualElement class="scenario__dark-viewport" >
<TextElement text="Scenario Properties" class="scenario__title-label"/>
<TextElement
class="scenario__info-box"
text="Scenarios control the execution flow of your simulation by applying randomization parameters. Make sure to always have only one scenario active within your scene."/>
<Toggle label="Quit On Complete" tooltip="Quit the application when the scenario completes" binding-path="quitOnComplete" style="margin-top:5px"/>
<editor:PropertyField
binding-path="constants"
tooltip="A list of parameters for this scenario that will be JSON serialized."/>
<Foldout style="padding-left: 16px" text="Constants" name="constants-list" tooltip="A list of parameters for this scenario that will be JSON serialized in the configuration file."/>
<editor:PropertyField name="configuration-file-name" label="Constants File Name" binding-path="serializedConstantsFileName"/>
<VisualElement style="flex-direction: row;">
<Button name="serialize" text="Serialize To Config File" style="flex-grow: 1;"

</VisualElement>
</VisualElement>
</VisualElement>
<VisualElement name="randomizer-list-placeholder"/>
<VisualElement name="randomizer-list-placeholder" style = "margin-top: 10px"/>
</VisualElement>
</UXML>

3
com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs


public class Constants : UnitySimulationScenarioConstants
{
/// <summary>
/// The number of frames to generate per iteration
/// The number of frames to render per iteration.
[Tooltip("The number of frames to render per iteration.")]
public int framesPerIteration = 1;
}

3
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioConstants.cs


public class ScenarioConstants
{
/// <summary>
/// The starting value initializing all random values sequences generated through Samplers, Parameters, and
/// The starting value initializing all random value sequences generated through Samplers, Parameters, and
[Tooltip("The starting value initializing all random value sequences generated through Samplers, Parameters, and Randomizers attached to a Scenario")]
public uint randomSeed = SamplerUtility.largePrime;
}
}

9
com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenarioConstants.cs


public class UnitySimulationScenarioConstants : ScenarioConstants
{
/// <summary>
/// The total number of iterations to run a scenario for
/// The total number of iterations to run a scenario for. At the start of each iteration, the timings for all Perception Cameras will be reset.
[Tooltip("The total number of iterations to run a scenario for. At the start of each iteration, the timings for all Perception Cameras will be reset.")]
/// The number of Unity Simulation instances assigned to executed this scenario
/// The number of Unity Simulation instances assigned to execute this scenario. The total number of iterations (N) will be divided by the number of instances (M), so each instance will run for N/M iterations.
[Tooltip("The number of Unity Simulation instances assigned to execute this scenario. The total number of iterations (N) will be divided by the number of instances (M), so each instance will run for N/M iterations.")]
/// The Unity Simulation instance index of the currently executing worker
/// The Unity Simulation instance index of the currently executing worker.
[Tooltip("The Unity Simulation instance index of the currently executing worker.")]
public int instanceIndex;
}
}
正在加载...
取消
保存