Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [0.0.12-preview] - 2018-03-20
- Minor UI updates
- doc updates
- fixed bug involving caching of "all assets"
- improved error checking & logging
- minor bug fixes.
  • Loading branch information
Unity Technologies committed Mar 19, 2018
1 parent f122f4a commit ca4b7bb
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 136 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.0.12-preview] - 2018-03-20
- Minor UI updates
- doc updates
- fixed bug involving caching of "all assets"
- improved error checking & logging
- minor bug fixes.

## [0.0.8-preview] - 2018-02-08
- Initial submission for package distribution
Expand Down
4 changes: 3 additions & 1 deletion Documentation/com.unity.addressables.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Unity Addressables

Addressable Assets info placeholder
Our new Addressable Asset System allows the developer to ask for an asset via its address and get back the thing that resides at that address. Once an asset (e.g. a prefab) is marked "addressable", it generates an address which can be called from anywhere. Wherever the asset resides (local or remote), the system will locate it and its dependencies, then return it.

The Addressable Asset System uses asynchronous loading to support loading from any location with any collection of dependencies. Whether you are using direct references, traditional asset bundles, or Resource folders, addressable assets provide a simpler way to make your game more dynamic. The Addressable Asset System simultaneously opens up the world of asset bundles while managing all the complexity.

32 changes: 24 additions & 8 deletions Editor/Build/BuildScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.IO;
using UnityEngine.ResourceManagement;
using UnityEngine.AddressableAssets;
using UnityEditor.SceneManagement;

namespace UnityEditor.AddressableAssets
{
Expand All @@ -31,6 +32,7 @@ public class AddressableAssetsBuildContext : IAddressableAssetsBuildContext
/// </summary>
public class BuildScript
{
static int codeVersion = 2;
[InitializeOnLoadMethod]
static void Init()
{
Expand Down Expand Up @@ -94,7 +96,6 @@ static bool LoadFromCache(AddressableAssetSettings aaSettings, string settingsHa
return runtimeData.CopyFromLibraryToPlayer(aaSettings.buildSettings.editorPlayMode.ToString());
}


public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool allowProfilerEvents, bool forceRebuild, bool enteringPlayMode, BuildTargetGroup buildTargetGroup, BuildTarget buildTarget)
{
var timer = new System.Diagnostics.Stopwatch();
Expand All @@ -104,7 +105,7 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool
if (aaSettings == null)
return true;

var settingsHash = aaSettings.currentHash.ToString();
var settingsHash = aaSettings.currentHash.ToString() + codeVersion;
ResourceManagerRuntimeData runtimeData = null;
ResourceLocationList contentCatalog = null;

Expand All @@ -115,18 +116,23 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool
// Debug.Log("Loaded cached runtime data in " + timer.Elapsed.TotalSeconds + " secs.");
return true;
}
bool validated = true;
foreach (var assetGroup in aaSettings.groups)
{
if (!assetGroup.processor.Validate(aaSettings, assetGroup))
validated = false;
}

if (!validated)
return false;

runtimeData = new ResourceManagerRuntimeData(isPlayerBuild ? ResourceManagerRuntimeData.EditorPlayMode.PackedMode : aaSettings.buildSettings.editorPlayMode);
contentCatalog = new ResourceLocationList();
contentCatalog.labels = aaSettings.labelTable.labelNames;
runtimeData.profileEvents = allowProfilerEvents && aaSettings.buildSettings.postProfilerEvents;
if (runtimeData.resourceProviderMode == ResourceManagerRuntimeData.EditorPlayMode.FastMode)
{
var allEntries = new List<AddressableAssetSettings.AssetGroup.AssetEntry>();
foreach (var a in aaSettings.allEntries)
a.Value.GatherAllAssets(allEntries, aaSettings, true);
foreach (var a in allEntries)
foreach (var a in aaSettings.GetAllAssets(true, true))
{
var t = AssetDatabase.GetMainAssetTypeAtPath(a.assetPath);
if (t == null)
Expand All @@ -150,6 +156,9 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool

if (allBundleInputDefs.Count > 0)
{
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
return false;

var bundleWriteData = new BundleWriteData();
var bundleBuildResults = new BundleBuildResults();
var dependencyData = new BuildDependencyData();
Expand Down Expand Up @@ -205,16 +214,23 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool

if (enteringPlayMode && runtimeData.resourceProviderMode != ResourceManagerRuntimeData.EditorPlayMode.PackedMode)
AddAddressableScenesToEditorBuildSettingsSceneList(aaSettings, runtimeData);
runtimeData.contentVersion = aaSettings.profileSettings.GetValueByName(aaSettings.activeProfile, "version");
runtimeData.contentVersion = aaSettings.profileSettings.GetValueByName(aaSettings.activeProfile, "ContentVersion");
if (string.IsNullOrEmpty(runtimeData.contentVersion))
runtimeData.contentVersion = "X";

runtimeData.settingsHash = settingsHash;
var catalogLocations = new List<ResourceLocationData>();
foreach (var assetGroup in aaSettings.groups)
{
assetGroup.processor.CreateCatalog(aaSettings, assetGroup, contentCatalog, catalogLocations);
}
runtimeData.catalogLocations.locations.AddRange(catalogLocations.OrderBy(s => s.m_address));

contentCatalog.Validate();

runtimeData.Save(contentCatalog, aaSettings.buildSettings.editorPlayMode.ToString());

Debug.Log("Processed " + aaSettings.assetEntries.Count() + " addressable assets in " + timer.Elapsed.TotalSeconds + " secs.");
Debug.Log("Processed " + contentCatalog.locations.Count + " addressable assets in " + timer.Elapsed.TotalSeconds + " secs.");
Resources.UnloadUnusedAssets();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AddressableAssetSettings.ProfileSettings.ProfileValue buildPath
{
var settings = AddressableAssetSettings.GetDefault(false, false);
if ((m_buildPath == null || string.IsNullOrEmpty(m_buildPath.value)) && settings != null)
m_buildPath = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("StreamingAsssetsBuildPath"));
m_buildPath = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("LocalBuildPath"));
return m_buildPath;
}
}
Expand All @@ -41,7 +41,7 @@ public AddressableAssetSettings.ProfileSettings.ProfileValue loadPrefix
{
var settings = AddressableAssetSettings.GetDefault(false, false);
if ((m_loadPrefix == null || string.IsNullOrEmpty(m_loadPrefix.value)) && settings != null)
m_loadPrefix = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("StreamingAssetsLoadPrefix"));
m_loadPrefix = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("LocalLoadPrefix"));
return m_loadPrefix;
}
}
Expand All @@ -64,9 +64,9 @@ internal override void Initialize(AddressableAssetSettings settings)
{
Debug.Log("Initialize");
if (m_buildPath == null || string.IsNullOrEmpty(m_buildPath.value))
m_buildPath = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("StreamingAsssetsBuildPath"));
m_buildPath = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("LocalBuildPath"));
if (m_loadPrefix == null || string.IsNullOrEmpty(m_loadPrefix.value))
m_loadPrefix = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("StreamingAssetsLoadPrefix"));
m_loadPrefix = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("LocalLoadPrefix"));
if (m_bundleLoadProvider == null || string.IsNullOrEmpty(m_bundleLoadProvider.value))
m_bundleLoadProvider = settings.profileSettings.CreateProfileValue(typeof(RemoteAssetBundleProvider).FullName, true);
}
Expand Down
5 changes: 5 additions & 0 deletions Editor/Build/GroupProcessors/AssetGroupProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ internal virtual int GetPriority(AddressableAssetSettings aaSettings, Addressabl
{
return int.MaxValue;
}

internal virtual bool Validate(AddressableAssetSettings aaSettings, AddressableAssetSettings.AssetGroup assetGroup)
{
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ internal override int GetPriority(AddressableAssetSettings aaSettings, Addressab

internal override void CreateCatalog(AddressableAssetSettings aaSettings, AddressableAssetSettings.AssetGroup group, ResourceLocationList contentCatalog, List<ResourceLocationData> locations)
{
var buildPath = GetBuildPath(aaSettings) + aaSettings.profileSettings.Evaluate(aaSettings.activeProfile, "/catalog_[version].json");
var remoteHashLoadPath = "file://{UnityEngine.Application.streamingAssetsPath}/catalog_{version}.hash";
var localCacheLoadPath = "{UnityEngine.Application.persistentDataPath}/catalog_{version}.hash";
var buildPath = GetBuildPath(aaSettings) + aaSettings.profileSettings.Evaluate(aaSettings.activeProfile, "/catalog_[ContentVersion].json");
var remoteHashLoadPath = "file://{UnityEngine.Application.streamingAssetsPath}/catalog_{ContentVersion}.hash";
var localCacheLoadPath = "{UnityEngine.Application.persistentDataPath}/catalog_{ContentVersion}.hash";

var jsonText = JsonUtility.ToJson(contentCatalog);
var contentHash = Build.Utilities.HashingMethods.CalculateMD5Hash(jsonText).ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public AddressableAssetSettings.ProfileSettings.ProfileValue buildPath
{
var settings = AddressableAssetSettings.GetDefault(false, false);
if ((m_buildPath == null || string.IsNullOrEmpty(m_buildPath.value)) && settings != null)
m_buildPath = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("StreamingAsssetsBuildPath"));
m_buildPath = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("LocalBuildPath"));
return m_buildPath;
}
}
Expand All @@ -42,19 +42,37 @@ public AddressableAssetSettings.ProfileSettings.ProfileValue loadPrefix
{
var settings = AddressableAssetSettings.GetDefault(false, false);
if ((m_loadPrefix == null || string.IsNullOrEmpty(m_loadPrefix.value)) && settings != null)
m_loadPrefix = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("StreamingAssetsLoadPrefix"));
m_loadPrefix = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("LocalLoadPrefix"));
return m_loadPrefix;
}
}

internal override bool Validate(AddressableAssetSettings aaSettings, AddressableAssetSettings.AssetGroup assetGroup)
{
bool valid = true;
if (string.IsNullOrEmpty(loadPrefix.value))
{
Debug.LogWarningFormat("Asset Group '{0}' has invalid loadPrefix", assetGroup.name);
valid = false;
}
var bp = GetBuildPath(aaSettings);
if (string.IsNullOrEmpty(bp))
{
Debug.LogWarningFormat("Asset Group '{0}' has invalid buildPath", assetGroup.name);
valid = false;
}
return valid;
}

public BundleMode bundleMode = BundleMode.PackTogether;

internal override string displayName { get { return "Remote Packed Content"; } }
internal override void Initialize(AddressableAssetSettings settings)
{
if(m_buildPath == null)
m_buildPath = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("StreamingAsssetsBuildPath"));
m_buildPath = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("LocalBuildPath"));
if(m_loadPrefix == null)
m_loadPrefix = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("StreamingAssetsLoadPrefix"));
m_loadPrefix = settings.profileSettings.CreateProfileValue(settings.profileSettings.GetVariableIdFromName("LocalLoadPrefix"));
}

internal override void SerializeForHash(System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter, Stream stream)
Expand Down Expand Up @@ -89,11 +107,13 @@ internal override int GetPriority(AddressableAssetSettings aaSettings, Addressab
return 0;
}


internal override void CreateCatalog(AddressableAssetSettings aaSettings, AddressableAssetSettings.AssetGroup group, ResourceLocationList contentCatalog, List<ResourceLocationData> locations)
{
var buildPath = GetBuildPath(aaSettings) + aaSettings.profileSettings.Evaluate(aaSettings.activeProfile, "/catalog_[version].json");
var remoteHashLoadPath = m_loadPrefix.Evaluate(aaSettings.profileSettings, aaSettings.activeProfile) + "/catalog_{version}.hash";
var localCacheLoadPath = "{UnityEngine.Application.persistentDataPath}/catalog_{version}.hash";
var bp = GetBuildPath(aaSettings);
var buildPath = Path.Combine(bp, aaSettings.profileSettings.Evaluate(aaSettings.activeProfile, "catalog_[ContentVersion].json"));
var remoteHashLoadPath = m_loadPrefix.Evaluate(aaSettings.profileSettings, aaSettings.activeProfile) + "/catalog_{ContentVersion}.hash";
var localCacheLoadPath = "{UnityEngine.Application.persistentDataPath}/catalog_{ContentVersion}.hash";

var jsonText = JsonUtility.ToJson(contentCatalog);
var contentHash = Build.Utilities.HashingMethods.CalculateMD5Hash(jsonText).ToString();
Expand Down
2 changes: 1 addition & 1 deletion Editor/GUI/AddressableAssetsSettingsGroupEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void OnSettingsModification(AddressableAssetSettings s, AddressableAssetSettings
if (window != null)
window.Repaint();
break;

case AddressableAssetSettings.ModificationEvent.EntryCreated:
case AddressableAssetSettings.ModificationEvent.LabelAdded:
case AddressableAssetSettings.ModificationEvent.LabelRemoved:
case AddressableAssetSettings.ModificationEvent.ProfileAdded:
Expand Down
22 changes: 9 additions & 13 deletions Editor/GUI/AssetReferenceDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,17 @@ protected override TreeViewItem BuildRoot()
else
{
root.AddChild(new AssetRefTreeViewItem(k_noAssetString.GetHashCode(), 0, k_noAssetString, string.Empty, string.Empty));
foreach (var entry in aaSettings.assetEntries)
foreach (var entry in aaSettings.GetAllAssets(true, true))
{
if ((entry.guid != AddressableAssetSettings.AssetGroup.AssetEntry.EditorSceneListName) &&
(entry.guid != AddressableAssetSettings.AssetGroup.AssetEntry.ResourcesName))
{
bool passedFilters = true;
if (m_drawer.labelFilter != null && !m_drawer.labelFilter.Validate(entry.labels))
passedFilters = false;

if (passedFilters && m_drawer.typeFilter != null && !m_drawer.typeFilter.Validate(AssetDatabase.GetMainAssetTypeAtPath(entry.assetPath)))
passedFilters = false;
bool passedFilters = true;
if (m_drawer.labelFilter != null && !m_drawer.labelFilter.Validate(entry.labels))
passedFilters = false;

if (passedFilters && m_drawer.typeFilter != null && !m_drawer.typeFilter.Validate(AssetDatabase.GetMainAssetTypeAtPath(entry.assetPath)))
passedFilters = false;

if(passedFilters)
root.AddChild(new AssetRefTreeViewItem(entry.address.GetHashCode(), 0, entry.address, entry.guid, entry.assetPath));
}
if(passedFilters)
root.AddChild(new AssetRefTreeViewItem(entry.address.GetHashCode(), 0, entry.address, entry.guid, entry.assetPath));
}
}

Expand Down
Loading

0 comments on commit ca4b7bb

Please sign in to comment.