Beispiel #1
0
        internal static Hash128 GetArtifactHash(string guid, Type importerType, ImportMode mode)
        {
            switch (mode)
            {
#if UNITY_2020_2_OR_NEWER
            case ImportMode.Asynchronous:
                return(AssetDatabaseExperimental.ProduceArtifactAsync(new ArtifactKey(new GUID(guid), importerType)).value);

            case ImportMode.Synchronous:
                return(AssetDatabaseExperimental.ProduceArtifact(new ArtifactKey(new GUID(guid), importerType)).value);

            case ImportMode.NoImport:
                return(AssetDatabaseExperimental.LookupArtifact(new ArtifactKey(new GUID(guid), importerType)).value);
#else
            case ImportMode.Asynchronous:
                return(AssetDatabaseExperimental.GetArtifactHash(guid, importerType, AssetDatabaseExperimental.ImportSyncMode.Queue));

            case ImportMode.Synchronous:
                return(AssetDatabaseExperimental.GetArtifactHash(guid, importerType));

            case ImportMode.NoImport:
                return(AssetDatabaseExperimental.GetArtifactHash(guid, importerType, AssetDatabaseExperimental.ImportSyncMode.Poll));
#endif
            }

            return(default);
Beispiel #2
0
        private static Hash128 ProduceArtifact(GUID guid, Type importerType, ImportMode mode, out OnDemandState state)
        {
            state = OnDemandState.Unavailable;
            switch (mode)
            {
                #if UNITY_2020_2_OR_NEWER
            case ImportMode.Asynchronous:
                return(AssetDatabaseExperimental.ProduceArtifactAsync(new ArtifactKey(guid, importerType)).value);

            case ImportMode.Synchronous:
                return(AssetDatabaseExperimental.ProduceArtifact(new ArtifactKey(guid, importerType)).value);

            case ImportMode.NoImport:
                var akey = new ArtifactKey(guid, importerType);
                var id   = AssetDatabaseExperimental.LookupArtifact(akey).value;
                if (!id.isValid)
                {
                    state = AssetDatabaseExperimental.GetOnDemandArtifactProgress(akey).state;
                }
                return(id);
                #else
            case ImportMode.Asynchronous:
                return(AssetDatabaseExperimental.GetArtifactHash(guid.ToString(), importerType, AssetDatabaseExperimental.ImportSyncMode.Queue));

            case ImportMode.Synchronous:
                return(AssetDatabaseExperimental.GetArtifactHash(guid.ToString(), importerType));

            case ImportMode.NoImport:
                return(AssetDatabaseExperimental.GetArtifactHash(guid.ToString(), importerType, AssetDatabaseExperimental.ImportSyncMode.Poll));
                #endif
            }

            return(default);
Beispiel #3
0
        public static string GetLibraryFullPath(string guid)
        {
            if (String.IsNullOrEmpty(guid))
            {
                return(null);
            }

            string path = AssetDatabase.GUIDToAssetPath(guid);

            if (Path.GetExtension(path).Equals(".asset"))
            {
                return(path);
            }

#if UNITY_2019_2_OR_NEWER
            if (EditorSettings.assetPipelineMode == AssetPipelineMode.Version1)
            {
                return(GetAssetDatabaseVersion1LibraryDataPath(guid));
            }
            else
            {
#if UNITY_2020_2_OR_NEWER
                Hash128 artifactHash = AssetDatabaseExperimental.LookupArtifact(new ArtifactKey(new GUID(guid))).value;
#else
                Hash128 artifactHash = AssetDatabaseExperimental.GetArtifactHash(guid);
#endif

                if (!artifactHash.isValid)
                {
                    return(null);
                }

#if UNITY_2020_2_OR_NEWER
                ArtifactID artifactID = new ArtifactID();
                artifactID.value = artifactHash;
                AssetDatabaseExperimental.GetArtifactPaths(artifactID, out string[] paths);
#else
                AssetDatabaseExperimental.GetArtifactPaths(artifactHash, out string[] paths);
#endif

                foreach (string artifactPath in paths)
                {
                    if (artifactPath.EndsWith(".info"))
                    {
                        continue;
                    }

                    return(Path.GetFullPath(artifactPath));
                }
            }
#else // For older unity versions that dont have asset database V2 yet
            return(return GetAssetDatabaseVersion1LibraryDataPath(guid));
#endif

            return(null);
        }
Beispiel #4
0
 static void HandleNotImportedAssetsInSafeModeOverlay(string guid, Rect drawRect)
 {
     if (EditorUtility.isInSafeMode)
     {
         GUID lookupGUID = new GUID(guid);
         var  hash       = AssetDatabaseExperimental.LookupArtifact(new ArtifactKey(lookupGUID));
         if (!hash.isValid)
         {
             GUI.Label(drawRect, s_NotImportedAssetTooltip);
         }
     }
 }
Beispiel #5
0
        static void HandleOndemandProgressOverlay(string guid, Rect drawRect, Action repaintAction)
        {
            if (AssetDatabaseExperimental.ActiveOnDemandMode == AssetDatabaseExperimental.OnDemandMode.Off)
            {
                return;
            }

            var now = EditorApplication.timeSinceStartup;

            if (repaintAction != null)
            {
                GUID lookupGUID = new GUID(guid);
                var  hash       = AssetDatabaseExperimental.LookupArtifact(new ArtifactKey(lookupGUID));
                if (!hash.isValid)
                {
                    if (s_ProgressRepainters.IndexOf(repaintAction) == -1)
                    {
                        s_ProgressRepainters.Add(repaintAction);
                    }

                    s_LastInvalidArtifactHashTime = now;

                    if (!s_CallbackController.active)
                    {
                        s_CallbackController.Start();
                    }

                    var texture = InternalEditorUtility.animatedProgressImage.image;
                    var xOffset = (drawRect.width - texture.width) / 2.0f;
                    if (xOffset < 0)
                    {
                        xOffset = 0;
                    }
                    var yOffset = (drawRect.height - texture.height) / 2.0f;
                    if (yOffset < 0)
                    {
                        yOffset = 0;
                    }
                    var width  = texture.width <= drawRect.width ? texture.width : drawRect.width;
                    var height = texture.height <= drawRect.height ? texture.height : drawRect.height;
                    var rect   = new Rect(drawRect.x + xOffset, drawRect.y + yOffset, width, height);
                    GUI.DrawTexture(rect, texture);
                }
            }

            if (s_CallbackController.active && (s_LastInvalidArtifactHashTime + k_AnimatedProgressImageTimeout) < now)
            {
                s_CallbackController.Stop();
                s_ProgressRepainters.Clear();
            }
        }