Skip to content

Commit 3fc53d4

Browse files
authored
Merge pull request Unity-Technologies#97 from jwtan-unity/odr-prefetch-tags
On-Demand Resources: Added functionality to apply prefetch categories to Addressables groups
2 parents 9d48808 + a9e5ed1 commit 3fc53d4

File tree

11 files changed

+137
-3
lines changed

11 files changed

+137
-3
lines changed

Advanced/On-Demand Resources/Assets/AddressableAssetsData/AssetGroups/Schemas/pack_d_AppleODRSchema.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ MonoBehaviour:
1313
m_Name: pack_d_AppleODRSchema
1414
m_EditorClassIdentifier:
1515
m_Group: {fileID: 11400000, guid: a9cbeb263f29246fcb5b9413cb69beb7, type: 2}
16+
m_prefetchCategory: 0
17+
m_order: 0
1618
m_BuildPath:
1719
m_Id: a7070c84fc67c4384b42419195dcee13

Advanced/On-Demand Resources/Assets/AddressableAssetsData/AssetGroups/Schemas/pack_e_AppleODRSchema.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ MonoBehaviour:
1313
m_Name: pack_e_AppleODRSchema
1414
m_EditorClassIdentifier:
1515
m_Group: {fileID: 11400000, guid: 27577b1f1eb80442aa0b36a2cb468bab, type: 2}
16+
m_prefetchCategory: 0
17+
m_order: 0
1618
m_BuildPath:
1719
m_Id: a7070c84fc67c4384b42419195dcee13

Advanced/On-Demand Resources/Assets/AddressableAssetsData/AssetGroups/Schemas/pack_f_AppleODRSchema.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ MonoBehaviour:
1313
m_Name: pack_f_AppleODRSchema
1414
m_EditorClassIdentifier:
1515
m_Group: {fileID: 11400000, guid: 367da7168bca646ffb7d98f87f2d872d, type: 2}
16+
m_prefetchCategory: 0
17+
m_order: 0
1618
m_BuildPath:
1719
m_Id: a7070c84fc67c4384b42419195dcee13

Advanced/On-Demand Resources/Assets/AddressableAssetsData/AssetGroups/Schemas/pack_g_AppleODRSchema.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ MonoBehaviour:
1313
m_Name: pack_g_AppleODRSchema
1414
m_EditorClassIdentifier:
1515
m_Group: {fileID: 11400000, guid: d927d0430d285434598a4c39f1c68931, type: 2}
16+
m_prefetchCategory: 1
17+
m_order: 3
1618
m_BuildPath:
1719
m_Id: a7070c84fc67c4384b42419195dcee13

Advanced/On-Demand Resources/Assets/AddressableAssetsData/AssetGroups/Schemas/pack_h_AppleODRSchema.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ MonoBehaviour:
1313
m_Name: pack_h_AppleODRSchema
1414
m_EditorClassIdentifier:
1515
m_Group: {fileID: 11400000, guid: c7fcc31dd72734b32ae7874a778246f4, type: 2}
16+
m_prefetchCategory: 1
17+
m_order: 2
1618
m_BuildPath:
1719
m_Id: a7070c84fc67c4384b42419195dcee13

Advanced/On-Demand Resources/Assets/AddressableAssetsData/AssetGroups/Schemas/pack_i_AppleODRSchema.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ MonoBehaviour:
1313
m_Name: pack_i_AppleODRSchema
1414
m_EditorClassIdentifier:
1515
m_Group: {fileID: 11400000, guid: 0ed893044bb394073875fa7eee1b3e70, type: 2}
16+
m_prefetchCategory: 1
17+
m_order: 1
1618
m_BuildPath:
1719
m_Id: a7070c84fc67c4384b42419195dcee13

Advanced/On-Demand Resources/Assets/AdrOdrExt/Editor/Build/DataBuilders/BuildScriptPackedModeODR.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ void PostProcessBundles(AddressableAssetGroup assetGroup, IBundleBuildResults bu
14811481
Debug.LogWarning($"ODR Schema build path value is null");
14821482
}
14831483
targetPath = Path.Combine(schemaPath, Path.GetFileName(targetPath));
1484-
AddBundleODR(outputBundleNames[i], targetPath, outputBundleNames[i]);
1484+
AddBundleODR(outputBundleNames[i], targetPath, assetGroup.Name, (int)odrSchema.Category, odrSchema.Order);
14851485
}
14861486
#endif
14871487

@@ -1664,6 +1664,8 @@ public class Bundle
16641664
public string name;
16651665
public string path;
16661666
public string tag;
1667+
public int category;
1668+
public int order;
16671669
}
16681670

16691671
public List<Bundle> m_bundles = new List<Bundle>();
@@ -1677,9 +1679,9 @@ public void CleanBundleInfoODR()
16771679
DeleteFile(odrSettingsPath);
16781680
m_Resources = new BundleInfoODR();
16791681
}
1680-
public void AddBundleODR(string odr_name, string odr_path, string odr_tag)
1682+
public void AddBundleODR(string odr_name, string odr_path, string odr_tag, int odr_category, int odr_order)
16811683
{
1682-
m_Resources.m_bundles.Add(new BundleInfoODR.Bundle() { name = odr_name, path = odr_path, tag = odr_tag });
1684+
m_Resources.m_bundles.Add(new BundleInfoODR.Bundle() { name = odr_name, path = odr_path, tag = odr_tag, category = odr_category, order = odr_order });
16831685
}
16841686

16851687
public void PreserveODRSettings(FileRegistry registry)
@@ -1722,6 +1724,32 @@ private static UnityEditor.iOS.Resource[] BuildPipeline_collectResources()
17221724

17231725
return m_CollectedResources.ToArray();
17241726
}
1727+
1728+
public static Dictionary<int, List<string>> CollectPrefetchCategories()
1729+
{
1730+
CollectODR();
1731+
1732+
var results = new Dictionary<int, List<string>>();
1733+
1734+
var initialTags = m_Resources.m_bundles
1735+
.Where(b=> b.category == (int)AppleODRSchema.PrefetchCategory.InitialInstallTags)
1736+
.Select(b=>b.tag)
1737+
.Distinct()
1738+
.ToList();
1739+
1740+
results.Add((int)AppleODRSchema.PrefetchCategory.InitialInstallTags, initialTags);
1741+
1742+
var prefetchedTags = m_Resources.m_bundles
1743+
.Where(b=> b.category == (int)AppleODRSchema.PrefetchCategory.PrefetchedTagOrder)
1744+
.OrderBy(b=>b.order)
1745+
.Select(b=>b.tag)
1746+
.Distinct()
1747+
.ToList();
1748+
1749+
results.Add((int)AppleODRSchema.PrefetchCategory.PrefetchedTagOrder, prefetchedTags);
1750+
1751+
return results;
1752+
}
17251753
#endif
17261754
}
17271755
}

Advanced/On-Demand Resources/Assets/AdrOdrExt/Editor/Build/PostProcess.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#if UNITY_IOS
2+
using System;
3+
using UnityEditor;
4+
using UnityEditor.AddressableAssets.Build.DataBuilders;
5+
using UnityEditor.Build;
6+
using UnityEditor.Build.Reporting;
7+
using UnityEditor.iOS.Xcode;
8+
using UnityEngine;
9+
10+
public class PostProcessODRBundles : IPostprocessBuildWithReport
11+
{
12+
public int callbackOrder { get { return 10; } }
13+
14+
private const string InitialInstallTagsKey = "ON_DEMAND_RESOURCES_INITIAL_INSTALL_TAGS";
15+
private const string PrefetchedTagOrderKey = "ON_DEMAND_RESOURCES_PREFETCH_ORDER";
16+
17+
public void OnPostprocessBuild(BuildReport report)
18+
{
19+
// Initialize PBXProject
20+
var pathToBuiltProject = report.summary.outputPath;
21+
string projectPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
22+
PBXProject pbxProject = new PBXProject();
23+
pbxProject.ReadFromFile(projectPath);
24+
25+
// Set Prefetch Categories
26+
string mainTargetGuid = pbxProject.GetUnityMainTargetGuid();
27+
var categories = BuildScriptPackedModeODR.CollectPrefetchCategories();
28+
29+
// Initial Install Tags
30+
var initialTags = categories[(int)AppleODRSchema.PrefetchCategory.InitialInstallTags];
31+
var initialTagsValue = string.Join(" ", initialTags);
32+
pbxProject.SetBuildProperty(mainTargetGuid, InitialInstallTagsKey, initialTagsValue);
33+
34+
// Prefetched Tag Order
35+
var prefetchedTags = categories[(int)AppleODRSchema.PrefetchCategory.PrefetchedTagOrder];
36+
var prefetchedTagsValue = string.Join(" ", prefetchedTags);
37+
pbxProject.SetBuildProperty(mainTargetGuid, PrefetchedTagOrderKey, prefetchedTagsValue);
38+
39+
// Apply changes to the PBXProject
40+
pbxProject.WriteToFile(projectPath);
41+
}
42+
}
43+
#endif

Advanced/On-Demand Resources/Assets/AdrOdrExt/Editor/Build/PostProcess/PostProcessODRBundles.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)