using System; using System.Collections.Generic; using UnityEditor.AddressableAssets.Settings; using UnityEngine; namespace UnityEditor.AddressableAssets.Build.AnalyzeRules { /// /// Base class for creating rules to analyze Addressables data. Use AnalyzeWindow.RegisterNewRule<T>() to register. /// a rule with the GUI window. /// [Serializable] public class AnalyzeRule { internal struct CustomContextMenu { public string MenuName; public Action MenuAction; public bool MenuEnabled; public bool ToggledOn; public CustomContextMenu(string name, Action action, bool enabled, bool toggledOn) { MenuName = name; MenuAction = action; MenuEnabled = enabled; ToggledOn = toggledOn; } } /// /// True if this rule can fix itself. If child class sets this to true, class must override FixIssues /// public virtual bool CanFix { get; set; } [SerializeField] internal List m_Results = new List(); /// /// Represents a state where no errors were found after analyzing Addressables data. /// [NonSerialized] protected AnalyzeResult noErrors = new AnalyzeResult { resultName = "No issues found" }; /// /// Delimiter character used in analyze rule string names. This is used when a rule result needs to display /// as a tree view hierarchy. A rule result of A:B:C will end up in the tree view with: /// - A /// --- B /// ----- C /// public const char kDelimiter = ':'; /// /// Result data returned by rules. /// [Serializable] public class AnalyzeResult { [SerializeField] string m_ResultName; /// /// Name of result data. This name uses AnalyzeRule.kDelimiter to signify breaks in the tree display. /// public string resultName { get { return m_ResultName; } set { m_ResultName = value; } } [SerializeField] MessageType m_Severity = MessageType.None; /// /// Severity of rule result /// public MessageType severity { get { return m_Severity; } set { m_Severity = value; } } } /// /// Display name for rule /// public virtual string ruleName { get { return GetType().ToString(); } } /// /// This method runs the actual analysis for the rule. /// /// The settings object to analyze /// A list of resulting information (warnings, errors, or info) public virtual List RefreshAnalysis(AddressableAssetSettings settings) { return new List(); } /// /// Fixing method to be run on results of the RefreshAnalysis. If CanFix returns true, this method must be /// overriden. It is recommended that RefreshAnalysis caches any data that will be needed to fix. Fix should /// not rerun RefreshAnalysis before fixing. /// /// The settings object to analyze public virtual void FixIssues(AddressableAssetSettings settings) {} /// /// Clears out the analysis results. When overriding, use to clear rule-specific data as well. /// public virtual void ClearAnalysis() { m_Results.Clear(); } internal virtual IList GetCustomContextMenuItems() { return new List(); } } }