listView . style . flexGrow = 1.0f ;
listView . style . height = new StyleLength ( listView . itemHeight * 4 ) ;
var uniformToggle = template . Q < Toggle > ( "uniform" ) ;
VisualElement MakeItem ( )
{
return new CategoricalOptionElement (
// First delete sets option to null, second delete removes option
var numOptions = optionsProperty . arraySize ;
optionsProperty . DeleteArrayElementAtIndex ( i ) ;
{
}
void ResetProbabilities ( )
{
var uniformProbability = probabilitiesProperty . arraySize > 0 ? 1f / probabilitiesProperty . arraySize : 0 ;
for ( var i = 0 ; i < probabilitiesProperty . arraySize ; i + + )
{
probabilitiesProperty . GetArrayElementAtIndex ( i ) . floatValue = uniformProbability ;
}
}
listView . bindItem = BindItem ;
var addOptionButton = template . Q < Button > ( "add-option" ) ;
break ;
}
// New items probability will be 0, unless uniform toggle is true
probabilitiesProperty . GetArrayElementAtIndex ( probabilitiesProperty . arraySize - 1 ) . floatValue = 0 ;
if ( uniformToggle . value )
ResetProbabilities ( ) ;
m_SerializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
listView . itemsSource = categoricalParameter . probabilities ;
listView . Refresh ( ) ;
if ( folderPath = = string . Empty )
return ;
var categories = LoadAssetsFromFolder ( folderPath , categoricalParameter . sampleType ) ;
probabilitiesProperty . arraySize + = categories . Count ;
var optionsIndex = optionsProperty . arraySize ;
var uniformProbability = 1f / categories . Count ;
probabilitiesProperty . arraySize + = categories . Count ;
var optionProperty = optionsProperty . GetArrayElementAtIndex ( i ) ;
var probabilityProperty = probabilitiesProperty . GetArrayElementAtIndex ( i ) ;
var optionProperty = optionsProperty . GetArrayElementAtIndex ( optionsIndex + i ) ;
probabilityProperty . floatValue = uniformProbability ;
probabilitiesProperty . GetArrayElementAtIndex ( i ) . floatValue = 0 ;
if ( uniformToggle . value )
ResetProbabilities ( ) ;
m_SerializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
listView . itemsSource = categoricalParameter . probabilities ;
evt . StopImmediatePropagation ( ) ;
} ) ;
var uniformToggle = template . Q < Toggle > ( "uniform" ) ;
var uniformProperty = m_SerializedProperty . FindPropertyRelative ( "uniform" ) ;
uniformToggle . BindProperty ( uniformProperty ) ;