SerializableGuid.cs 904 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. [Serializable]
  6. class SerializableGuid : ISerializationCallbackReceiver
  7. {
  8. public SerializableGuid()
  9. {
  10. m_Guid = Guid.NewGuid();
  11. }
  12. public SerializableGuid(Guid guid)
  13. {
  14. m_Guid = guid;
  15. }
  16. [NonSerialized]
  17. private Guid m_Guid;
  18. [SerializeField]
  19. private string m_GuidSerialized;
  20. public Guid guid
  21. {
  22. get { return m_Guid; }
  23. }
  24. public virtual void OnBeforeSerialize()
  25. {
  26. m_GuidSerialized = m_Guid.ToString();
  27. }
  28. public virtual void OnAfterDeserialize()
  29. {
  30. if (!string.IsNullOrEmpty(m_GuidSerialized))
  31. m_Guid = new Guid(m_GuidSerialized);
  32. else
  33. m_Guid = Guid.NewGuid();
  34. }
  35. }
  36. }