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,75 @@
using System;
namespace UnityEngine.AddressableAssets.ResourceLocators
{
#if ENABLE_CCD
/// <summary>
/// This is an internal class used as an intermediary data store from editor time to runtime
/// </summary>
[Serializable]
internal class CcdManagedData
{
/// <summary>
/// Denotes what state the config is in.
/// </summary>
public enum ConfigState
{
/// <summary>
/// Config has not been modified.
/// </summary>
None,
/// <summary>
/// Config should use default values according to CCD opinionated workflow.
/// </summary>
Default,
/// <summary>
/// The config has been overriden externally.
/// </summary>
Override
};
/// <summary>
/// Id of the Environment to store
/// </summary>
public string EnvironmentId;
/// <summary>
/// Name of the Environment to store
/// </summary>
public string EnvironmentName;
/// <summary>
/// Id of the Bucket to store
/// </summary>
public string BucketId;
/// <summary>
/// Name of the Badge to store
/// </summary>
public string Badge;
/// <summary>
/// The current state of the config
/// </summary>
public ConfigState State;
/// <summary>
/// Constructor for CcdManagedData
/// </summary>
public CcdManagedData()
{
State = ConfigState.None;
}
/// <summary>
/// Determines if the CcdManagedData has been configured
/// </summary>
/// <returns>True if all fields have been set. False, otherwise.</returns>
public bool IsConfigured()
{
return !string.IsNullOrEmpty(EnvironmentId) && !string.IsNullOrEmpty(BucketId) && !string.IsNullOrEmpty(Badge);
}
}
#endif
}

View file

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

View file

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

View file

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine.AddressableAssets.ResourceLocators;
using UnityEngine.ResourceManagement.ResourceLocations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.ResourceManagement.Util;
using UnityEngine.U2D;
namespace UnityEngine.AddressableAssets
{
internal class DynamicResourceLocator : IResourceLocator
{
AddressablesImpl m_Addressables;
public string LocatorId => nameof(DynamicResourceLocator);
public virtual IEnumerable<object> Keys => new object[0];
private string m_AtlasSpriteProviderId = null;
private string AtlasSpriteProviderId
{
get
{
if (!string.IsNullOrEmpty(m_AtlasSpriteProviderId))
return m_AtlasSpriteProviderId;
var providers = m_Addressables.ResourceManager.ResourceProviders;
foreach (IResourceProvider provider in providers)
{
if (provider is AtlasSpriteProvider)
{
m_AtlasSpriteProviderId = provider.ProviderId;
return m_AtlasSpriteProviderId;
}
}
// if nothing found, fallback to the default name
return typeof(AtlasSpriteProvider).FullName;
}
}
public IEnumerable<IResourceLocation> AllLocations => new IResourceLocation[0];
public DynamicResourceLocator(AddressablesImpl addr)
{
m_Addressables = addr;
}
public bool Locate(object key, Type type, out IList<IResourceLocation> locations)
{
locations = null;
if (ResourceManagerConfig.ExtractKeyAndSubKey(key, out string mainKey, out string subKey))
{
if (!m_Addressables.GetResourceLocations(mainKey, type, out IList<IResourceLocation> locs))
{
if (type == typeof(Sprite))
m_Addressables.GetResourceLocations(mainKey, typeof(SpriteAtlas), out locs);
}
if (locs != null && locs.Count > 0)
{
locations = new List<IResourceLocation>(locs.Count);
foreach (var l in locs)
CreateDynamicLocations(type, locations, key as string, subKey, l);
return true;
}
}
return false;
}
internal void CreateDynamicLocations(Type type, IList<IResourceLocation> locations, string locName, string subKey, IResourceLocation mainLoc)
{
if (type == typeof(Sprite) && mainLoc.ResourceType == typeof(U2D.SpriteAtlas))
{
locations.Add(new ResourceLocationBase(locName, $"{mainLoc.InternalId}[{subKey}]", AtlasSpriteProviderId, type, new IResourceLocation[] {mainLoc}));
}
else
{
if (mainLoc.HasDependencies)
locations.Add(new ResourceLocationBase(locName, $"{mainLoc.InternalId}[{subKey}]", mainLoc.ProviderId, mainLoc.ResourceType, mainLoc.Dependencies.ToArray()));
else
locations.Add(new ResourceLocationBase(locName, $"{mainLoc.InternalId}[{subKey}]", mainLoc.ProviderId, mainLoc.ResourceType));
}
}
}
}

View file

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

View file

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using UnityEngine.ResourceManagement.ResourceLocations;
namespace UnityEngine.AddressableAssets.ResourceLocators
{
/// <summary>
/// Interface used by the Addressables system to find the locations of a given key.
/// </summary>
public interface IResourceLocator
{
/// <summary>
/// The id for this locator.
/// </summary>
string LocatorId { get; }
/// <summary>
/// The keys defined by this locator.
/// </summary>
IEnumerable<object> Keys { get; }
#if ENABLE_BINARY_CATALOG
/// <summary>
/// All locations that are available by this locator.
/// </summary>
IEnumerable<IResourceLocation> AllLocations { get; }
#endif
/// <summary>
/// Retrieve the locations from a specified key.
/// </summary>
/// <param name="key">The key to use.</param>
/// <param name="type">The resource type.</param>
/// <param name="locations">The resulting set of locations for the key.</param>
/// <returns>True if any locations were found with the specified key.</returns>
bool Locate(object key, Type type, out IList<IResourceLocation> locations);
}
}

View file

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

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using UnityEngine.ResourceManagement.ResourceLocations;
using UnityEngine.ResourceManagement.ResourceProviders;
namespace UnityEngine.AddressableAssets.ResourceLocators
{
/// <summary>
/// Simple locator that acts as a passthrough for assets loaded from resources directories.
/// </summary>
public class LegacyResourcesLocator : IResourceLocator
{
/// <summary>
/// The key is converted to a string and used as the internal id of the location added to the locations parameter.
/// </summary>
/// <param name="key">The key of the location. This should be a string with the resources path of the asset.</param>
/// <param name="type">The resource type.</param>
/// <param name="locations">The list of locations. This will have at most one item.</param>
/// <returns>True if the key is a string object and a location was created, false otherwise.</returns>
public bool Locate(object key, Type type, out IList<IResourceLocation> locations)
{
locations = null;
var strKey = key as string;
if (strKey == null)
return false;
locations = new List<IResourceLocation>();
locations.Add(new ResourceLocationBase("LegacyResourceLocation", strKey, typeof(LegacyResourcesProvider).FullName, typeof(UnityEngine.Object)));
return true;
}
#if ENABLE_BINARY_CATALOG
/// <summary>
/// Enumeration of all locations for this locator. This will return an empty array.
/// </summary>
public IEnumerable<IResourceLocation> AllLocations => new IResourceLocation[0];
#endif
/// <summary>
/// The keys available in this locator.
/// </summary>
public IEnumerable<object> Keys
{
get { return null; }
}
/// <summary>
/// Id of locator.
/// </summary>
public string LocatorId => nameof(LegacyResourcesLocator);
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6f5f2eb71e71b446dae10e69b8a38b2c
timeCreated: 1504834356
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,118 @@
using System;
using UnityEngine.ResourceManagement.Util;
using UnityEngine.Serialization;
namespace UnityEngine.AddressableAssets.ResourceLocators
{
/// <summary>
/// Serializable location data. This is used for the locations of the content catalogs.
/// </summary>
[Serializable]
public class ResourceLocationData
{
[FormerlySerializedAs("m_keys")]
[SerializeField]
string[] m_Keys;
/// <summary>
/// The collection of keys for this location.
/// </summary>
public string[] Keys
{
get { return m_Keys; }
}
[FormerlySerializedAs("m_internalId")]
[SerializeField]
string m_InternalId;
/// <summary>
/// The internal id.
/// </summary>
public string InternalId
{
get { return m_InternalId; }
}
[FormerlySerializedAs("m_provider")]
[SerializeField]
string m_Provider;
/// <summary>
/// The provider id.
/// </summary>
public string Provider
{
get { return m_Provider; }
}
[FormerlySerializedAs("m_dependencies")]
[SerializeField]
string[] m_Dependencies;
/// <summary>
/// The collection of dependencies for this location.
/// </summary>
public string[] Dependencies
{
get { return m_Dependencies; }
}
[SerializeField]
SerializedType m_ResourceType;
/// <summary>
/// The type of the resource for the location.
/// </summary>
public Type ResourceType
{
get { return m_ResourceType.Value; }
}
[SerializeField]
byte[] SerializedData;
object _Data;
/// <summary>
/// The optional arbitrary data stored along with location
/// </summary>
public object Data
{
get
{
if (_Data == null)
{
if (SerializedData == null || SerializedData.Length <= 0)
return null;
_Data = Utility.SerializationUtilities.ReadObjectFromByteArray(SerializedData, 0);
}
return _Data;
}
set
{
var tmp = new System.Collections.Generic.List<byte>();
Utility.SerializationUtilities.WriteObjectToByteList(value, tmp);
SerializedData = tmp.ToArray();
}
}
/// <summary>
/// Construct a new ResourceLocationData object.
/// </summary>
/// <param name="keys">Array of keys for the location. This must contain at least one item.</param>
/// <param name="id">The internal id.</param>
/// <param name="provider">The provider id.</param>
/// <param name="t">The resource object type.</param>
/// <param name="dependencies">Optional array of dependencies.</param>
public ResourceLocationData(string[] keys, string id, Type provider, Type t, string[] dependencies = null)
{
m_Keys = keys;
m_InternalId = id;
m_Provider = provider == null ? "" : provider.FullName;
m_Dependencies = dependencies == null ? new string[0] : dependencies;
m_ResourceType = new SerializedType() {Value = t};
}
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: f409833c61db2b9428d2f2bcf4dbb0a1
timeCreated: 1506572728
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.ResourceManagement;
using UnityEngine.ResourceManagement.ResourceLocations;
namespace UnityEngine.AddressableAssets.ResourceLocators
{
/// <summary>
/// Simple implementation of an IResourceLocator
/// </summary>
public class ResourceLocationMap : IResourceLocator
{
/// <summary>
/// Construct a new ResourceLocationMap object.
/// </summary>
/// <param name="id">The locator id.</param>
/// <param name="capacity">The expected number of items.</param>
public ResourceLocationMap(string id, int capacity = 0)
{
LocatorId = id;
locations = new Dictionary<object, IList<IResourceLocation>>(capacity == 0 ? 100 : capacity);
}
/// <summary>
/// Stores the resource locator id.
/// </summary>
public string LocatorId { get; private set; }
/// <summary>
/// Construct a new ResourceLocationMap object with a list of locations.
/// </summary>
/// <param name="id">The locator id.</param>
/// <param name="locations">The list of locations to initialize with.</param>
public ResourceLocationMap(string id, IList<ResourceLocationData> locations)
{
LocatorId = id;
if (locations == null)
return;
this.locations = new Dictionary<object, IList<IResourceLocation>>(locations.Count * 2);
var locMap = new Dictionary<string, ResourceLocationBase>();
var dataMap = new Dictionary<string, ResourceLocationData>();
//create and collect locations
for (int i = 0; i < locations.Count; i++)
{
var rlData = locations[i];
if (rlData.Keys == null || rlData.Keys.Length < 1)
{
Addressables.LogErrorFormat("Address with id '{0}' does not have any valid keys, skipping...", rlData.InternalId);
continue;
}
if (locMap.ContainsKey(rlData.Keys[0]))
{
Addressables.LogErrorFormat("Duplicate address '{0}' with id '{1}' found, skipping...", rlData.Keys[0], rlData.InternalId);
continue;
}
var loc = new ResourceLocationBase(rlData.Keys[0], Addressables.ResolveInternalId(rlData.InternalId), rlData.Provider, rlData.ResourceType);
loc.Data = rlData.Data;
locMap.Add(rlData.Keys[0], loc);
dataMap.Add(rlData.Keys[0], rlData);
}
//fix up dependencies between them
foreach (var kvp in locMap)
{
var data = dataMap[kvp.Key];
if (data.Dependencies != null)
{
foreach (var d in data.Dependencies)
kvp.Value.Dependencies.Add(locMap[d]);
kvp.Value.ComputeDependencyHash();
}
}
foreach (KeyValuePair<string, ResourceLocationBase> kvp in locMap)
{
ResourceLocationData rlData = dataMap[kvp.Key];
foreach (var k in rlData.Keys)
Add(k, kvp.Value);
}
}
/// <summary>
/// The mapping of key to location lists.
/// </summary>
Dictionary<object, IList<IResourceLocation>> locations;
#if ENABLE_BINARY_CATALOG
/// <summary>
/// Enumeration of all locations for this locator.
/// </summary>
public IEnumerable<IResourceLocation> AllLocations => locations.SelectMany(k => k.Value);
#endif
/// <summary>
/// Map of all locations for this locator.
/// </summary>
public Dictionary<object, IList<IResourceLocation>> Locations => locations;
/// <summary>
/// The keys available in this locator.
/// </summary>
public IEnumerable<object> Keys
{
get { return locations.Keys; }
}
/// <summary>
/// Locate all of the locations that match the given key.
/// </summary>
/// <param name="key">The key used to locate the locations.</param>
/// <param name="type">The resource type.</param>
/// <param name="locations">The list of found locations. This list is shared so it should not be modified.</param>
/// <returns>Returns true if a location was found. Returns false otherwise.</returns>
public bool Locate(object key, Type type, out IList<IResourceLocation> locations)
{
IList<IResourceLocation> locs = null;
if (!this.locations.TryGetValue(key, out locs))
{
locations = null;
return false;
}
if (type == null)
{
locations = locs;
return true;
}
var validTypeCount = 0;
foreach (var l in locs)
if (type.IsAssignableFrom(l.ResourceType))
validTypeCount++;
if (validTypeCount == 0)
{
locations = null;
return false;
}
if (validTypeCount == locs.Count)
{
locations = locs;
return true;
}
locations = new List<IResourceLocation>();
foreach (var l in locs)
{
if (type.IsAssignableFrom(l.ResourceType))
locations.Add(l);
}
return true;
}
/// <summary>
/// Add a new location.
/// </summary>
/// <param name="key">The key to reference the location.</param>
/// <param name="location">The location to add.</param>
public void Add(object key, IResourceLocation location)
{
IList<IResourceLocation> locations;
if (!this.locations.TryGetValue(key, out locations))
this.locations.Add(key, locations = new List<IResourceLocation>());
locations.Add(location);
}
/// <summary>
/// Add a list of locations.
/// </summary>
/// <param name="key">The key to reference the locations with.</param>
/// <param name="locations">The list of locations to store at the given key.</param>
public void Add(object key, IList<IResourceLocation> locations)
{
this.locations.Add(key, locations);
}
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 902a23aa7fb810b4c90bd35c50e66fde
timeCreated: 1500663969
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: