forked from needle-mirror/com.unity.xr.management
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XRBuildProcessorHelper.cs
89 lines (74 loc) · 3.58 KB
/
XRBuildProcessorHelper.cs
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
using System;
using System.Linq;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
namespace UnityEditor.XR.Management
{
/// <summary>
/// Base abstract class that provides some common functionality for plugins wishing to integrate with management assisted build.
/// </summary>
/// <typeparam name="T">The type parameter that will be used as the base type of the settings.</typeparam>
public abstract class XRBuildHelper<T> : IPreprocessBuildWithReport, IPostprocessBuildWithReport where T : UnityEngine.Object
{
/// <summary>Override of base IXxxprocessBuildWithReport</summary>
/// <returns>The callback order.</returns>
public virtual int callbackOrder { get { return 0; } }
/// <summary>Override of base IXxxprocessBuildWithReport</summary>
/// <returns>A string specifying the key to be used to set/get settigns in EditorBuildSettings.</returns>
public abstract string BuildSettingsKey { get; }
/// <summary>Helper functin to return current settings for a specific build target.</summary>
///
/// <param name="buildTargetGroup">An enum specifying which platform group this build is for.</param>
/// <returns>A unity object representing the settings instance data for that build target, or null if not found.</returns>
public virtual UnityEngine.Object SettingsForBuildTargetGroup(BuildTargetGroup buildTargetGroup)
{
UnityEngine.Object settingsObj = null;
EditorBuildSettings.TryGetConfigObject(BuildSettingsKey, out settingsObj);
if (settingsObj == null || !(settingsObj is T))
return null;
return settingsObj;
}
void CleanOldSettings()
{
BuildHelpers.CleanOldSettings<T>();
}
void SetSettingsForRuntime(UnityEngine.Object settingsObj)
{
// Always remember to cleanup preloaded assets after build to make sure we don't
// dirty later builds with assets that may not be needed or are out of date.
CleanOldSettings();
if (settingsObj == null)
return;
if (!(settingsObj is T))
{
Type typeOfT = typeof(T);
Debug.LogErrorFormat("Settings object is not of type {0}. No settings will be copied to runtime.", typeOfT.Name);
return;
}
UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();
if (!preloadedAssets.Contains(settingsObj))
{
var assets = preloadedAssets.ToList();
assets.Add(settingsObj);
PlayerSettings.SetPreloadedAssets(assets.ToArray());
}
}
/// <summary>Override of base IPreprocessBuildWithReport</summary>
///
/// <param name="report">BuildReport instance passed in from build pipeline.</param>
public virtual void OnPreprocessBuild(BuildReport report)
{
SetSettingsForRuntime(SettingsForBuildTargetGroup(report.summary.platformGroup));
}
/// <summary>Override of base IPostprocessBuildWithReport</summary>
///
/// <param name="report">BuildReport instance passed in from build pipeline.</param>
public virtual void OnPostprocessBuild(BuildReport report)
{
// Always remember to cleanup preloaded assets after build to make sure we don't
// dirty later builds with assets that may not be needed or are out of date.
CleanOldSettings();
}
}
}