Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [0.0.18-preview] - 2018-04-13
 - minor bug fixes
 - exposed memory cache parameters to build settings, changed defaults to use LRU and timed releases to make preloading dependencies more effective
## [0.0.17-preview] - 2018-04-13
 - added tests
 - fixed bugs
 - major API rewrite
	- all API that deals with addresses or keys have been moved to Addressables
	- LoadDependencies APIs moved to Addressables
	- Async suffix removed from all Load APIs
  • Loading branch information
Unity Technologies committed Apr 12, 2018
1 parent b363ed6 commit f730925
Show file tree
Hide file tree
Showing 39 changed files with 1,769 additions and 711 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ 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.18-preview] - 2018-04-13
- minor bug fixes
- exposed memory cache parameters to build settings, changed defaults to use LRU and timed releases to make preloading dependencies more effective
## [0.0.17-preview] - 2018-04-13
- added tests
- fixed bugs
- major API rewrite
- all API that deals with addresses or keys have been moved to Addressables
- LoadDependencies APIs moved to Addressables
- Async suffix removed from all Load APIs

## [0.0.16-preview] - 2018-04-04
- added BuildResult and callback for BuildScript
- added validation of instance to scene and scene to instance maps to help debug instances that change scenes and have not been updated
Expand Down
29 changes: 15 additions & 14 deletions Editor/Build/BuildScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AddressableAssetsBuildContext : IAddressableAssetsBuildContext
/// </summary>
public class BuildScript
{
static int codeVersion = 3;
static int codeVersion = 4;
[InitializeOnLoadMethod]
static void Init()
{
Expand Down Expand Up @@ -68,20 +68,20 @@ private static void OnEditorPlayModeChanged(PlayModeStateChange state)
}
}

static bool LoadFromCache(AddressableAssetSettings aaSettings, string settingsHash, ref ResourceManagerRuntimeData runtimeData, ref ResourceLocationList contentCatalog)
static bool LoadFromCache(AddressableAssetSettings aaSettings, string settingsHash, ResourceManagerRuntimeData.EditorPlayMode playMode, ref ResourceManagerRuntimeData runtimeData, ref ResourceLocationList contentCatalog)
{
if (!ResourceManagerRuntimeData.LoadFromLibrary(aaSettings.buildSettings.editorPlayMode.ToString(), ref runtimeData, ref contentCatalog))
return false;

if (runtimeData.settingsHash != settingsHash)
{
ResourceManagerRuntimeData.DeleteFromLibrary(aaSettings.buildSettings.editorPlayMode.ToString());
if (runtimeData.resourceProviderMode == ResourceManagerRuntimeData.EditorPlayMode.VirtualMode)
if (playMode == ResourceManagerRuntimeData.EditorPlayMode.VirtualMode)
VirtualAssetBundleRuntimeData.DeleteFromLibrary();
return false;
}

if (runtimeData.resourceProviderMode == ResourceManagerRuntimeData.EditorPlayMode.VirtualMode)
if (playMode == ResourceManagerRuntimeData.EditorPlayMode.VirtualMode)
{
if (!VirtualAssetBundleRuntimeData.CopyFromLibraryToPlayer())
WriteVirtualBundleDataTask.Run(aaSettings, runtimeData, contentCatalog, null);
Expand Down Expand Up @@ -122,9 +122,12 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool
ResourceManagerRuntimeData runtimeData = null;
ResourceLocationList contentCatalog = null;

if (!forceRebuild && LoadFromCache(aaSettings, settingsHash, ref runtimeData, ref contentCatalog))
var playMode = isPlayerBuild ? ResourceManagerRuntimeData.EditorPlayMode.PackedMode : aaSettings.buildSettings.editorPlayMode;
PlayerPrefs.SetInt("AddressablesPlayMode", (int)playMode);

if (!forceRebuild && LoadFromCache(aaSettings, settingsHash, playMode, ref runtimeData, ref contentCatalog))
{
if (enteringPlayMode && runtimeData.resourceProviderMode != ResourceManagerRuntimeData.EditorPlayMode.PackedMode)
if (enteringPlayMode && playMode != ResourceManagerRuntimeData.EditorPlayMode.PackedMode)
AddAddressableScenesToEditorBuildSettingsSceneList(aaSettings, runtimeData);
if (buildCompleted != null)
buildCompleted(new BuildResult() { completed = true, duration = timer.Elapsed.TotalSeconds });
Expand All @@ -141,12 +144,11 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool
if (!validated)
return false;


runtimeData = new ResourceManagerRuntimeData(isPlayerBuild ? ResourceManagerRuntimeData.EditorPlayMode.PackedMode : aaSettings.buildSettings.editorPlayMode);
runtimeData = new ResourceManagerRuntimeData();
contentCatalog = new ResourceLocationList();
contentCatalog.labels = aaSettings.labelTable.labelNames;
runtimeData.profileEvents = allowProfilerEvents && aaSettings.buildSettings.postProfilerEvents;
if (runtimeData.resourceProviderMode == ResourceManagerRuntimeData.EditorPlayMode.FastMode)
if (playMode == ResourceManagerRuntimeData.EditorPlayMode.FastMode)
{
foreach (var a in aaSettings.GetAllAssets(true, true))
{
Expand Down Expand Up @@ -199,7 +201,7 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool
buildTasks.Add(new BuildPlayerScripts());
buildTasks.Add(new SetBundleSettingsTypeDB());

if (runtimeData.resourceProviderMode == ResourceManagerRuntimeData.EditorPlayMode.VirtualMode)
if (playMode == ResourceManagerRuntimeData.EditorPlayMode.VirtualMode)
buildTasks.Add(new PreviewSceneDependencyData());
else
buildTasks.Add(new CalculateSceneDependencyData());
Expand All @@ -208,7 +210,7 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool
buildTasks.Add(new StripUnusedSpriteSources());
buildTasks.Add(new GenerateBundlePacking());
buildTasks.Add(new GenerateLocationListsTask());
if (runtimeData.resourceProviderMode == ResourceManagerRuntimeData.EditorPlayMode.VirtualMode)
if (playMode == ResourceManagerRuntimeData.EditorPlayMode.VirtualMode)
{
buildTasks.Add(new WriteVirtualBundleDataTask());
}
Expand Down Expand Up @@ -236,7 +238,7 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool
}
}

if (enteringPlayMode && runtimeData.resourceProviderMode != ResourceManagerRuntimeData.EditorPlayMode.PackedMode)
if (enteringPlayMode && playMode != ResourceManagerRuntimeData.EditorPlayMode.PackedMode)
AddAddressableScenesToEditorBuildSettingsSceneList(aaSettings, runtimeData);
runtimeData.contentVersion = aaSettings.profileSettings.GetValueByName(aaSettings.activeProfile, "ContentVersion");
if (string.IsNullOrEmpty(runtimeData.contentVersion))
Expand All @@ -251,7 +253,6 @@ public static bool PrepareRuntimeData(bool isPlayerBuild, bool isDevBuild, bool
contentCatalog.Validate();

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

Resources.UnloadUnusedAssets();
if (buildCompleted != null)
buildCompleted(new BuildResult() { completed = true, duration = timer.Elapsed.TotalSeconds, locationCount = contentCatalog.locations.Count });
Expand All @@ -278,7 +279,7 @@ internal static bool PreviewDependencyInfo(out BuildDependencyData depData, out
return false;
SceneManagerState.Record();

var runtimeData = new ResourceManagerRuntimeData(ResourceManagerRuntimeData.EditorPlayMode.VirtualMode);
var runtimeData = new ResourceManagerRuntimeData();
var contentCatalog = new ResourceLocationList();
var allBundleInputDefs = new List<AssetBundleBuild>();
foreach (var assetGroup in aaSettings.groups)
Expand Down
29 changes: 26 additions & 3 deletions Editor/Build/Tasks/WriteVirtualBundleDataTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEditor.Build.Pipeline.Interfaces;
using UnityEngine.ResourceManagement;
using UnityEngine.AddressableAssets;
using System.IO;

namespace UnityEditor.AddressableAssets
{
Expand Down Expand Up @@ -40,15 +41,37 @@ public static ReturnCode Run(AddressableAssetSettings aaSettings, ResourceManage
}
}
}

foreach (var bd in bundledAssets)
{
var bundleLocData = contentCatalog.locations.Find(a => a.m_address == bd.Key);
uint size = (uint)(bd.Value.Count * 1024 * 1024); //for now estimate 1MB per entry
virtualBundleData.AssetBundles.Add(new VirtualAssetBundle(bundleLocData.m_internalId, bundleLocData.m_provider == typeof(LocalAssetBundleProvider).FullName, size, bd.Value));
var bundleData = new VirtualAssetBundle(bundleLocData.m_internalId, bundleLocData.m_provider == typeof(LocalAssetBundleProvider).FullName);

long dataSize = 0;
long headerSize = 0;
foreach (var a in bd.Value)
{
var size = ComputeSize(writeData, a);
bundleData.Assets.Add(new VirtualAssetBundle.AssetInfo(a, size));
dataSize += size;
headerSize += (long)(a.Length * 5); //assume 5x path length overhead size per item, probably much less
}
bundleData.SetSize(dataSize, headerSize);
virtualBundleData.AssetBundles.Add(bundleData);
}
virtualBundleData.Save();
return ReturnCode.Success;
}

private static long ComputeSize(IBundleWriteData writeData, string a)
{
var guid = AssetDatabase.AssetPathToGUID(a);
if (string.IsNullOrEmpty(guid) || guid.Length < 2)
return 1024;
var path = string.Format("Library/metadata/{0}{1}/{2}", guid[0], guid[1], guid);
if (!File.Exists(path))
return 1024;
return new FileInfo(path).Length;
}
}
}
8 changes: 4 additions & 4 deletions Editor/GUI/AddressableAssetsSettingsConfigEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public bool OnGUI(Rect pos)
return false;
}

private void DrawSpeedSlider(string text, ref uint speed)
private void DrawSpeedSlider(string text, ref long speed)
{
speed = (uint)(Mathf.Clamp(EditorGUILayout.FloatField(text, speed / 1048576f), .1f, 1024f) * 1048576);
speed = (long)(Mathf.Clamp(EditorGUILayout.FloatField(text, speed / 1048576f), .1f, 1024f) * 1048576);
}

internal void OnEnable()
Expand Down Expand Up @@ -143,8 +143,8 @@ internal class LocalConfigData
{
internal bool postProfilerEvents;
internal ResourceManagerRuntimeData.EditorPlayMode editorPlayMode;
internal uint localLoadSpeed;
internal uint remoteLoadSpeed;
internal long localLoadSpeed;
internal long remoteLoadSpeed;
}
}
}
23 changes: 21 additions & 2 deletions Editor/GUI/AddressableAssetsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,34 @@ public void OnGUI()
if (settingsObject == null)
{
GUILayout.Space(50);
if (GUILayout.Button("Begin Using The Addressables System"))
if (GUILayout.Button("Create Addressables Settings"))
{
settingsObject = AddressableAssetSettings.GetDefault(true, true);
}
if (GUILayout.Button("Import Addressables Settings"))
{
var path = EditorUtility.OpenFilePanel("Addressables Settings Object", AddressableAssetSettings.DefaultConfigFolder, "asset");
if (!string.IsNullOrEmpty(path))
{
var i = path.ToLower().IndexOf("/assets/");
if (i > 0)
{
path = path.Substring(i+1);
Debug.LogFormat("Loading Addressables Settings from {0}", path);
var obj = AssetDatabase.LoadAssetAtPath<AddressableAssetSettings>(path);
if (obj != null)
{
EditorBuildSettings.AddConfigObject(AddressableAssetSettings.DefaultConfigName, obj, true);
settingsObject = AddressableAssetSettings.GetDefault(true, true);
}
}
}
}
GUILayout.Space(20);
GUILayout.BeginHorizontal();
GUILayout.Space(50);
GUI.skin.label.wordWrap = true;
GUILayout.Label("Click the \"Begin\" button above or simply drag an asset into this window to start using Addressables. Once you begin, the Addressables system will save some assets to your project to keep up with its data");
GUILayout.Label("Click the \"Create\" or \"Import\" button above or simply drag an asset into this window to start using Addressables. Once you begin, the Addressables system will save some assets to your project to keep up with its data");
GUILayout.Space(50);
GUILayout.EndHorizontal();
switch (Event.current.type)
Expand Down
4 changes: 2 additions & 2 deletions Editor/Settings/AddressableAssetSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace UnityEditor.AddressableAssets
/// </summary>
public partial class AddressableAssetSettings : ScriptableObject, ISerializationCallbackReceiver
{
const string DefaultConfigName = "AddresableAssetSettings";
const string DefaultConfigFolder = "Assets/AddressableAssetsData";
public const string DefaultConfigName = "AddressableAssetSettings";
public const string DefaultConfigFolder = "Assets/AddressableAssetsData";
/// <summary>
/// TODO - doc
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Editor/Settings/BuildSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public class BuildSettings
/// TODO - doc
/// </summary>
[NonSerialized]
public uint localLoadSpeed = 1024 * 1024 * 10;
public long localLoadSpeed = 1024 * 1024 * 10;
/// <summary>
/// TODO - doc
/// </summary>
[NonSerialized]
public uint remoteLoadSpeed = 1024 * 1024 * 1;
public long remoteLoadSpeed = 1024 * 1024 * 1;
/// <summary>
/// TODO - doc
/// </summary>
Expand Down
107 changes: 107 additions & 0 deletions Runtime/AAConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Reflection;

namespace UnityEngine.AddressableAssets
{
public static class AAConfig
{
#if !UNITY_EDITOR && UNITY_WSA_10_0 && ENABLE_DOTNET
static Assembly[] GetAssemblies()
{
//Not supported on UWP platforms
return new Assembly[0];
}
#else
static Assembly[] GetAssemblies()
{
return AppDomain.CurrentDomain.GetAssemblies();
}
#endif

static Dictionary<string, string> s_cachedValues = new Dictionary<string, string>();

public static void AddCachedValue(string key, string val)
{
s_cachedValues.Add(key, val);
}

public static string GetGlobalVar(string variableName)
{
Debug.Assert(s_cachedValues != null, "ResourceManagerConfig.GetGlobalVar - s_cachedValues == null.");

if (string.IsNullOrEmpty(variableName))
return string.Empty;

string cachedValue = null;
if (s_cachedValues.TryGetValue(variableName, out cachedValue))
return cachedValue;

int i = variableName.LastIndexOf('.');
if (i < 0)
return variableName;

var className = variableName.Substring(0, i);
var propName = variableName.Substring(i + 1);
foreach (var a in GetAssemblies())
{
Type t = a.GetType(className, false, false);
if (t == null)
continue;
try
{
var pi = t.GetProperty(propName, BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public);
if (pi != null)
{
var v = pi.GetValue(null, null);
if (v != null)
{
s_cachedValues.Add(variableName, v.ToString());
return v.ToString();
}
}
var fi = t.GetField(propName, BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public);
if (fi != null)
{
var v = fi.GetValue(null);
if (v != null)
{
s_cachedValues.Add(variableName, v.ToString());
return v.ToString();
}
}
}
catch (Exception)
{
}
}
return variableName;
}

public static string ExpandPathWithGlobalVariables(string inputString)
{
return ExpandWithVariables(inputString, '{', '}', GetGlobalVar);
}

public static string ExpandWithVariables(string inputString, char startDelimiter, char endDelimiter, Func<string, string> varFunc)
{
if (string.IsNullOrEmpty(inputString))
return string.Empty;

while (true)
{
int i = inputString.IndexOf(startDelimiter);
if (i < 0)
return inputString;
int e = inputString.IndexOf(endDelimiter, i);
if (e < i)
return inputString;
var token = inputString.Substring(i + 1, e - i - 1);
var tokenVal = varFunc == null ? string.Empty : varFunc(token);
inputString = inputString.Substring(0, i) + tokenVal + inputString.Substring(e + 1);
}
}


}
}
11 changes: 11 additions & 0 deletions Runtime/AAConfig.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f730925

Please sign in to comment.