SHARE
TWEET

AnalyzeDuplicateAddressableNames.cs

a guest Feb 20th, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. using System.Collections.Generic;
  3. using UnityEditor.AddressableAssets.Settings;
  4.  
  5.  
  6. namespace UnityEditor.AddressableAssets.Build.AnalyzeRules
  7. {
  8.  
  9.     [InitializeOnLoad]
  10.     class RegisterAnalyzeDuplicateAddressableNames
  11.     {
  12.         static RegisterAnalyzeDuplicateAddressableNames()
  13.         {
  14.             AnalyzeSystem.RegisterNewRule<AnalyzeDuplicateAddressableNames>();
  15.         }
  16.     }
  17.    
  18.     class AnalyzeDuplicateAddressableNames : AnalyzeRule
  19.     {
  20.        
  21.        
  22.         //--------------------------------
  23.        
  24.         public override bool CanFix
  25.         {
  26.             get { return false;}
  27.         }
  28.  
  29.         public override string ruleName
  30.         {
  31.             get { return "Check Duplicate Addressable Names"; }
  32.         }
  33.        
  34.         //--------------------------------
  35.        
  36.         public override List<AnalyzeResult> RefreshAnalysis(AddressableAssetSettings settings)
  37.         {
  38.             List<AnalyzeResult> results = new List<AnalyzeResult>();
  39.  
  40.             HashSet<string> addressable_names = new HashSet<string>();
  41.            
  42.             for (int i = 0; i < settings.groups.Count; ++i)
  43.             {
  44.                 AddressableAssetGroup group = settings.groups[i];
  45.  
  46.                 foreach (AddressableAssetEntry entry in group.entries)
  47.                 {
  48.                     if (addressable_names.Contains(entry.address))
  49.                     {
  50.                         AnalyzeResult r = new AnalyzeResult();
  51.                         r.resultName = $"{group.name}:{entry.address}";
  52.                         r.severity = MessageType.Warning;
  53.                         results.Add(r);
  54.                     }
  55.                     else
  56.                     {
  57.                         addressable_names.Add(entry.address);
  58.                     }
  59.                    
  60.                 }
  61.             }
  62.  
  63.             return results;
  64.         }
  65.  
  66.         public override void FixIssues(AddressableAssetSettings settings)
  67.         {
  68.             base.FixIssues(settings);
  69.         }
  70.  
  71.         public override void ClearAnalysis()
  72.         {
  73.             base.ClearAnalysis();
  74.         }
  75.        
  76.         //--------------------------------
  77.  
  78.     }
  79.  
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top