public static Guid GetGuid(this UnityEngine.Object obj) { if (!UnityEditor.AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long fileId)) { return(Guid.Empty); } if (string.IsNullOrEmpty(guid) || guid == "00000000000000000000000000000000") { // Special case for memory textures if (obj is UnityEngine.Texture texture) { return(texture.imageContentsHash.ToGuid()); } Debug.LogWarning($"Could not get {nameof(Guid)} for object type '{obj.GetType().FullName}'."); return(Guid.Empty); } // Merge asset database guid and file identifier var bytes = new byte[guid.Length + sizeof(long)]; Encoding.ASCII.GetBytes(guid).CopyTo(bytes, 0); BitConverter.GetBytes(fileId).CopyTo(bytes, guid.Length); return(GuidUtility.NewGuid(bytes)); }
public override Guid GetExportHash(UnityEngine.Texture2D texture) { var bytes = new List <byte>(); // Add tiny texture settings bytes var settings = Texture2DAsset.GetSettings(texture); var settingsJson = UnityEditor.EditorJsonUtility.ToJson(settings); bytes.AddRange(Encoding.ASCII.GetBytes(settingsJson)); // Add texture importer settings bytes var assetPath = UnityEditor.AssetDatabase.GetAssetPath(texture); if (!string.IsNullOrEmpty(assetPath)) { var importer = UnityEditor.AssetImporter.GetAtPath(assetPath) as UnityEditor.TextureImporter; if (importer != null) { var importerJson = UnityEditor.EditorJsonUtility.ToJson(importer); bytes.AddRange(Encoding.ASCII.GetBytes(importerJson)); } } // Add image content hash bytes var contentHash = texture.imageContentsHash.ToString(); bytes.AddRange(Encoding.ASCII.GetBytes(contentHash)); // New guid from bytes return(GuidUtility.NewGuid(bytes.ToArray())); }
static internal Entity LoadConfigAsync() { if (World.Active.TinyEnvironment().configEntity != Entity.Null) { throw new Exception("Configuration already loaded"); } var configGuid = GuidUtility.NewGuid(ConfigurationAssetPath); return(LoadSceneAsync(new SceneGuid() { Guid = configGuid })); }
public override Guid GetExportHash(UnityEngine.Video.VideoClip clip) { var bytes = new List <byte>(); // Add clip importer settings bytes var assetPath = UnityEditor.AssetDatabase.GetAssetPath(clip); if (!string.IsNullOrEmpty(assetPath)) { var importer = UnityEditor.AssetImporter.GetAtPath(assetPath) as UnityEditor.VideoClipImporter; if (importer != null) { var importerJson = UnityEditor.EditorJsonUtility.ToJson(importer); bytes.AddRange(Encoding.ASCII.GetBytes(importerJson)); } // Add hash file bytes.AddRange(File.ReadAllBytes(assetPath)); } // New id from bytes return(GuidUtility.NewGuid(bytes.ToArray())); }
public void NewGuid() { var guid = GuidUtility.NewGuid("Configuration"); Assert.AreEqual("46b433b264c69cbd39f04ad2e5d12be8", guid.ToString("N")); }