Ejemplo n.º 1
0
        private static void HandleScriptsChange(string[] importedAssets, string[] deletedAssets, string[] movedAssets)
        {
            bool hasScriptAssets = false;

            string[] assets = new string[0];
            ArrayUtility.AddRange(ref assets, importedAssets);
            ArrayUtility.AddRange(ref assets, deletedAssets);
            ArrayUtility.AddRange(ref assets, movedAssets);

            if (assets != null)
            {
                foreach (var item in assets)
                {
                    if (Utility.IsScriptAsset(item))
                    {
                        hasScriptAssets = true;
                        break;
                    }
                }
            }

            if (hasScriptAssets)
            {
                APCache.SaveToLocalAsync();
            }
        }
Ejemplo n.º 2
0
            private static bool HandleNewAnimationClipOnSelection(UnityEngine.Object obj)
            {
                string assetPath = AssetDatabase.GetAssetPath(obj);

                if (Utility.IsUntyNewAnimation(assetPath))
                {
                    var guid             = AssetDatabase.AssetPathToGUID(assetPath);
                    var animationInCache = APCache.GetValue(guid) as APAnimation;

                    if (animationInCache == null)
                    {
                        return(false);
                    }

                    var currentAnimation = APResources.GetAPAnimationFromClip(obj as AnimationClip);
                    currentAnimation.Id = guid;

                    if (animationInCache.CycleOffset - currentAnimation.CycleOffset > 0.001f ||
                        animationInCache.LoopPose != currentAnimation.LoopPose ||
                        animationInCache.LoopTime != currentAnimation.LoopTime ||
                        animationInCache.FPS != currentAnimation.FPS ||
                        animationInCache.InAssetBundle != currentAnimation.InAssetBundle ||
                        animationInCache.Length - currentAnimation.Length > 0.001f)
                    {
                        webCommunicationService.UpdateObjectsIntoCache(APAssetType.AnimationClip, currentAnimation, SyncManager.ModifiedAssets);
                        return(true);
                    }
                }

                return(false);
            }
Ejemplo n.º 3
0
            private static bool HandlePrefabOnSelection(UnityEngine.Object obj)
            {
                string assetPath = AssetDatabase.GetAssetPath(obj);

                if (Utility.IsPrefab(assetPath))
                {
                    var guid          = AssetDatabase.AssetPathToGUID(assetPath);
                    var prefabInCache = APCache.GetValue(guid) as APPrefab;

                    if (prefabInCache == null)
                    {
                        return(false);
                    }

                    var currentPrefab = APResources.GetAPPrefabFromAssetGuid(guid);

                    if (prefabInCache.InLayers != currentPrefab.InLayers ||
                        prefabInCache.InAssetBundle != currentPrefab.InAssetBundle ||
                        prefabInCache.ContainTags != currentPrefab.ContainTags)
                    {
                        webCommunicationService.UpdateObjectsIntoCache(APAssetType.Prefab, currentPrefab, SyncManager.ModifiedAssets);
                        return(true);
                    }
                }

                return(false);
            }
Ejemplo n.º 4
0
            private static void CheckUsedUpdate()
            {
                var markFile = AssetsUsageChecker.GetMarkFile();

                if (File.Exists(markFile))
                {
                    if (!APCache.LoadFromLocal())
                    {
                        APCache.LoadDataIntoCache(CheckUnusedState);
                    }
                    else
                    {
                        CheckUnusedState();
                    }
                }


                if (File.Exists(AFTERBUILD_A_PLUS))
                {
                    if (APlusWindow.Instance != null &&
                        APlusWindow.Instance.webview != null &&
                        AssetNotification.webCommunicationService != null)
                    {
                        AssetNotification.webCommunicationService.RefreshAll();
                        AssetNotification.webCommunicationService.Refresh();
                        File.Delete(AFTERBUILD_A_PLUS);
                    }
                }
            }
Ejemplo n.º 5
0
        private static void HandleDeletedAssets(string[] deletedAssets)
        {
            var animationClips = APCache.GetAssetsListByTypeFromCache <APAnimation>(APAssetType.AnimationClip);

            foreach (var assetPath in deletedAssets)
            {
                Utility.DebugLog(string.Format("Deleted: {0}", assetPath));

                if (Utility.IsModelPath(assetPath))
                {
                    foreach (var clip in animationClips)
                    {
                        if (clip.Path.Contains(assetPath))
                        {
                            APCache.Remove(APAssetType.AnimationClip, clip.Id);
                            SyncManager.DeleteAssets.Enqueue(clip);
                            SyncManager.DeleteAssets.Enqueue(APResources.GetBlackListAPAsset(assetPath));
                        }
                    }
                }

                var id    = AssetDatabase.AssetPathToGUID(assetPath);
                var asset = APCache.GetValue(AssetDatabase.AssetPathToGUID(assetPath));
                if (asset != null)
                {
                    APCache.Remove(id);
                    APCache.RemoveFromBlacklist(assetPath);
                    SyncManager.DeleteAssets.Enqueue(asset);
                    SyncManager.DeleteAssets.Enqueue(APResources.GetBlackListAPAsset(assetPath));
                }
            }
        }
        private void CopyAssetPropertyToClipboard(string msg, Func <APAsset, string> selector)
        {
            if (string.IsNullOrEmpty(msg))
            {
                return;
            }

            var decompressedMessage = Encoding.UTF8.GetString(CLZF2.Decompress(Convert.FromBase64String(msg)));
            var assets = decompressedMessage.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var names  = new List <string>();

            foreach (var assetId in assets)
            {
                var asset = APCache.GetValue(assetId);
                if (asset != null)
                {
                    names.Add(selector(asset));
                }
            }

            TextEditor textEditor = new TextEditor();

            textEditor.ReplaceSelection(string.Join("\n", names.ToArray()));
            textEditor.OnFocus();
            textEditor.Copy();
        }
        public static void Process(WebViewCommunicationService service, bool saveToLocal = false)
        {
            if (!Enable)
            {
                return;
            }

            if (!IfNeedToProcess())
            {
                return;
            }

            var modifed   = LoopDequeueToList(ModifiedAssets);
            var deleted   = LoopDequeueToList(DeleteAssets);
            var movedFrom = LoopDequeueToList(MovedFromAssets);
            var movedTo   = LoopDequeueToList(MovedToAssets);
            var added     = LoopDequeueToList(AddedAssets);

            service.DoAssetsChange(added, deleted, modifed, movedFrom, movedTo);

            if (saveToLocal)
            {
                APCache.SaveToLocalAsync();
            }

            Resources.UnloadUnusedAssets();
        }
Ejemplo n.º 8
0
        public static List <string> GetReferencesByType <T>(string assetPath, APAssetType type, string progressInfo, float startProgress, float endProcess, ref bool cancel) where T : APAsset
        {
            List <string> references = new List <string>();
            var           lookForSet = APCache.GetAssetsListByTypeFromCache <T>(type);

            string title    = "Find references";
            float  progress = 0;

            for (int i = 0; i < lookForSet.Count; i++)
            {
                var dependences = AssetDatabase.GetDependencies(new string[] { lookForSet[i].Path });
                if (dependences.Any(denpend => denpend.Equals(assetPath, StringComparison.CurrentCultureIgnoreCase)))
                {
                    references.Add(lookForSet[i].Path);
                }

                progress = startProgress + (endProcess - startProgress) * (i + 1) * 1f / lookForSet.Count;
                if (EditorUtility.DisplayCancelableProgressBar(title, progressInfo, progress))
                {
                    cancel = true;
                    break;
                }
                ;
            }

            return(references);
        }
Ejemplo n.º 9
0
        private static void SelectReferencesByType(string assetType)
        {
            HashSet <string> references = new HashSet <string>();
            var  objects = Selection.objects;
            bool Cancel  = false;

            for (int i = 0; i < objects.Length; i++)
            {
                var    path          = AssetDatabase.GetAssetPath(objects[i]);
                string message       = "Find references of " + path;
                float  startProgress = i * 1f / objects.Length;
                float  endProgress   = (i + 1) * 1f / objects.Length;

                List <string> referencesAssets = new List <string>();
                switch (assetType)
                {
                case AssetType.MODELS:
                    referencesAssets = APCache.GetReferencesByType <APModel>(path, APAssetType.Model, message, startProgress, endProgress, ref Cancel);
                    break;

                case AssetType.MATERIALS:
                    referencesAssets = APCache.GetReferencesByType <APMaterial>(path, APAssetType.Material, message, startProgress, endProgress, ref Cancel);
                    break;

                case AssetType.PREFABS:
                    referencesAssets = APCache.GetReferencesByType <APPrefab>(path, APAssetType.Prefab, message, startProgress, endProgress, ref Cancel);
                    break;

                case AssetType.SCENE:
                    referencesAssets = APCache.GetReferencesInScene(path, ref Cancel, true, message, startProgress, endProgress);
                    break;

                default:
                    break;
                }

                foreach (var item in referencesAssets)
                {
                    if (!item.Equals(path, StringComparison.CurrentCultureIgnoreCase))
                    {
                        references.Add(item);
                    }
                }

                if (Cancel)
                {
                    break;
                }
            }

            if (!Cancel)
            {
                SelectReferences(references.ToList());
            }
            else
            {
                EditorUtility.ClearProgressBar();
            }
        }
Ejemplo n.º 10
0
        private static string GetNullKey()
        {
            var nullKey  = "AA625B9BDB3AE0E4";
            var nullIcon = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAFBUlEQVRYCdVXa0wcVRT+dvbN7rK0LE8tVBpJTLU/tBFC+OEPhURrfCQ1aSXRxkQwFZOKMdUmNYZqgqbBEEvBV4zGlNYfNlGDIGgULNrq1opoghEIBDbyKrvssju7OzOeMzC8dtqFJU30JGfuuXfuPee7555z5o4BiSTU1dWdThxeGVEUBQMDA+MdHR1v0qhILK+83Zxk0JmeMTc3d1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evXuWk3qAJ/0z40f/rB0FGUYcf7IczZ/2YoLKrX8+iJ62M7joD2KP24K/L/fBmeGBNTyLW2/xQLJtR82Lr2kpmJoHGEBOphtTaSF8deoFFOWmY7zvfXzRcBjDnzXiN28fKnflQYjOI9OTjsDsBNVcCX0DY1STYmoNYB3Xog15gBf7RoeQV1Ck6vF6vbDb7cjNzVXvAJzrr77xFuaGvQgHpiErBqQ7HdhZWIhnj/G1cZH0YmBDAERRXP7casrWt3zWraffxh+Xuqn8yrir7F4cqq5VA1CbmzIATcFWWz0ASbNgq0aTrf//AaipqYHf71/eGPe3Qil5wO12L9tsaWnhS+hyf7NCSgDWG+F/glRpQ2mYqvL16/6TWaDnAb4j8FfrRhDfthf/526E9lR0/gs8uBE8u4t8mgAAAABJRU5ErkJggg==";

            APCache.AddIcon(nullKey, nullIcon);
            return(nullKey);
        }
Ejemplo n.º 11
0
 private static void PlaymodeStateChanged()
 {
     if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
     {
         Utility.DebugLog("APCache.SaveToLocalAsync()");
         APCache.SaveToLocalAsync();
     }
 }
        private void GetIconCache(string message, object callback)
        {
            var json = APCache.GetIconCacheJSON();

            json = Convert.ToBase64String(CLZF2.Compress(Encoding.UTF8.GetBytes(json)));
            wrap = new CallbackWrapper(callback);
            wrap.Send(json);
        }
Ejemplo n.º 13
0
        public static string GetIconID(string assetPath, bool isAnimation = false)
        {
            if (isAnimation)
            {
                var iconData1 = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAKoElEQVR4AeVba2+UxxU+ezX2rh17fceAGxOXIlDaVBWiEl+a0pakalUXgQC1FPGhUvkF/QF86C8AqRJfqFSpUqRIUf9EW0Ta0rRuSLBjO9h4zdp7v3gvPc959+zO4r3Ma3BY14NmZ3beeWfOec5zzlzWeCqVCh3k5D3IykP3Aw+A34YBHo+nh/sNc+616d8FfbIsw3N273wnWawA4EGGf/f7Pyx1Gqybnv/21788xvI87SSTL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VRbAHIVMICzgtBp4NfxHABA+eqWLWcjg0d9p11nHhh/knGSc6Rdvy56hgPFf1i3551kagpAEx/al/9zlJVv+J+jzYxtCwCABAi4o9gPCfdmDcpD6GYA2MYAvL9jQDTu9/Q/Fx0+MU9jgzEAAAAASUVORK5CYII=";
                var key1      = Utility.MD5(iconData1);
                APCache.AddIcon(key1, iconData1);
                return(key1);
            }
            try
            {
                var texture = AssetDatabase.GetCachedIcon(assetPath);

                if (texture == null)
                {
                    return(GetNullKey());
                }

                var format = (texture as Texture2D).format;

                if (!IsSupportedFormat(format))
                {
                    return(GetNullKey());
                }

                var newTexture = new Texture2D(texture.width, texture.height, (texture as Texture2D).format, false);
                newTexture.LoadRawTextureData((texture as Texture2D).GetRawTextureData());

                // Thanks Axel Garcia for fixing the read icon texture exception.
                //
                var bytes = new byte[0];
                try
                {
                    bytes = newTexture.EncodeToPNG();
                }
                catch (Exception e)
                {
                    Debug.Log(string.Format("Get Icon of {0} failed\r\n Exception: \r\n {1}", assetPath, e));
                    return(GetNullKey());
                }

                if (bytes != null && bytes.Length > 0)
                {
                    var iconData = System.Convert.ToBase64String(newTexture.EncodeToPNG());
                    var key      = Utility.MD5(iconData);
                    APCache.AddIcon(key, iconData);
                    return(key);
                }
                else
                {
                    return(GetNullKey());
                }
            }
            catch
            {
                return(GetNullKey());
            }
        }
Ejemplo n.º 14
0
 public static void RefreshCache()
 {
     EditorPrefs.DeleteKey(APCache.LOAD_FROM_LOCAL_KEY);
     APCache.ReloadCache(() =>
     {
         AssetNotification.webCommunicationService.RefreshAll();
         AssetNotification.webCommunicationService.Refresh();
     });
 }
 public void UpdateObjectsIntoCache(APAssetType type, APAsset asset, Queue <APAsset> modifedAssets = null)
 {
     if (APCache.HasAsset(type, asset.Id))
     {
         APCache.SetValue(type, asset.Id, asset);
         if (modifedAssets != null)
         {
             modifedAssets.Enqueue(asset);
         }
     }
 }
        private static string GenerateCSV <T>(string header, APAssetType type, Func <T, string> rowDataGenerator) where T : APAsset
        {
            var           dataSet = APCache.GetAssetsListByTypeFromCache <T>(type);
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine(header);
            foreach (var item in dataSet)
            {
                sb.AppendLine(rowDataGenerator(item));
            }

            return(sb.ToString());
        }
Ejemplo n.º 17
0
        public static void FindUnusedAssets()
        {
            string title   = "Find unused files?";
            string message = "Press 'OK' to launch a build setting dialog to start a build.\r\n\r\n";

            if (EditorUtility.DisplayDialog(title, message, "OK", "Cancel"))
            {
                EditorWindow.GetWindow(System.Type.GetType("UnityEditor.BuildPlayerWindow,UnityEditor"));
            }

            APCache.SaveToLocal();
            EditorPrefs.SetString(APCache.LOAD_FROM_LOCAL_KEY, APCache.LOAD_FROM_LOCAL_KEY);
        }
Ejemplo n.º 18
0
            static PrepareOnLoad()
            {
                Utility.DebugLog("Executing PrepareOnLoad");
                webCommunicationService           = ScriptableObject.CreateInstance <WebViewCommunicationService>();
                webCommunicationService.hideFlags = HideFlags.HideAndDontSave;

                EditorApplication.update -= BackgroundUpdate;
                EditorApplication.update -= CheckUsedUpdate;

                EditorApplication.update += BackgroundUpdate;
                EditorApplication.update += CheckUsedUpdate;

#if UNITY_2017_1_OR_NEWER
                EditorApplication.playModeStateChanged += e => { PlaymodeStateChanged(); };
#else
                EditorApplication.playmodeStateChanged += PlaymodeStateChanged;
#endif

                time = EditorApplication.timeSinceStartup;

                // Load black list data form local file
                APCache.LoadBlacklist();

                if (PreferencesItems.AutoRefreshCacheOnProjectLoad)
                {
                    APCache.LoadDataIntoCache(CheckUnusedState);
                }
                else
                {
                    if (EditorApplication.isPlayingOrWillChangePlaymode ||
                        EditorApplication.isCompiling)
                    {
                        if (!APCache.LoadFromLocal())
                        {
                            APCache.LoadDataIntoCache(CheckUnusedState);
                        }
                        else
                        {
                            CheckUnusedState();
                        }
                    }
                    else
                    {
                        if (!APCache.LoadFromLocal())
                        {
                            APCache.LoadDataIntoCache(CheckUnusedState);
                        }
                    }
                }
            }
Ejemplo n.º 19
0
            private static bool HandleMaterialOnSelection(UnityEngine.Object obj)
            {
                string assetPath       = AssetDatabase.GetAssetPath(obj);
                var    currentMaterial = (obj as Material);
                var    guid            = AssetDatabase.AssetPathToGUID(assetPath);
                var    materialInCache = APCache.GetValue(APAssetType.Material, guid) as APMaterial;

                if (materialInCache != null && !currentMaterial.shader.name.Equals(materialInCache.Shader, StringComparison.CurrentCultureIgnoreCase))
                {
                    webCommunicationService.UpdateObjectsIntoCache(APAssetType.Material, guid, SyncManager.ModifiedAssets);
                    return(true);
                }

                return(false);
            }
Ejemplo n.º 20
0
        private static List <string> GetReferences <T>(string assetPath, APAssetType type) where T : APAsset
        {
            List <string> references = new List <string>();
            var           lookForSet = APCache.GetAssetsListByTypeFromCache <T>(type);

            foreach (var asset in lookForSet)
            {
                var dependences = AssetDatabase.GetDependencies(new string[] { asset.Path });
                if (dependences.Any(denpend => denpend.Equals(assetPath, StringComparison.CurrentCultureIgnoreCase)))
                {
                    references.Add(asset.Path);
                }
            }

            return(references);
        }
        private void DeleteFromBlacklist(string paths, object callback)
        {
            var assetPaths = paths.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (assetPaths.Length == 0)
            {
                return;
            }

            foreach (string path in assetPaths)
            {
                APCache.RemoveFromBlacklist(path);
            }

            APCache.CommitBlacklistChange();
        }
        private string GetHierarchyAssetsListJson()
        {
            var assets = EditorUtility.CollectDependencies(GameObject.FindObjectsOfType(typeof(GameObject)));
            Dictionary <string, APHierarchyAsset> realAssets = new Dictionary <string, APHierarchyAsset>();

            foreach (var item in assets)
            {
                var assetPath = AssetDatabase.GetAssetPath(item);

                if (string.IsNullOrEmpty(assetPath) ||
                    assetPath.Contains("unity_builtin_extra") ||
                    assetPath.Contains("unity default resources") ||
                    assetPath.Contains("unity editor resources"))
                {
                    continue;
                }

                var guid = AssetDatabase.AssetPathToGUID(assetPath);
                if (realAssets.ContainsKey(guid))
                {
                    Utility.UpdateJsonInAsset(realAssets[guid]);
                }
                else
                {
                    APHierarchyAsset aphAsset = new APHierarchyAsset();

                    if (Utility.IsModelPath(assetPath) && (item is AnimationClip))
                    {
                        aphAsset.Id   = Utility.GetAssetId(guid, Utility.GetLocalIndentifierOfObject(item).ToString());
                        aphAsset.Name = item.name;
                    }
                    else
                    {
                        aphAsset.Id   = guid;
                        aphAsset.Name = Utility.GetFileName(assetPath);
                    }

                    aphAsset.FileType = Utility.GetFileExtension(assetPath);
                    aphAsset.Icon     = APResources.GetIconID(assetPath, item is AnimationClip);
                    Utility.UpdateJsonInAsset(aphAsset);
                    realAssets.Add(guid, aphAsset);
                }
            }

            return(APCache.GetJsonFromList(realAssets.Values.ToArray()));
        }
Ejemplo n.º 23
0
        private static void AddModelInCache(string modelAssetPath)
        {
            var guid  = AssetDatabase.AssetPathToGUID(modelAssetPath);
            var asset = APResources.GetAPAssetByPath(APAssetType.Model, guid);

            APCache.SetValue(APAssetType.Model, guid, asset);
            SyncManager.AddedAssets.Enqueue(asset);

            var animationClipAssetids = APResources.GetAnimationClipAssetIdInModel(modelAssetPath);

            foreach (var id in animationClipAssetids)
            {
                var clip = APResources.GetAPAssetByPath(APAssetType.AnimationClip, id);
                APCache.SetValue(APAssetType.AnimationClip, id, clip);
                SyncManager.AddedAssets.Enqueue(clip);
            }
        }
Ejemplo n.º 24
0
        private static void HandleImportedAssets(string[] importedAssets)
        {
            foreach (var assetPath in importedAssets)
            {
                var id = AssetDatabase.AssetPathToGUID(assetPath);

                if (!APCache.HasAsset(id))
                {
                    AddNewImportAssets(assetPath);
                }
                else
                {
                    UpdateReimportExistAssets(assetPath);
                }
            }

            webCommunicationService.RefreshIconCache();
        }
        public void UpdateObjectsIntoCache(APAssetType type, string assetid, Queue <APAsset> modifedAssets = null)
        {
            APAsset asset = APResources.GetAPAssetByPath(type, assetid);

            if (APCache.HasAsset(type, assetid))
            {
                var previousAssets = APCache.GetValue(type, assetid);
                if (asset != null && previousAssets != null)
                {
                    asset.Used = previousAssets.Used;
                    APCache.SetValue(type, assetid, asset);
                    if (modifedAssets != null)
                    {
                        modifedAssets.Enqueue(asset);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        public static void AddToBlacklist()
        {
            List <APAsset> newBlacklist = new List <APAsset>();

            foreach (var item in Selection.objects)
            {
                var path = GetPathOfSelectedAssets(item);
                if (!APCache.ExistsInBlacklist(path))
                {
                    var asset = APResources.GetBlackListAPAsset(path);
                    APCache.AddToBlacklist(path, asset);
                    newBlacklist.Add(asset);
                }
            }

            AssetNotification.webCommunicationService.AddAssets(newBlacklist);
            APCache.CommitBlacklistChange();
        }
Ejemplo n.º 27
0
        public static List <APOtherFile> GetOthers()
        {
            List <APOtherFile> files = new List <APOtherFile>();
            var allfiles             = Utility.GetFilesInRelativePath(Application.dataPath);

            foreach (var file in allfiles)
            {
                string filePath = "Assets" + file;
                var    guid     = AssetDatabase.AssetPathToGUID(filePath);
                if (APCache.HasAsset(guid))
                {
                    continue;
                }

                files.Add(GetOtherFile(filePath));
            }

            return(files);
        }
Ejemplo n.º 28
0
        private static void UpdateModelInCache(string modelAssetPath)
        {
            var guid = AssetDatabase.AssetPathToGUID(modelAssetPath);

            webCommunicationService.UpdateObjectsIntoCache(APAssetType.Model, guid, SyncManager.ModifiedAssets);

            var animationsInCache = APCache.GetAssetsListByTypeFromCache <APAnimation>(APAssetType.AnimationClip);
            HashSet <string> animationsAssetIdInCache = new HashSet <string>();

            foreach (var animation in animationsInCache)
            {
                if (animation.Id.ToLower().Contains(guid.ToLower()))
                {
                    animationsAssetIdInCache.Add(animation.Id);
                }
            }

            var clipIds = APResources.GetAnimationClipAssetIdInModel(modelAssetPath);

            foreach (var id in clipIds)
            {
                if (animationsAssetIdInCache.Contains(id))
                {
                    webCommunicationService.UpdateObjectsIntoCache(APAssetType.AnimationClip, id, SyncManager.ModifiedAssets);
                }
                else
                {
                    var clip = APResources.GetAPAssetByPath(APAssetType.AnimationClip, id);
                    APCache.SetValue(APAssetType.AnimationClip, id, clip);
                    SyncManager.AddedAssets.Enqueue(clip);
                }
            }

            foreach (var id in animationsAssetIdInCache)
            {
                if (!clipIds.Contains(id))
                {
                    var clip = APCache.GetValue(APAssetType.AnimationClip, id);
                    APCache.Remove(id);
                    SyncManager.DeleteAssets.Enqueue(clip);
                }
            }
        }
Ejemplo n.º 29
0
        public static void RemoveBlacklist()
        {
            List <APAsset> deleteAssets = new List <APAsset>();

            foreach (var item in Selection.objects)
            {
                var path = GetPathOfSelectedAssets(item);
                if (APCache.ExistsInBlacklist(path))
                {
                    var asset = APResources.GetBlackListAPAsset(path);
                    APCache.RemoveFromBlacklist(path);
                    Utility.UpdateJsonInAsset(asset);
                    deleteAssets.Add(asset);
                }
            }

            AssetNotification.webCommunicationService.DeleteAssets(deleteAssets.ToArray().ToList());;
            APCache.CommitBlacklistChange();
        }
Ejemplo n.º 30
0
            static PrepareOnLoad()
            {
                Utility.DebugLog("Executing PrepareOnLoad");
                webCommunicationService           = ScriptableObject.CreateInstance <WebViewCommunicationService>();
                webCommunicationService.hideFlags = HideFlags.HideAndDontSave;

                EditorApplication.update += BackgroundUpdate;
                EditorApplication.playmodeStateChanged += PlaymodeStateChanged;

                time = EditorApplication.timeSinceStartup;
                bool hasLoadFromLocalKey = EditorPrefs.HasKey(APCache.LOAD_FROM_LOCAL_KEY);


                if (PreferencesItems.AutoRefreshCacheOnProjectLoad)
                {
                    APCache.LoadDataIntoCache(CheckUnusedState);
                }
                else
                {
                    if (hasLoadFromLocalKey ||
                        EditorApplication.isPlayingOrWillChangePlaymode ||
                        EditorApplication.isCompiling)
                    {
                        if (!APCache.LoadFromLocal())
                        {
                            APCache.LoadDataIntoCache(CheckUnusedState);
                        }
                        else
                        {
                            CheckUnusedState();
                        }
                    }
                    else
                    {
                        if (!APCache.LoadFromLocal())
                        {
                            APCache.LoadDataIntoCache(CheckUnusedState);
                        }
                    }
                }
            }