浏览代码

Merge pull request #153 from Unity-Technologies/remove-all-randomizers-bug

Remove all randomizers bug
/main
GitHub 4 年前
当前提交
a851f43c
共有 5 个文件被更改,包括 17 次插入13 次删除
  1. 2
      com.unity.perception/CHANGELOG.md
  2. 12
      com.unity.perception/Editor/Randomization/Uxml/Randomizer/RandomizerList.uxml
  3. 7
      com.unity.perception/Editor/Randomization/VisualElements/Randomizer/AddRandomizerMenu.cs
  4. 7
      com.unity.perception/Editor/Randomization/VisualElements/Randomizer/RandomizerList.cs
  5. 2
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs

2
com.unity.perception/CHANGELOG.md


Randomizer.OnCreate() is no longer called in edit-mode when adding a randomizer to a scenario
Fixed a bug where removing all randomizers from a scenario caused the randomizer container UI element to overflow over the end of Scenario component UI
## [0.6.0-preview.1] - 2020-12-03
### Added

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


<UXML xmlns="UnityEngine.UIElements">
<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 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>
</VisualElement>
</UXML>

7
com.unity.perception/Editor/Randomization/VisualElements/Randomizer/AddRandomizerMenu.cs


{
var rootList = new List<MenuItem>();
m_MenuItemsMap.Add(string.Empty, rootList);
var randomizerTypeSet = new HashSet<Type>();
foreach (var randomizer in m_RandomizerList.scenario.m_Randomizers)
randomizerTypeSet.Add(randomizer.GetType());
if (m_RandomizerList.randomizerTypeSet.Contains(randomizerType))
if (randomizerTypeSet.Contains(randomizerType))
continue;
var menuAttribute = (AddRandomizerMenuAttribute)Attribute.GetCustomAttribute(randomizerType, typeof(AddRandomizerMenuAttribute));
if (menuAttribute != null)

7
com.unity.perception/Editor/Randomization/VisualElements/Randomizer/RandomizerList.cs


{
SerializedProperty m_Property;
VisualElement m_Container;
ToolbarMenu m_AddRandomizerMenu;
public HashSet<Type> randomizerTypeSet = new HashSet<Type>();
ScenarioBase scenario => (ScenarioBase)m_Property.serializedObject.targetObject;
public ScenarioBase scenario => (ScenarioBase)m_Property.serializedObject.targetObject;
VisualElement inspectorContainer
{

m_Container.Clear();
for (var i = 0; i < m_Property.arraySize; i++)
m_Container.Add(new RandomizerElement(m_Property.GetArrayElementAtIndex(i), this));
randomizerTypeSet.Clear();
foreach (var randomizer in scenario.randomizers)
randomizerTypeSet.Add(randomizer.GetType());
}
public void AddRandomizer(Type randomizerType)

2
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


{
if (!randomizerType.IsSubclassOf(typeof(Randomizer)))
throw new ScenarioException(
$"Cannot add non-randomizer type {randomizerType.Name} to randomizer list");
$"Cannot remove non-randomizer type {randomizerType.Name} from randomizer list");
var removed = false;
for (var i = 0; i < m_Randomizers.Count; i++)
{

正在加载...
取消
保存