Skip to content

Commit e111fb9

Browse files
Erik Bylundkirre-bylund
authored andcommitted
fix: Change how tags are made to keep track of LootLockerServerAPI gameObjects
1 parent 11ef4ca commit e111fb9

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

Runtime/Client/LootLockerServerApi.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
using UnityEngine;
44
using UnityEngine.Networking;
55
using System;
6+
using System.Linq;
67
using System.Text;
78
using LootLocker.LootLockerEnums;
89
using UnityEditor;
910
using LootLocker.Requests;
11+
using UnityEditorInternal;
1012

1113
namespace LootLocker.LootLockerEnums
1214
{
@@ -17,6 +19,7 @@ namespace LootLocker
1719
{
1820
public class LootLockerServerApi : MonoBehaviour
1921
{
22+
private static bool _bTaggedGameObjects = false;
2023
private static LootLockerServerApi _instance;
2124
private static int _instanceId = 0;
2225
private const int MaxRetries = 3;
@@ -26,11 +29,12 @@ public static void Instantiate()
2629
{
2730
if (_instance == null)
2831
{
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+
3438
_instanceId = gameObject.GetInstanceID();
3539
_instance = gameObject.AddComponent<LootLockerServerApi>();
3640
_instance.StartCoroutine(CleanUpOldInstances());
@@ -41,6 +45,10 @@ public static void Instantiate()
4145

4246
public static IEnumerator CleanUpOldInstances()
4347
{
48+
if (!_bTaggedGameObjects)
49+
{
50+
yield break;
51+
}
4452
GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("LootLockerServerApiGameObject");
4553
foreach (GameObject gameObject in gameObjects)
4654
{
@@ -70,10 +78,24 @@ public static void ResetInstance()
7078

7179
#if UNITY_EDITOR
7280
[InitializeOnEnterPlayMode]
73-
static void OnEnterPlaymodeInEditor(EnterPlayModeOptions options)
81+
private static void OnEnterPlaymodeInEditor(EnterPlayModeOptions options)
7482
{
7583
ResetInstance();
7684
}
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+
}
7799
#endif
78100

79101
public static void SendRequest(LootLockerServerRequest request, Action<LootLockerResponse> OnServerResponse = null)

0 commit comments

Comments
 (0)