first commit
This commit is contained in:
27
NitroxClient/MonoBehaviours/ReferenceHolder.cs
Normal file
27
NitroxClient/MonoBehaviours/ReferenceHolder.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.MonoBehaviours;
|
||||
|
||||
public class ReferenceHolder : MonoBehaviour
|
||||
{
|
||||
private readonly Dictionary<Type, object> references = [];
|
||||
|
||||
public bool TryGetReference<T>(out T outReference)
|
||||
{
|
||||
if (references.TryGetValue(typeof(T), out object value) && value is T reference)
|
||||
{
|
||||
outReference = reference;
|
||||
return true;
|
||||
}
|
||||
|
||||
outReference = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void AddReference<T>(T reference)
|
||||
{
|
||||
references[typeof(T)] = reference;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user