using System.Collections.Generic; using UnityEngine.Assertions; namespace Unity.Tutorials.Core { /// /// Manages SceneObjectGuids. /// /// public class SceneObjectGuidManager { static SceneObjectGuidManager m_Instance; Dictionary m_Components = new Dictionary(); /// /// Returns the singleton instance. /// public static SceneObjectGuidManager Instance { get { if (m_Instance == null) { m_Instance = new SceneObjectGuidManager(); } return m_Instance; } private set { m_Instance = value; } } /// /// Registers a GUID component. /// /// public void Register(SceneObjectGuid component) { Assert.IsFalse(string.IsNullOrEmpty(component.Id)); //Add will trow an exception if the id is already registered m_Components.Add(component.Id, component); } /// /// Does the manager contain a Component for specific GUID. /// /// /// public bool Contains(string id) { return m_Components.ContainsKey(id); } /// /// Unregisters a GUID Component. /// /// /// True if the Component was found and unregistered, false otherwise. public bool Unregister(SceneObjectGuid component) { return m_Components.Remove(component.Id); } /// /// Returns the GUID Component for a specific GUID, if found. /// /// /// public SceneObjectGuid GetComponent(string id) { if (m_Components.TryGetValue(id, out SceneObjectGuid value)) { return value; } return null; } } }