@@ -559,13 +559,14 @@ private string CreateToken(string[] fieldPrefixes, string[] values) {
559
559
/// <param name="fieldPrefixes">The first item of this list is used as the prefix.
560
560
/// </param>
561
561
/// <param name="values">Set of values to store with the field.</param>
562
+ /// <param name="currentLabels">Labels to search for the suitable prefix.</param>
562
563
/// <param name="preserve">Always preserve these labels.</param>
563
564
private static string [ ] CreateLabels ( string [ ] fieldPrefixes , IEnumerable < string > values ,
564
- bool preserve = false ) {
565
+ HashSet < string > currentLabels , bool preserve = false ) {
565
566
string prefix = fieldPrefixes [ 0 ] ;
566
567
List < string > labels = new List < string > ( ) ;
567
568
foreach ( var value in values ) {
568
- labels . Add ( CreateLabel ( prefix , value , preserve : preserve ) ) ;
569
+ labels . Add ( CreateLabel ( prefix , value , currentLabels , preserve : preserve ) ) ;
569
570
}
570
571
571
572
return labels . ToArray ( ) ;
@@ -582,6 +583,23 @@ public static string CreateLabel(string prefix, string value, bool preserve = fa
582
583
return ( preserve ? LABEL_PREFIX_PRESERVE : LABEL_PREFIX ) + prefix + value ;
583
584
}
584
585
586
+ /// <summary>
587
+ /// Create an asset label keeping the preservation in the supplied set if it already exists.
588
+ /// </summary>
589
+ /// <param name="prefix"> The field prefix to be applied to the label.
590
+ /// </param>
591
+ /// <param name="value">The value to store in the field</param>
592
+ /// <param name="currentLabels">Labels to search for the suitable prefix.</param>
593
+ /// <param name="preserve">Whether the label should be preserved.</param>
594
+ public static string CreateLabel ( string prefix , string value , HashSet < string > currentLabels ,
595
+ bool preserve = false ) {
596
+ var legacyLabel = CreateLabel ( prefix , value , false ) ;
597
+ var preservedLabel = CreateLabel ( prefix , value , true ) ;
598
+ if ( currentLabels . Contains ( legacyLabel ) ) return legacyLabel ;
599
+ if ( currentLabels . Contains ( preservedLabel ) ) return preservedLabel ;
600
+ return preserve ? preservedLabel : legacyLabel ;
601
+ }
602
+
585
603
/// <summary>
586
604
/// Determine whether this file is compatible with the editor.
587
605
/// This is a special case as the editor isn't a "platform" covered
@@ -661,8 +679,8 @@ public void UpdateAssetLabels() {
661
679
return ;
662
680
}
663
681
AssetImporter importer = AssetImporter . GetAtPath ( filename ) ;
664
- var labels = new List < string > ( ) ;
665
- var currentLabels = new List < string > ( ) ;
682
+ var labels = new HashSet < string > ( ) ;
683
+ var currentLabels = new HashSet < string > ( ) ;
666
684
// Strip labels we're currently managing.
667
685
foreach ( string label in AssetDatabase . GetLabels ( importer ) ) {
668
686
currentLabels . Add ( label ) ;
@@ -676,52 +694,56 @@ public void UpdateAssetLabels() {
676
694
labels . Add ( ASSET_LABEL ) ;
677
695
// Add labels for the metadata in this class.
678
696
if ( ! String . IsNullOrEmpty ( versionString ) ) {
679
- labels . Add ( CreateLabel ( TOKEN_VERSION [ 0 ] , versionString ) ) ;
697
+ labels . Add ( CreateLabel ( TOKEN_VERSION [ 0 ] , versionString , currentLabels ) ) ;
680
698
}
681
699
if ( targets != null && targets . Count > 0 ) {
682
- labels . AddRange ( CreateLabels ( TOKEN_TARGETS , targets ) ) ;
700
+ labels . UnionWith ( CreateLabels ( TOKEN_TARGETS , targets , currentLabels ) ) ;
683
701
684
702
if ( ! isHandledByPluginImporter ) {
685
703
labels . Add ( ASSET_LABEL_RENAME_TO_DISABLE ) ;
686
704
}
687
705
}
688
706
if ( dotNetTargets != null && dotNetTargets . Count > 0 ) {
689
- labels . AddRange ( CreateLabels ( TOKEN_DOTNET_TARGETS , dotNetTargets ) ) ;
707
+ labels . UnionWith ( CreateLabels ( TOKEN_DOTNET_TARGETS , dotNetTargets , currentLabels ) ) ;
690
708
}
691
709
if ( ! String . IsNullOrEmpty ( linuxLibraryBasename ) ) {
692
- labels . Add ( CreateLabel ( TOKEN_LINUX_LIBRARY_BASENAME [ 0 ] , linuxLibraryBasename ) ) ;
710
+ labels . Add ( CreateLabel ( TOKEN_LINUX_LIBRARY_BASENAME [ 0 ] , linuxLibraryBasename ,
711
+ currentLabels ) ) ;
693
712
}
694
713
if ( ! String . IsNullOrEmpty ( exportPath ) ) {
695
- labels . Add ( CreateLabel ( TOKEN_EXPORT_PATH [ 0 ] , exportPath , preserve : true ) ) ;
714
+ labels . Add ( CreateLabel ( TOKEN_EXPORT_PATH [ 0 ] , exportPath , currentLabels ,
715
+ preserve : true ) ) ;
696
716
}
697
717
if ( isManifest ) {
698
- labels . Add ( CreateLabel ( TOKEN_MANIFEST [ 0 ] , null ) ) ;
718
+ labels . Add ( CreateLabel ( TOKEN_MANIFEST [ 0 ] , null , currentLabels ) ) ;
699
719
}
700
720
if ( customManifestNames != null && customManifestNames . Count > 0 ) {
701
721
foreach ( var indexAndName in customManifestNames ) {
702
722
int order = indexAndName . Key + CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET ;
703
723
var name = indexAndName . Value ;
704
724
if ( order < CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET ) {
705
725
labels . Add ( CreateLabel ( TOKEN_MANIFEST_NAME [ 0 ] , order . ToString ( ) + name ,
706
- preserve : true ) ) ;
726
+ currentLabels , preserve : true ) ) ;
707
727
} else {
708
- labels . Add ( CreateLabel ( TOKEN_MANIFEST_NAME [ 0 ] , name , preserve : true ) ) ;
728
+ labels . Add ( CreateLabel ( TOKEN_MANIFEST_NAME [ 0 ] , name , currentLabels ,
729
+ preserve : true ) ) ;
709
730
}
710
731
}
711
732
}
712
- var uniqueLabels = new HashSet < string > ( labels ) ;
713
- labels = new List < string > ( uniqueLabels ) ;
714
- if ( ! uniqueLabels . SetEquals ( new HashSet < string > ( currentLabels ) ) ) {
715
- currentLabels . Sort ( ) ;
716
- labels . Sort ( ) ;
733
+ if ( ! labels . SetEquals ( currentLabels ) ) {
734
+ var sortedLabels = new List < string > ( labels ) ;
735
+ var sortedCurrentLabels = new List < string > ( currentLabels ) ;
736
+ sortedCurrentLabels . Sort ( ) ;
737
+ sortedLabels . Sort ( ) ;
738
+ var labelsArray = sortedLabels . ToArray ( ) ;
717
739
Log ( String . Format ( "Changing labels of {0}\n " +
718
740
"from: {1}\n " +
719
- "to: {2}\n " ,
741
+ "to: {2}\n " ,
720
742
filename ,
721
- String . Join ( ", " , currentLabels . ToArray ( ) ) ,
722
- String . Join ( ", " , labels . ToArray ( ) ) ) ,
743
+ String . Join ( ", " , sortedCurrentLabels . ToArray ( ) ) ,
744
+ String . Join ( ", " , labelsArray ) ) ,
723
745
verbose : true ) ;
724
- AssetDatabase . SetLabels ( importer , labels . ToArray ( ) ) ;
746
+ AssetDatabase . SetLabels ( importer , labelsArray ) ;
725
747
}
726
748
}
727
749
0 commit comments