ARSceneValidator.cs
3 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
using System;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEditor.Callbacks;
using UnityEngine.XR.ARFoundation;
using UnityEditor.XR.Management;
namespace UnityEditor.XR.ARFoundation
{
internal class ARSceneValidator
{
[PostProcessBuild]
static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
{
if (s_ScenesWithARTypes.Count > 0 && s_SessionCount == 0)
{
var scenes = "";
foreach(var sceneName in s_ScenesWithARTypes)
{
scenes += string.Format("\n\t{0}", sceneName);
}
Debug.LogWarningFormat(
"The following scenes contain AR components but no ARSession. The ARSession component controls the AR lifecycle, so these components will not do anything at runtime. Was this intended?{0}",
scenes);
}
var generalSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
if(generalSettings != null && generalSettings.Manager != null && generalSettings.Manager.loaders != null)
{
int loaderCount = generalSettings.Manager.loaders.Count;
if(loaderCount <= 0 && s_SessionCount > 0)
{
Debug.LogWarning(
"There are scenes that contain an ARSession, but no XR plug-in providers have been selected for the current platform. To make a plug-in provider available at runtime go to Project Settings > XR Plug-in Management and enable at least one for the target platform.");
}
}
s_ScenesWithARTypes.Clear();
s_SessionCount = 0;
}
[PostProcessScene]
static void OnPostProcessScene()
{
if (sceneContainsARTypes)
s_ScenesWithARTypes.Add(SceneManager.GetActiveScene().name);
s_SessionCount += UnityEngine.Object.FindObjectsOfType<ARSession>().Length;
}
static bool sceneContainsARTypes
{
get
{
foreach (var type in k_ARTypes)
{
foreach (var component in UnityEngine.Object.FindObjectsOfType(type))
{
var monobehaviour = component as MonoBehaviour;
if (monobehaviour != null && monobehaviour.enabled)
return true;
}
}
return false;
}
}
static List<string> s_ScenesWithARTypes = new List<string>();
static int s_SessionCount;
static readonly Type[] k_ARTypes = new Type[]
{
typeof(ARCameraBackground),
typeof(ARPlaneManager),
typeof(ARPointCloudManager),
typeof(ARAnchorManager)
};
}
}