Unity SDK Docs 1.5.0-beta.6
Loading...
Searching...
No Matches
TiltFiveSingletonHelper.cs
1/*
2 * Copyright (C) 2020-2023 Tilt Five, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16using UnityEngine;
17
18using Obsolete = System.ObsoleteAttribute;
19
20namespace TiltFive
21{
22 public interface ISceneInfo
23 {
24 [Obsolete("ISceneInfo.GetScaleToUWRLD_UGBD is deprecated. Please use ISceneInfo.GetScaleToWorldSpaceFromGameboardSpace instead.")]
25 float GetScaleToUWRLD_UGBD();
26 float GetScaleToWorldSpaceFromGameboardSpace();
27 Pose GetGameboardPose();
28 Camera GetEyeCamera();
29 uint GetSupportedPlayerCount();
30 bool IsActiveAndEnabled();
31 }
32
33 public static class TiltFiveSingletonHelper
34 {
35 public static ISceneInfo GetISceneInfo()
36 {
37 TryGetISceneInfo(out var singleplayerSingleton);
38 return singleplayerSingleton;
39 }
40
41 public static bool TryGetISceneInfo(out ISceneInfo sceneInfo)
42 {
43 if (TiltFiveManager2.IsInstantiated)
44 {
45 sceneInfo = TiltFiveManager2.Instance;
46 return true;
47 }
48
49 if (TiltFiveManager.IsInstantiated)
50 {
51 sceneInfo = TiltFiveManager.Instance;
52 return true;
53 }
54
55 // The TiltFiveManager2 or TiltFiveManager won't appear to be instantiated
56 // until their Awake() functions are called. If we're calling from the editor
57 // outside of play mode, just scan the scene.
58 // Presumably this is being called from a menu script, gizmo, etc.
59 if (!Application.isPlaying)
60 {
61 var tiltFiveManager2 = GameObject.FindObjectOfType<TiltFiveManager2>();
62 if (tiltFiveManager2 != null)
63 {
64 sceneInfo = tiltFiveManager2;
65 return true;
66 }
67
68 var tiltFiveManager = GameObject.FindObjectOfType<TiltFiveManager>();
69 if (tiltFiveManager != null)
70 {
71 sceneInfo = tiltFiveManager;
72 return true;
73 }
74 }
75
76 sceneInfo = null;
77 return false;
78 }
79 }
80}