} ) ;
}
void UpdateActivenessOfUiElements ( )
bool SerializedObjectHasValidLabelingScheme ( SerializedObject serObj )
{
var schemeName = serObj . FindProperty ( nameof ( Labeling . autoLabelingSchemeType ) ) . stringValue ;
return IsValidLabelingSchemeName ( schemeName ) ;
}
bool IsValidLabelingSchemeName ( string schemeName )
{
return schemeName ! = string . Empty & &
m_LabelingSchemes . FindAll ( scheme = > scheme . GetType ( ) . Name = = schemeName ) . Count > 0 ;
}
void UpdateUiAspects ( )
if ( serializedObject . targetObjects . Length > 1 )
if ( ! m_AutoLabelingToggle . value | | serializedObject . targetObjects . Length > 1 | |
! SerializedObjectHasValidLabelingScheme ( new SerializedObject ( serializedObject . targetObjects [ 0 ] ) ) )
{
m_CurrentAutoLabel . style . display = DisplayStyle . None ;
}
else
{
m_CurrentAutoLabel . style . display = DisplayStyle . Flex ;
}
if ( serializedObject . targetObjects . Length = = 1 )
{
m_AutoLabelingToggle . text = "Use Automatic Labeling" ;
}
else
m_CurrentAutoLabel . style . display = DisplayStyle . None ;
m_AutoLabelingToggle . text = "Use Automatic Labeling for All Selected Items" ;
}
}
void UpdateCurrentAutoLabelValue ( SerializedObject serObj )
{
var array = serObj . FindProperty ( nameof ( Labeling . labels ) ) ;
if ( array . arraySize > 0 )
{
m_CurrentAutoLabel . text = array . GetArrayElementAtIndex ( 0 ) . stringValue ;
// if (m_LabelingSchemesPopup.index == 0)
// {
// m_CurrentAutoLabel.style.display = DisplayStyle.None;
//
// }
}
void InitializeLabelingSchemes ( VisualElement parent )
void AutoLabelToggleChanged ( )
{
UpdateActivenessOfUiElemen ts ( ) ;
UpdateUiAspec ts ( ) ;
if ( serializedObject . targetObjects . Length = = 1 )
{
SyncAutoLabelWithSchemeSingleTarget ( true ) ;
}
// if (serializedObject.targetObjects.Length == 1)
// {
// SyncAutoLabelWithSchemeSingleTarget(true);
// }
}
else
{
serObj . FindProperty ( nameof ( Labeling . useAutoLabeling ) ) . boolValue = false ;
var schemeName = serObj . FindProperty ( nameof ( Labeling . autoLabelingSchemeType ) ) . stringValue ;
if ( schemeName ! = String . Empty )
if ( SerializedObjectHasValidLabelingScheme ( serObj ) )
serObj . FindProperty ( nameof ( Labeling . autoLabelingSchemeType ) ) . stringValue = string . Empty ;
m_LabelingSchemesPopup . index = 0 ;
UpdateActivenessOfUiElements ( ) ;
if ( m_LabelingSchemesPopup . index = = 0 )
{
return ;
string topAssetAutoLabel = String . Empty ;
foreach ( var targetObj in serializedObject . targetObjects )
{
BackupManualLabels ( serObj ) ;
var serLabelsArray = serObj . FindProperty ( nameof ( Labeling . labels ) ) ;
serLabelsArray . ClearArray ( ) ;
serLabelsArray . InsertArrayElementAtIndex ( 0 ) ;
{
topAssetAutoLabel = label ;
UpdateCurrentAutoLabelValue ( serObj ) ;
m_CurrentAutoLabel . text = topAssetAutoLabel ;
}
void AssignAutomaticLabelToSerializedObject ( SerializedObject serObj , string labelingSchemeName )
{
var labelingScheme = m_LabelingSchemes . Find ( scheme = > scheme . GetType ( ) . Name = = labelingSchemeName ) ;
AssignAutomaticLabelToSerializedObject ( serObj , labelingScheme ) ;
UpdateUiAspects ( ) ;
RefreshManualLabelingData ( ) ;
}
void AssignAutomaticLabelToSerializedObject ( SerializedObject serObj , AssetLabelingScheme labelingScheme )
BackupManualLabels ( serObj ) ;
serLabelsArray . ClearArray ( ) ;
serLabelsArray . InsertArrayElementAtIndex ( 0 ) ;
serLabelsArray . GetArrayElementAtIndex ( 0 ) . stringValue = label ;
void BackupManualLabels ( SerializedObject serObj )
{
// var serLabelsArray = serObj.FindProperty(nameof(Labeling.labels));
// var backupLabelsArray = serObj.FindProperty(nameof(Labeling.manualLabelsBackup));
// backupLabelsArray.ClearArray();
// for (int i = 0; i < serLabelsArray.arraySize; i++)
// {
// backupLabelsArray.InsertArrayElementAtIndex(i);
// backupLabelsArray.GetArrayElementAtIndex(i).stringValue =
// serLabelsArray.GetArrayElementAtIndex(i).stringValue;
// }
}
void RetrieveFromManualLabelsBackupArray ( SerializedObject serObj )
{
// var serLabelsArray = serObj.FindProperty(nameof(Labeling.labels));
// var backupLabelsArray = serObj.FindProperty(nameof(Labeling.manualLabelsBackup));
// serLabelsArray.ClearArray();
// for (int i = 0; i < backupLabelsArray.arraySize; i++)
// {
// serLabelsArray.InsertArrayElementAtIndex(i);
// serLabelsArray.GetArrayElementAtIndex(i).stringValue =
// backupLabelsArray.GetArrayElementAtIndex(i).stringValue;
// }
}
void SyncAutoLabelWithSchemeSingleTarget ( bool enableAutoLabeling = false )
{
var serObj = new SerializedObject ( serializedObject . targetObjects [ 0 ] ) ;
var currentLabelingSchemeName = serObj . FindProperty ( nameof ( Labeling . autoLabelingSchemeType ) ) . stringValue ;
if ( currentLabelingSchemeName ! = String . Empty )
{
if ( enableAutoLabeling )
{
//the useAutoLabeling flag is only turned on for an asset if a valid scheme for auto labeling has also been chosen, that is why it is deferred to here instead of immediately on toggle click
serObj . FindProperty ( nameof ( Labeling . useAutoLabeling ) ) . boolValue = true ;
}
AssignAutomaticLabelToSerializedObject ( serObj , currentLabelingSchemeName ) ;
var labelsArray = serObj . FindProperty ( nameof ( Labeling . labels ) ) ;
if ( labelsArray . arraySize > 0 )
{
var autoLabel = labelsArray . GetArrayElementAtIndex ( 0 ) . stringValue ;
m_CurrentAutoLabel . text = autoLabel ;
}
m_LabelingSchemesPopup . index =
m_LabelingSchemes . FindIndex ( scheme = > scheme . GetType ( ) . Name . ToString ( ) = = currentLabelingSchemeName ) + 1 ;
}
else
{
}
}
m_AutoLabelingToggle . text = "Use Automatic Labeling" ;
m_CurrentAutoLabel . style . display = DisplayStyle . Flex ;
SyncAutoLabelWithSchemeSingleTarget ( ) ;
var currentLabelingSchemeName = serObj . FindProperty ( nameof ( Labeling . autoLabelingSchemeType ) ) . stringValue ;
if ( IsValidLabelingSchemeName ( currentLabelingSchemeName ) )
{
m_LabelingSchemesPopup . index =
m_LabelingSchemes . FindIndex ( scheme = > scheme . GetType ( ) . Name . ToString ( ) = = currentLabelingSchemeName ) + 1 ;
}
UpdateCurrentAutoLabelValue ( serObj ) ;
m_AutoLabelingToggle . text = "Use Automatic Labeling for All Selected Items" ;
m_CurrentAutoLabel . style . display = DisplayStyle . None ;
foreach ( var targetObj in serializedObject . targetObjects )
{
allAssetsUseSameLabelingScheme = false ;
}
}
if ( targetObj = = serializedObject . targetObjects [ 0 ] )
{
var labelsArray = serObj . FindProperty ( nameof ( Labeling . labels ) ) ;
if ( labelsArray . arraySize > 0 )
{
var autoLabelOfTopSelectedItem = labelsArray . GetArrayElementAtIndex ( 0 ) . stringValue ;
m_CurrentAutoLabel . text = autoLabelOfTopSelectedItem ;
}
}
//}
}
m_AutoLabelingToggle . value = enabledOrNot ;
}
}
if ( ! enabledOrNot )
m_CurrentAutoLabel . text = String . Empty ;
UpdateUiAspects ( ) ;
UpdateActivenessOfUiElements ( ) ;
}
HashSet < string > CreateUnionOfAllLabels ( )
{
string label2 = commonLabels [ j ] ;
if ( S tring. Equals ( label , label2 ) & & ! commonsIndexToLabelsIndex . ContainsKey ( j ) )
if ( s tring. Equals ( label , label2 ) & & ! commonsIndexToLabelsIndex . ContainsKey ( j ) )
{
commonsIndexToLabelsIndex . Add ( j , i ) ;
}