3
3
using UnityEngine ;
4
4
using UnityEngine . Networking ;
5
5
using System ;
6
+ using System . Linq ;
6
7
using System . Text ;
7
8
using LootLocker . LootLockerEnums ;
8
9
using UnityEditor ;
9
10
using LootLocker . Requests ;
11
+ using UnityEditorInternal ;
10
12
11
13
namespace LootLocker . LootLockerEnums
12
14
{
@@ -17,6 +19,7 @@ namespace LootLocker
17
19
{
18
20
public class LootLockerServerApi : MonoBehaviour
19
21
{
22
+ private static bool _bTaggedGameObjects = false ;
20
23
private static LootLockerServerApi _instance ;
21
24
private static int _instanceId = 0 ;
22
25
private const int MaxRetries = 3 ;
@@ -26,11 +29,12 @@ public static void Instantiate()
26
29
{
27
30
if ( _instance == null )
28
31
{
29
- var gameObject = new GameObject ( "LootLockerServerApi" ) ;
30
- #if UNITY_EDITOR
31
- UnityEditorInternal . InternalEditorUtility . AddTag ( "LootLockerServerApiGameObject" ) ;
32
- gameObject . tag = "LootLockerServerApiGameObject" ;
33
- #endif
32
+ var gameObject = new GameObject ( "LootLockerServerApi" ) ;
33
+ if ( _bTaggedGameObjects )
34
+ {
35
+ gameObject . tag = "LootLockerServerApiGameObject" ;
36
+ }
37
+
34
38
_instanceId = gameObject . GetInstanceID ( ) ;
35
39
_instance = gameObject . AddComponent < LootLockerServerApi > ( ) ;
36
40
_instance . StartCoroutine ( CleanUpOldInstances ( ) ) ;
@@ -41,6 +45,10 @@ public static void Instantiate()
41
45
42
46
public static IEnumerator CleanUpOldInstances ( )
43
47
{
48
+ if ( ! _bTaggedGameObjects )
49
+ {
50
+ yield break ;
51
+ }
44
52
GameObject [ ] gameObjects = GameObject . FindGameObjectsWithTag ( "LootLockerServerApiGameObject" ) ;
45
53
foreach ( GameObject gameObject in gameObjects )
46
54
{
@@ -70,10 +78,24 @@ public static void ResetInstance()
70
78
71
79
#if UNITY_EDITOR
72
80
[ InitializeOnEnterPlayMode ]
73
- static void OnEnterPlaymodeInEditor ( EnterPlayModeOptions options )
81
+ private static void OnEnterPlaymodeInEditor ( EnterPlayModeOptions options )
74
82
{
75
83
ResetInstance ( ) ;
76
84
}
85
+
86
+ [ InitializeOnLoadMethod ]
87
+ private static void CreateTag ( )
88
+ {
89
+ if ( InternalEditorUtility . tags . Contains ( "LootLockerServerApiGameObject" ) )
90
+ {
91
+ _bTaggedGameObjects = true ;
92
+ }
93
+ else
94
+ {
95
+ InternalEditorUtility . AddTag ( "LootLockerServerApiGameObject" ) ;
96
+ _bTaggedGameObjects = true ;
97
+ }
98
+ }
77
99
#endif
78
100
79
101
public static void SendRequest ( LootLockerServerRequest request , Action < LootLockerResponse > OnServerResponse = null )
0 commit comments