浏览代码

UI code updates

- Changed how UI is created for constants to include tooltips. - - Added info box about Randomizer execution order
/main
Mohsen Kamalzadeh 4 年前
当前提交
e77310cf
共有 7 个文件被更改,包括 62 次插入21 次删除
  1. 37
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
  2. 8
      com.unity.perception/Editor/Randomization/Uss/Styles.uss
  3. 17
      com.unity.perception/Editor/Randomization/Uxml/Randomizer/RandomizerList.uxml
  4. 6
      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

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

SerializedObject m_SerializedObject;
VisualElement m_Root;
VisualElement m_InspectorPropertiesContainer;
VisualElement m_ConstantsContainer;
VisualElement m_ConstantsListVisualContainer;
VisualElement m_RandomizerListPlaceholder;
SerializedProperty m_ConstantsProperty;

m_InspectorPropertiesContainer = m_Root.Q<VisualElement>("inspector-properties");
m_InspectorPropertiesContainer.Clear();
m_ConstantsListVisualContainer = m_Root.Q<VisualElement>("constants-list");
m_ConstantsListVisualContainer.Clear();
var iterator = m_SerializedObject.GetIterator();
var foundProperties = false;
if (iterator.NextVisible(true))

Debug.Log(iterator.name);
case "m_Randomizers":
m_RandomizerListPlaceholder.Add(new RandomizerList(iterator.Copy()));
break;
break;
case "m_Randomizers":
m_RandomizerListPlaceholder.Add(new RandomizerList(iterator.Copy()));
m_ConstantsProperty.NextVisible(true);
do
{
var constantsPropertyField = new PropertyField(m_ConstantsProperty.Copy());
constantsPropertyField.Bind(m_SerializedObject);
var originalField = m_Scenario.genericConstants.GetType().GetField(m_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 (m_ConstantsProperty.NextVisible(true));
break;
default:
{

void CheckIfConstantsExist()
{
m_ConstantsContainer = m_Root.Q<VisualElement>("constants-container");
m_ConstantsListVisualContainer = m_Root.Q<VisualElement>("constants-container");
m_ConstantsContainer.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
m_ConstantsListVisualContainer.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
}
}
}

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


background-image: resource("Packages/com.unity.perception/Editor/Icons/ChevronRight.png");
}
.title-label {
-unity-font-style: bold;
margin-bottom: 5px;
color: #CACACA;
}
/* Scenario classes */
.scenario__info-box {

background-color: #191919;
padding: 2px;
}
/* Randomizer classes */
.randomizer__drag-bar {

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

17
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="title-label" style="margin-left: 3px; margin-top:3px"/>
<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."
style="margin-left: 3px; margin-right: 3px"/>
<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>

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


<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 name="constants-container">
<editor:PropertyField
binding-path="constants"
tooltip="A list of parameters for this scenario that will be JSON serialized."/>
<Foldout 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;
}
}
正在加载...
取消
保存