A game about forced loneliness, made by TACStudios
1using System; 2using System.Collections.Generic; 3 4namespace Unity.VisualScripting 5{ 6 public sealed class CloningContext : IPoolable, IDisposable 7 { 8 public Dictionary<object, object> clonings { get; } = new Dictionary<object, object>(ReferenceEqualityComparer.Instance); 9 10 public ICloner fallbackCloner { get; private set; } 11 12 public bool tryPreserveInstances { get; private set; } 13 14 private bool disposed; 15 16 void IPoolable.New() 17 { 18 disposed = false; 19 } 20 21 void IPoolable.Free() 22 { 23 disposed = true; 24 clonings.Clear(); 25 } 26 27 public void Dispose() 28 { 29 if (disposed) 30 { 31 throw new ObjectDisposedException(ToString()); 32 } 33 34 GenericPool<CloningContext>.Free(this); 35 } 36 37 public static CloningContext New(ICloner fallbackCloner, bool tryPreserveInstances) 38 { 39 var context = GenericPool<CloningContext>.New(() => new CloningContext()); 40 context.fallbackCloner = fallbackCloner; 41 context.tryPreserveInstances = tryPreserveInstances; 42 return context; 43 } 44 } 45}