initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,4 @@
{
"displayName": "Custom Analyze Rules",
"description": "This sample shows how to create custom AnalyzeRules for use within the Analyze window. Both rules follow the recommended pattern for adding themselves to the UI. See the Custom Analyze Rules sample project located at github.com/Unity-Technologies/Addressables-Sample"
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6796f792860ff7d4c999d47a82b39295
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,60 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
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 non-fixable rule (meaning it will not fix itself).
/// * When run, it checks that all addresses have a capital C in them. Any that do not are flagged as errors.
/// * A rule like this would be useful if your studio enforced some sort of naming convention on addresses. (though it would probably be best if it could fix itself)
/// </summary>
public class AddressHasC : UnityEditor.AddressableAssets.Build.AnalyzeRules.AnalyzeRule
{
public override bool CanFix
{
get { return false; }
set { }
}
public override string ruleName
{
get { return "Ensure all addresses have a 'C'"; }
}
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("C"))
results.Add(new AnalyzeResult {resultName = group.Name + kDelimiter + e.address, severity = MessageType.Error});
}
}
if (results.Count == 0)
results.Add(new AnalyzeResult {resultName = ruleName + " - No issues found."});
return results;
}
}
[InitializeOnLoad]
class RegisterAddressHasC
{
static RegisterAddressHasC()
{
AnalyzeSystem.RegisterNewRule<AddressHasC>();
}
}
#endif

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7f8f48de5f3e9341b19f0a6844c2e48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,101 @@
#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.AddressableAssets.Build;
using UnityEditor.AddressableAssets.Build.AnalyzeRules;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
public class CheckBundleDupeDependenciesMultiIsolatedGroups : CheckBundleDupeDependencies
{
protected internal struct GroupComparator : IEqualityComparer<List<AddressableAssetGroup>>
{
public bool Equals(List<AddressableAssetGroup> x, List<AddressableAssetGroup> y)
{
foreach (AddressableAssetGroup group in x)
{
if (y.Find(i => i.Guid == group.Guid) == null)
return false;
}
return true;
}
public int GetHashCode(List<AddressableAssetGroup> obj)
{
int hashCode = obj.Count > 0 ? 17 : 0;
foreach (AddressableAssetGroup group in obj)
hashCode = hashCode * 31 + group.Guid.GetHashCode();
return hashCode;
}
}
/// <inheritdoc />
public override string ruleName
{
get { return "Check Duplicate Bundle Dependencies Multi-Isolated Groups"; }
}
/// <summary>
/// Fix duplicates by moving them to new groups.
/// </summary>
/// <param name="settings">The current Addressables settings object</param>
/// <remarks>Duplicates referenced by the same groups will be moved to the same new group.</remarks>
public override void FixIssues(AddressableAssetSettings settings)
{
if (CheckDupeResults == null)
CheckForDuplicateDependencies(settings);
Dictionary<GUID, List<AddressableAssetGroup>> implicitAssetsToGroup = GetImplicitAssetsToGroup(CheckDupeResults);
var groupsToAssets = new Dictionary<List<AddressableAssetGroup>, List<GUID>>(new GroupComparator());
foreach (KeyValuePair<GUID, List<AddressableAssetGroup>> pair in implicitAssetsToGroup)
{
if (!groupsToAssets.TryGetValue(pair.Value, out List<GUID> assets))
{
assets = new List<GUID>();
groupsToAssets.Add(pair.Value, assets);
}
groupsToAssets[pair.Value].Add(pair.Key);
}
foreach (KeyValuePair<List<AddressableAssetGroup>, List<GUID>> pair in groupsToAssets)
{
var group = settings.CreateGroup("Duplicate Asset Isolation", false, false, false, null, typeof(BundledAssetGroupSchema), typeof(ContentUpdateGroupSchema));
group.GetSchema<ContentUpdateGroupSchema>().StaticContent = true;
foreach (GUID asset in pair.Value)
settings.CreateOrMoveEntry(asset.ToString(), group, false, false);
}
settings.SetDirty(AddressableAssetSettings.ModificationEvent.BatchModification, null, true, true);
}
protected Dictionary<GUID, List<AddressableAssetGroup>> GetImplicitAssetsToGroup(IEnumerable<CheckDupeResult> checkDupeResults)
{
var implicitAssetsToGroup = new Dictionary<GUID, List<AddressableAssetGroup>>();
foreach (var checkDupeResult in checkDupeResults)
{
GUID assetGuid = checkDupeResult.DuplicatedGroupGuid;
if (!implicitAssetsToGroup.TryGetValue(assetGuid, out List<AddressableAssetGroup> groups))
{
groups = new List<AddressableAssetGroup>();
implicitAssetsToGroup.Add(assetGuid, groups);
}
implicitAssetsToGroup[assetGuid].Add(checkDupeResult.Group);
}
return implicitAssetsToGroup;
}
}
[InitializeOnLoad]
class RegisterCheckBundleDupeDependenciesMultiIsolatedGroups
{
static RegisterCheckBundleDupeDependenciesMultiIsolatedGroups()
{
AnalyzeSystem.RegisterNewRule<CheckBundleDupeDependenciesMultiIsolatedGroups>();
}
}
#endif

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 088af34993ef24e4bb1eef60a41942d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,82 @@
#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

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5e44340fa5cd66c46ba43dd3bdbdba4f
timeCreated: 1559935065