-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathBuildScriptInheritedVirtualMode.cs
More file actions
107 lines (92 loc) · 3.7 KB
/
BuildScriptInheritedVirtualMode.cs
File metadata and controls
107 lines (92 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.AddressableAssets.Build;
using UnityEditor.AddressableAssets.Build.DataBuilders;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
using UnityEngine.ResourceManagement.ResourceProviders.Simulation;
using UnityEngine.ResourceManagement.Util;
using UnityEngine.Serialization;
[CreateAssetMenu(fileName = "BuildScriptInheritedVirtualMode.asset", menuName = "Addressables/Custom Build/Variant Simulate Groups (advanced)")]
public class BuildScriptInheritedVirtualMode : BuildScriptVirtualMode
{
public override string Name
{
get { return "Variant Simulate Groups (advanced)"; }
}
protected override TResult BuildDataImplementation<TResult>(AddressablesDataBuilderInput context)
{
var result = base.BuildDataImplementation<TResult>(context);
AddressableAssetSettings settings = context.AddressableSettings;
DoCleanup(settings);
return result;
}
protected override string ProcessGroup(AddressableAssetGroup assetGroup, AddressableAssetsBuildContext aaContext)
{
if (assetGroup.HasSchema<TextureVariationSchema>())
ProcessTextureScaler(assetGroup.GetSchema<TextureVariationSchema>(), assetGroup, aaContext);
if (assetGroup.HasSchema<PrefabTextureVariantSchema>())
ProcessVariants(assetGroup.GetSchema<PrefabTextureVariantSchema>(), assetGroup, aaContext);
return base.ProcessGroup(assetGroup, aaContext);
}
List<AddressableAssetGroup> m_SourceGroupList = new List<AddressableAssetGroup>();
void ProcessTextureScaler(TextureVariationSchema schema, AddressableAssetGroup assetGroup, AddressableAssetsBuildContext aaContext)
{
m_SourceGroupList.Add(assetGroup);
var entries = new List<AddressableAssetEntry>(assetGroup.entries);
foreach (var entry in entries)
{
foreach (var pair in schema.Variations)
{
entry.SetLabel(pair.label, true);
}
entry.SetLabel(schema.BaselineLabel, true);
}
}
void ProcessVariants(PrefabTextureVariantSchema schema,
AddressableAssetGroup group,
AddressableAssetsBuildContext context)
{
m_SourceGroupList.Add(group);
var entries = new List<AddressableAssetEntry>(group.entries);
foreach (var entry in entries)
{
entry.SetLabel(schema.DefaultLabel, true, true, false);
foreach (var variant in schema.Variants)
entry.SetLabel(variant.Label, true, true, false);
}
}
void DoCleanup(AddressableAssetSettings settings)
{
foreach (var group in m_SourceGroupList)
{
if (group.HasSchema<TextureVariationSchema>())
{
var schema = group.GetSchema<TextureVariationSchema>();
foreach (var entry in group.entries)
{
entry.labels.Remove(schema.BaselineLabel);
foreach (var pair in schema.Variations)
{
entry.labels.Remove(pair.label);
}
}
}
if (group.HasSchema<PrefabTextureVariantSchema>())
{
var schema = group.GetSchema<PrefabTextureVariantSchema>();
foreach (var entry in group.entries)
{
entry.labels.Remove(schema.DefaultLabel);
foreach (var variant in schema.Variants)
entry.labels.Remove(variant.Label);
}
}
}
m_SourceGroupList.Clear();
}
}