浏览代码

Merge pull request #59 from Unity-Technologies/categorical-parameter-fixes

Categorical parameter fixes
/main
GitHub 4 年前
当前提交
4d2ec14e
共有 2 个文件被更改,包括 48 次插入27 次删除
  1. 69
      com.unity.perception/Editor/Randomization/ParameterElement.cs
  2. 6
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTarget.cs

69
com.unity.perception/Editor/Randomization/ParameterElement.cs


VisualElement m_TargetContainer;
ToolbarMenu m_TargetPropertyMenu;
SerializedProperty m_SerializedProperty;
SerializedProperty m_TargetGameObjectProperty;
SerializedProperty m_Target;
SerializedProperty m_TargetGameObject;
SerializedProperty m_ApplicationFrequency;
const string k_CollapsedParameterClass = "collapsed-parameter";

m_TargetContainer = this.Q<VisualElement>("target-container");
m_TargetPropertyMenu = this.Q<ToolbarMenu>("property-select-menu");
m_TargetGameObjectProperty = m_SerializedProperty.FindPropertyRelative("target.gameObject");
m_Target = m_SerializedProperty.FindPropertyRelative("target");
m_TargetGameObject = m_Target.FindPropertyRelative("gameObject");
frequencyField.BindProperty(m_SerializedProperty.FindPropertyRelative("target.applicationFrequency"));
frequencyField.Init(ParameterApplicationFrequency.OnIterationSetup);
m_ApplicationFrequency = m_Target.FindPropertyRelative("applicationFrequency");
frequencyField.BindProperty(m_ApplicationFrequency);
targetField.value = m_TargetGameObjectProperty.objectReferenceValue;
targetField.value = m_TargetGameObject.objectReferenceValue;
m_TargetGameObjectProperty.objectReferenceValue = (GameObject)evt.newValue;
var appFreqEnumIndex = m_ApplicationFrequency.intValue;
m_TargetGameObject.objectReferenceValue = (GameObject)evt.newValue;
m_ApplicationFrequency.intValue = appFreqEnumIndex;
m_SerializedProperty.serializedObject.ApplyModifiedProperties();
ToggleTargetContainer();
FillPropertySelectMenu();

void ToggleTargetContainer()
{
m_TargetContainer.style.display = m_TargetGameObjectProperty.objectReferenceValue == null
m_TargetContainer.style.display = m_TargetGameObject.objectReferenceValue == null
? new StyleEnum<DisplayStyle>(DisplayStyle.None)
: new StyleEnum<DisplayStyle>(DisplayStyle.Flex);
}

m_SerializedProperty.FindPropertyRelative("target.component").objectReferenceValue = null;
m_SerializedProperty.FindPropertyRelative("target.propertyName").stringValue = string.Empty;
m_Target.FindPropertyRelative("component").objectReferenceValue = null;
m_Target.FindPropertyRelative("propertyName").stringValue = string.Empty;
m_SerializedProperty.FindPropertyRelative("target.gameObject").objectReferenceValue = newTarget.gameObject;
m_SerializedProperty.FindPropertyRelative("target.component").objectReferenceValue = newTarget.component;
m_SerializedProperty.FindPropertyRelative("target.propertyName").stringValue = newTarget.propertyName;
m_SerializedProperty.FindPropertyRelative("target.fieldOrProperty").enumValueIndex = (int)newTarget.fieldOrProperty;
m_TargetGameObject.objectReferenceValue = newTarget.gameObject;
m_Target.FindPropertyRelative("component").objectReferenceValue = newTarget.component;
m_Target.FindPropertyRelative("propertyName").stringValue = newTarget.propertyName;
m_Target.FindPropertyRelative("fieldOrProperty").intValue = (int)newTarget.fieldOrProperty;
m_SerializedProperty.serializedObject.ApplyModifiedProperties();
m_TargetPropertyMenu.text = TargetPropertyDisplayText(parameter.target);
}

return;
m_TargetPropertyMenu.menu.MenuItems().Clear();
m_TargetPropertyMenu.text = parameter.target.propertyName == string.Empty
? "Select a property"
: TargetPropertyDisplayText(parameter.target);
foreach (var option in options)
if (options.Count == 0)
m_TargetPropertyMenu.menu.AppendAction(
TargetPropertyDisplayText(option),
a => { SetTarget(option); });
m_TargetPropertyMenu.text = "No compatible properties";
m_TargetPropertyMenu.SetEnabled(false);
}
else
{
m_TargetPropertyMenu.SetEnabled(true);
foreach (var option in options)
{
m_TargetPropertyMenu.menu.AppendAction(
TargetPropertyDisplayText(option),
a => { SetTarget(option); });
}
m_TargetPropertyMenu.text = parameter.target.propertyName == string.Empty
? "Select a property"
: TargetPropertyDisplayText(parameter.target);
}
}

removeButton.clicked += () =>
{
probabilitiesProperty.DeleteArrayElementAtIndex(i);
// First delete sets option to null, second delete removes option
var numOptions = optionsProperty.arraySize;
if (numOptions == optionsProperty.arraySize)
optionsProperty.DeleteArrayElementAtIndex(i);
m_SerializedProperty.serializedObject.ApplyModifiedProperties();
listView.itemsSource = categoricalParameter.probabilities;
listView.Refresh();

else
listView.RemoveFromClassList("uniform-probability");
}
uniformToggle.RegisterCallback<ChangeEvent<bool>>(evt =>
{
ToggleProbabilityFields(evt.newValue);
});
if (Application.isPlaying)
uniformToggle.SetEnabled(false);
else
uniformToggle.RegisterCallback<ChangeEvent<bool>>(evt => ToggleProbabilityFields(evt.newValue));
var seedField = template.Q<IntegerField>("seed");
seedField.BindProperty(m_SerializedProperty.FindPropertyRelative("m_Sampler.<baseSeed>k__BackingField"));

6
com.unity.perception/Runtime/Randomization/Parameters/ParameterTarget.cs


{
[SerializeField] internal GameObject gameObject;
[SerializeField] internal Component component;
[SerializeField] internal string propertyName = "";
[SerializeField] internal FieldOrProperty fieldOrProperty;
[SerializeField] internal ParameterApplicationFrequency applicationFrequency;
[SerializeField] internal string propertyName = string.Empty;
[SerializeField] internal FieldOrProperty fieldOrProperty = FieldOrProperty.Field;
[SerializeField] internal ParameterApplicationFrequency applicationFrequency = ParameterApplicationFrequency.OnIterationSetup;
/// <summary>
/// Assigns a new target

正在加载...
取消
保存