Make proxies searchable

This commit is contained in:
Noah Pilarski 2022-08-18 08:49:25 -04:00
parent 6eb1209bcc
commit e397cbc7c5
2 changed files with 41 additions and 0 deletions

View File

@ -1,4 +1,5 @@
using NewHorizons.Components.SizeControllers;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using System.Collections.Generic;
using UnityEngine;
@ -19,6 +20,7 @@ namespace NewHorizons.Components
public override void Awake()
{
ProxyHandler.RegisterProxy(this);
base.Awake();
// The star part cant be disabled like the rest and we have to manually disable the renderers
@ -42,6 +44,11 @@ namespace NewHorizons.Components
ToggleRendering(false);
}
public override void OnDestroy()
{
ProxyHandler.UnregisterProxy(this);
}
public override void Initialize()
{
AstroObject astroObject = AstroObjectLocator.GetAstroObject(astroName);

View File

@ -0,0 +1,34 @@
using NewHorizons.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.Handlers
{
public static class ProxyHandler
{
private static List<NHProxy> _proxies = new List<NHProxy>();
public static NHProxy GetProxy(string astroName)
{
foreach (NHProxy proxy in _proxies)
{
if (proxy.astroName.Equals(astroName))
return proxy;
}
return null;
}
public static void RegisterProxy(NHProxy proxy)
{
_proxies.SafeAdd(proxy);
}
public static void UnregisterProxy(NHProxy proxy)
{
_proxies.Remove(proxy);
}
}
}