/// <summary> /// Generates new Guid. Be careful with this method. It should be called only in specific cases. /// </summary> public void RegenerateGuid() { GuidManagerSingleton.Remove(guid); serializedGuid = null; guid = Guid.Empty; cachedStringGuid = null; CreateGuid(); }
/// <summary> /// Sets guid. Be careful with this method. It should be called only in specific cases. /// </summary> /// <param name="value">New guid</param> public void SetGuid(Guid value) { cachedStringGuid = null; Guid?oldGuid = null; if (IsGuidAssigned()) { oldGuid = guid; GuidManagerSingleton.Remove(guid); } guid = value; if (!GuidManagerSingleton.Add(guid, gameObject)) { Debug.LogError($"Trying to set invalid guid: {value}. Previous guid restored."); if (oldGuid.HasValue) { guid = oldGuid.Value; GuidManagerSingleton.Add(guid, gameObject); } } }
// let the manager know we are gone, so other objects no longer find this public void OnDestroy() { GuidManagerSingleton.Remove(guid); }