-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCameraCache.cs
40 lines (36 loc) · 1.23 KB
/
CameraCache.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using UnityEngine;
namespace HoloToolkit.Unity
{
/// <summary>
/// The purpose of this class is to provide a cached reference to the main camera. Calling Camera.main
/// executes a FindByTag on the scene, which will get worse and worse with more tagged objects.
/// </summary>
public static class CameraCache
{
private static Camera cachedCamera;
/// <summary>
/// Returns a cached reference to the main camera and uses Camera.main if it hasn't been cached yet.
/// </summary>
public static Camera Main
{
get
{
if (cachedCamera == null)
{
return Refresh(Camera.main);
}
return cachedCamera;
}
}
/// <summary>
/// Set the cached camera to a new reference and return it
/// </summary>
/// <param name="newMain">New main camera to cache</param>
public static Camera Refresh(Camera newMain)
{
return cachedCamera = newMain;
}
}
}