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,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.ResourceManagement.ResourceLocations
{
/// <summary>
/// Interface for computing size of loading a location.
/// </summary>
public interface ILocationSizeData
{
/// <summary>
/// Compute the numder of bytes need to download for the specified location.
/// </summary>
/// <param name="location">The location to compute the size for.</param>
/// <param name="resourceManager">The object that contains all the resource locations.</param>
/// <returns>The size in bytes of the data needed to be downloaded.</returns>
long ComputeSize(IResourceLocation location, ResourceManager resourceManager);
}
}

View file

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

View file

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.ResourceManagement.ResourceLocations
{
/// <summary>
/// Contains enough information to load an asset (what/where/how/dependencies)
/// </summary>
public interface IResourceLocation
{
/// <summary>
/// Internal name used by the provider to load this location
/// </summary>
/// <value>The identifier.</value>
string InternalId { get; }
/// <summary>
/// Matches the provider used to provide/load this location
/// </summary>
/// <value>The provider id.</value>
string ProviderId { get; }
/// <summary>
/// Gets the dependencies to other IResourceLocations
/// </summary>
/// <value>The dependencies.</value>
IList<IResourceLocation> Dependencies { get; }
/// <summary>
/// The hash of this location combined with the specified type.
/// </summary>
/// <param name="resultType">The type of the result.</param>
/// <returns>The combined hash of the location and the type.</returns>
int Hash(Type resultType);
/// <summary>
/// The precomputed hash code of the dependencies.
/// </summary>
int DependencyHashCode { get; }
/// <summary>
/// Gets the dependencies to other IResourceLocations
/// </summary>
/// <value>The dependencies.</value>
bool HasDependencies { get; }
/// <summary>
/// Gets any data object associated with this locations
/// </summary>
/// <value>The object.</value>
object Data { get; }
/// <summary>
/// Primary address for this location.
/// </summary>
string PrimaryKey { get; }
/// <summary>
/// The type of the resource for th location.
/// </summary>
Type ResourceType { get; }
}
}

View file

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

View file

@ -0,0 +1,169 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.ResourceManagement.ResourceLocations
{
/// <summary>
/// Basic implementation of IResourceLocation
/// </summary>
public class ResourceLocationBase : IResourceLocation
{
string m_Name;
string m_Id;
string m_ProviderId;
object m_Data;
int m_DependencyHashCode;
int m_HashCode;
Type m_Type;
List<IResourceLocation> m_Dependencies;
string m_PrimaryKey;
/// <summary>
/// Internal id.
/// </summary>
public string InternalId
{
get { return m_Id; }
}
/// <summary>
/// Provider Id. This is usually set to the FullName property of the type of the provider class.
/// </summary>
public string ProviderId
{
get { return m_ProviderId; }
}
/// <summary>
/// List of dependencies that must be loaded before this location. This value may be null.
/// </summary>
public IList<IResourceLocation> Dependencies
{
get { return m_Dependencies; }
}
/// <summary>
/// Convenience method to see if there are any dependencies.
/// </summary>
public bool HasDependencies
{
get { return m_Dependencies != null && m_Dependencies.Count > 0; }
}
/// <summary>
/// Data that is intended for the provider. Objects can be serialized during the build process to be used by the provider. An example of usage is cache usage data for AssetBundleProvider.
/// </summary>
public object Data
{
get { return m_Data; }
set { m_Data = value; }
}
/// <inheritdoc/>
public string PrimaryKey
{
get { return m_PrimaryKey; }
set { m_PrimaryKey = value; }
}
/// <summary>
/// Precomputed hash code of dependencies.
/// </summary>
public int DependencyHashCode
{
get { return m_DependencyHashCode; }
}
/// <summary>
/// The type of the resource for th location.
/// </summary>
public Type ResourceType
{
get { return m_Type; }
}
/// <summary>
/// Compute the hash of this location for the specified type.
/// </summary>
/// <param name="t">The type to hash with.</param>
/// <returns>The combined hash code of the location and type.</returns>
public int Hash(Type t)
{
return (m_HashCode * 31 + t.GetHashCode()) * 31 + DependencyHashCode;
}
/// <summary>
/// Returns the Internal name used by the provider to load this location
/// </summary>
/// <returns></returns>
public override string ToString()
{
return m_Id;
}
/// <summary>
/// Construct a new ResourceLocationBase.
/// </summary>
/// <param name="name">The name of the location. This is usually set to the primary key, or "address" of the location.</param>
/// <param name="id">The internal id of the location. This is used by the IResourceProvider to identify the object to provide. For example this may contain the file path or url of an asset.</param>
/// <param name="providerId">The provider id. This is set to the FullName of the type of the provder class.</param>
/// <param name="t">The type of the object to provide.</param>
/// <param name="dependencies">Locations for the dependencies of this location.</param>
public ResourceLocationBase(string name, string id, string providerId, Type t, params IResourceLocation[] dependencies)
{
if (string.IsNullOrEmpty(id))
throw new ArgumentNullException(nameof(id));
if (string.IsNullOrEmpty(providerId))
throw new ArgumentNullException(nameof(providerId));
m_PrimaryKey = name;
m_HashCode = (name.GetHashCode() * 31 + id.GetHashCode()) * 31 + providerId.GetHashCode();
m_Name = name;
m_Id = id;
m_ProviderId = providerId;
m_Dependencies = new List<IResourceLocation>(dependencies);
m_Type = t == null ? typeof(object) : t;
ComputeDependencyHash();
}
/// <summary>
/// Compute the dependency hash for this location
/// </summary>
public void ComputeDependencyHash() // TODO: dependency hash is no longer just objects
{
m_DependencyHashCode = m_Dependencies.Count > 0 ? 17 : 0;
foreach (var d in m_Dependencies)
m_DependencyHashCode = m_DependencyHashCode * 31 + d.Hash(typeof(object));
}
}
internal class LocationWrapper : IResourceLocation
{
IResourceLocation m_InternalLocation;
public LocationWrapper(IResourceLocation location)
{
m_InternalLocation = location;
}
public string InternalId => m_InternalLocation.InternalId;
public string ProviderId => m_InternalLocation.ProviderId;
public IList<IResourceLocation> Dependencies => m_InternalLocation.Dependencies;
public int DependencyHashCode => m_InternalLocation.DependencyHashCode;
public bool HasDependencies => m_InternalLocation.HasDependencies;
public object Data => m_InternalLocation.Data;
public string PrimaryKey => m_InternalLocation.PrimaryKey;
public Type ResourceType => m_InternalLocation.ResourceType;
public int Hash(Type resultType)
{
return m_InternalLocation.Hash(resultType);
}
}
}

View file

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