Firstborn/Library/PackageCache/com.unity.addressables@1.19.19/Samples~/CustomAnalyzeRules/Editor/PathAddressIsPath.cs
Schaken-Mods 7502018d20 Adding Mod Support
There is an asset in the store I grabbed. the coding is WAY above my head, I got about half of it and integrated and adapted what I can to it. im going as far as I can with it and ill come back in a few month when I understand t better.
2023-05-13 22:01:48 -05:00

81 lines
2.6 KiB
C#

#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.AddressableAssets.Build;
using UnityEditor.AddressableAssets.GUI;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
using UnityEngine;
/// <summary>
/// * This is a fixable rule. Running fix on it will change addresses to comply with the rule.
/// * When run, it first identifies all addresses that seem to be paths. Of those, it makes sure that the address actually matches the path of the asset.
/// * This would be useful if you primarily left the addresses of your assets as the path (which is the default when marking an asset addressable). If the asset is moved within the project, then the address no longer maps to where it is. This rule could fix that.
/// </summary>
public class PathAddressIsPath : UnityEditor.AddressableAssets.Build.AnalyzeRules.AnalyzeRule
{
public override bool CanFix
{
get { return true;}
set { }
}
public override string ruleName
{
get { return "Addresses that are paths, match path"; }
}
[SerializeField]
List<AddressableAssetEntry> m_MisnamedEntries = new List<AddressableAssetEntry>();
public override List<AnalyzeResult> RefreshAnalysis(AddressableAssetSettings settings)
{
List<AnalyzeResult> results = new List<AnalyzeResult>();
foreach (var group in settings.groups)
{
if (group.HasSchema<PlayerDataGroupSchema>())
continue;
foreach (var e in group.entries)
{
if (e.address.Contains("Assets") && e.address.Contains("/") && e.address != e.AssetPath)
{
m_MisnamedEntries.Add(e);
results.Add(new AnalyzeResult { resultName = group.Name + kDelimiter + e.address, severity = MessageType.Error });
}
}
}
if (results.Count == 0)
results.Add(new AnalyzeResult{resultName = "No issues found."});
return results;
}
public override void FixIssues(AddressableAssetSettings settings)
{
foreach (var e in m_MisnamedEntries)
{
e.address = e.AssetPath;
}
m_MisnamedEntries = new List<AddressableAssetEntry>();
}
public override void ClearAnalysis()
{
m_MisnamedEntries = new List<AddressableAssetEntry>();
}
}
[InitializeOnLoad]
class RegisterPathAddressIsPath
{
static RegisterPathAddressIsPath()
{
AnalyzeSystem.RegisterNewRule<PathAddressIsPath>();
}
}
#endif