예제 #1
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);
            }
        }
        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()));
        }
        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);
                    }
                }
            }
        }
예제 #4
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();
        }
예제 #5
0
        private static void SelectAssetTypeInSelection(string assetType)
        {
            List <UnityEngine.Object> objects = new List <UnityEngine.Object>();

            foreach (var obj in Selection.objects)
            {
                if (assetType.Equals(APResources.GetAssetTypeByObject(obj), StringComparison.CurrentCultureIgnoreCase))
                {
                    objects.Add(obj);
                }
            }

            Selection.objects = objects.ToArray();
            if (Event.current != null)
            {
                Event.current.Use();
            }
        }
예제 #6
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();
        }
예제 #7
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);
                }
            }
        }
        public static bool ShowInAPlusEnable()
        {
            if (Selection.objects == null || Selection.objects.Length == 0)
            {
                return(false);
            }

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

            HashSet <string> types = new HashSet <string>();

            foreach (var item in Selection.objects)
            {
                types.Add(APResources.GetAssetTypeByObject(item));
            }

            return(types.Count() == 1 && !string.IsNullOrEmpty(types.ElementAt(0)));
        }
예제 #9
0
        public static void ShowInAPlus()
        {
            HashSet <string> types = new HashSet <string>();
            var ids = Selection.objects.Select(o =>
            {
                var path    = AssetDatabase.GetAssetPath(o);
                var assetid = AssetDatabase.AssetPathToGUID(path);
                if (o is AnimationClip)
                {
                    if (!path.EndsWith(".anim"))
                    {
                        assetid = Utility.GetAssetId(assetid, Utility.GetLocalIndentifierOfObject(o).ToString());
                    }
                }

                types.Add(APResources.GetAssetTypeByObject(o));
                return(assetid);
            }).ToArray();

            if (types.Count > 1)
            {
                string message = "This actions does not support multiple assets type. Please use 'Select in Selection' in Assets menu to select one type.";
                EditorUtility.DisplayDialog("Not Support Action", message, "OK");
                return;
            }

            if (types.Count == 1)
            {
                var assetType = types.ElementAt(0);
                if (string.IsNullOrEmpty(assetType))
                {
                    string message = "The assets selected are not supported in currect version.";
                    EditorUtility.DisplayDialog("Not Support Assets", message, "OK");
                    return;
                }

                AssetNotification.webCommunicationService.SetCurrentURL(string.Format("res/{0}", types.ElementAt(0)), string.Format("Id:{0}", string.Join("|", ids)));
            }
        }
예제 #10
0
            private static bool HandleRenderTextureOnSelection(UnityEngine.Object obj)
            {
                string assetPath = AssetDatabase.GetAssetPath(obj);
                string guid      = AssetDatabase.AssetPathToGUID(assetPath);
                var    rtInCache = APCache.GetValue(guid) as APTexture;

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

                var rtCurrent = APResources.GetAPTextureFromAssetGuid(guid);

                if (rtInCache.Width != rtCurrent.Width ||
                    rtInCache.Height != rtCurrent.Height ||
                    rtInCache.MipMap != rtCurrent.MipMap)
                {
                    webCommunicationService.UpdateObjectsIntoCache(APAssetType.Texture, AssetDatabase.AssetPathToGUID(assetPath), SyncManager.ModifiedAssets);
                    return(true);
                }

                return(false);
            }
예제 #11
0
        private static void HandleMovedAssets(string[] movedAssets, string[] movedFromAssetPaths)
        {
            for (var i = 0; i < movedAssets.Length; i++)
            {
                Utility.DebugLog(string.Format("moved {0} to {1}", movedFromAssetPaths[i], movedAssets[i]));
                var sid = AssetDatabase.AssetPathToGUID(movedAssets[i]);
                if (Utility.IsModelPath(movedAssets[i]))
                {
                    var clipIds = APResources.GetAnimationClipAssetIdInModel(movedAssets[i]);
                    foreach (var id in clipIds)
                    {
                        APCache.MoveTo(sid, movedAssets[i]);
                        var clip = APCache.GetValue(APAssetType.AnimationClip, id);
                        SyncManager.MovedFromAssets.Enqueue(id);
                        SyncManager.MovedToAssets.Enqueue(clip);
                    }
                }

                APCache.MoveTo(sid, movedAssets[i]);
                var asset = APCache.GetValue(sid);
                SyncManager.MovedFromAssets.Enqueue(sid);
                SyncManager.MovedToAssets.Enqueue(asset);
            }
        }
예제 #12
0
        private static void LoadResourcesIntoCache(APAssetType type)
        {
            IList assets = null;
            Dictionary <string, APAsset> dict = new Dictionary <string, APAsset>();

            switch (type)
            {
            case APAssetType.Font:
                assets = APResources.GetFonts();
                break;

            case APAssetType.MovieTexture:
                assets = APResources.GetMovies();
                break;

            case APAssetType.Texture:
                assets = APResources.GetTextures();
                break;

            case APAssetType.Model:
                assets = APResources.GetModels();
                break;

            case APAssetType.AudioClip:
                assets = APResources.GetAudios();
                break;

            case APAssetType.Material:
                assets = APResources.GetMaterials();
                break;

            case APAssetType.Shader:
                assets = APResources.GetShaders();
                break;

            case APAssetType.AnimationClip:
                assets = APResources.GetAnimations();
                break;

            case APAssetType.Prefab:
                assets = APResources.GetPrefabs();
                break;

            case APAssetType.StreamingAssets:
                assets = APResources.GetStreamingAssets();
                break;

            case APAssetType.Script:
                assets = APResources.GetCodeFiles();
                break;

            case APAssetType.Blacklist:
                assets = blacklistStorage.GetAssets();
                break;

            case APAssetType.Others:
                assets = APResources.GetOthers();
                break;
            }

            if (assets == null)
            {
                return;
            }

            foreach (var item in assets)
            {
                var asset = item as APAsset;
                if (asset == null)
                {
                    break;
                }

                Utility.UpdateJsonInAsset(asset);

                if (!dict.ContainsKey(asset.Id))
                {
                    dict.Add(asset.Id, asset);
                }
                else
                {
                    dict[asset.Id] = asset;
                }
            }

            int key = (int)type;

            if (AssetsCache.ContainsKey(key))
            {
                AssetsCache[key] = dict;
            }
            else
            {
                AssetsCache.Add(key, dict);
            }
        }
        private void RenameAssets(string assets, object callback)
        {
            Utility.DebugLog(string.Format("Rename {0}", assets));

            if (string.IsNullOrEmpty(assets))
            {
                return;
            }

            string[] temp = assets.Split(new char[] { ']', '[' }, StringSplitOptions.RemoveEmptyEntries);
            if (temp.Length != 3)
            {
                return;
            }

            var assetIds = temp[0].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var newNames = temp[2].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            string title    = "Renaming";
            float  progress = 0;

            if (assetIds.Length == newNames.Length)
            {
                int changedCount = 0;
                int passCount    = 0;
                Dictionary <string, List <long> >   fileIdMaps  = new Dictionary <string, List <long> >();
                Dictionary <string, List <string> > newNamesMap = new Dictionary <string, List <string> >();

                for (int i = 0; i < assetIds.Length; i++)
                {
                    if (Utility.IsSubAsset(assetIds[i]))
                    {
                        var  guid        = Utility.GetGuidFromAssetId(assetIds[i]);
                        var  fileId      = Utility.GetFileIdFromAssetId(assetIds[i]);
                        long fileId_long = -1;

                        if (long.TryParse(fileId, out fileId_long))
                        {
                            if (fileIdMaps.ContainsKey(guid))
                            {
                                fileIdMaps[guid].Add(fileId_long);
                                newNamesMap[guid].Add(newNames[i]);
                            }
                            else
                            {
                                fileIdMaps.Add(guid, new List <long>()
                                {
                                    fileId_long
                                });
                                newNamesMap.Add(guid, new List <string>()
                                {
                                    newNames[i]
                                });
                            }
                        }
                        else
                        {
                            passCount++;
                        }
                        continue;
                    }

                    var           assetPath = AssetDatabase.GUIDToAssetPath(assetIds[i]);
                    AssetImporter importer  = AssetImporter.GetAtPath(assetPath);
                    if (importer.ToString().Contains("UnityEngine.NativeFormatImporter"))
                    {
                        SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(assetPath));
                        serializedObject.targetObject.name = newNames[i];
                        serializedObject.ApplyModifiedProperties();
                        AssetDatabase.SaveAssets();
                    }

                    var errorMessage = AssetDatabase.RenameAsset(AssetDatabase.GUIDToAssetPath(assetIds[i]), newNames[i]);
                    if (string.IsNullOrEmpty(errorMessage))
                    {
                        changedCount++;
                    }
                    else
                    {
                        Debug.LogWarning(errorMessage);
                    }

                    progress = (changedCount + passCount) * 1.0f / assetIds.Length;
                    if (EditorUtility.DisplayCancelableProgressBar(title, assetIds[i], progress))
                    {
                        wrap = new CallbackWrapper(callback);
                        wrap.Send("done");
                        EditorUtility.ClearProgressBar();
                        return;
                    }
                }

                foreach (var keyVal in fileIdMaps)
                {
                    var modelPath = AssetDatabase.GUIDToAssetPath(keyVal.Key);
                    APResources.RenameAnimationClipInFbx(modelPath, keyVal.Value.ToArray(), newNamesMap[keyVal.Key].ToArray(), ref changedCount);
                    progress = (changedCount + keyVal.Value.Count + passCount) * 1.0f / assetIds.Length;
                    if (EditorUtility.DisplayCancelableProgressBar(title, keyVal.Key, progress))
                    {
                        wrap = new CallbackWrapper(callback);
                        wrap.Send("done");
                        EditorUtility.ClearProgressBar();
                        return;
                    }
                }

                AssetDatabase.Refresh();

                int    errorCount = assetIds.Length - passCount - changedCount;
                string msg        = string.Format("{0} Success, {1} Failed, {2} Passed", changedCount, errorCount, passCount);
                EditorUtility.DisplayDialog("Bulk Rename Result", msg, "OK");

                wrap = new CallbackWrapper(callback);
                wrap.Send("done");
                EditorUtility.ClearProgressBar();
            }
        }
예제 #14
0
        public static void FindReferences()
        {
            HashSet <string> references = new HashSet <string>();
            var objects    = Selection.objects;
            var scriptsMap = APResources.GetMonoScriptsMap();

            bool Cancel = false;

            for (int i = 0; i < objects.Length; i++)
            {
                var    path             = AssetDatabase.GetAssetPath(objects[i]);
                string message          = "Find references of " + path;
                var    referencesAssets = APCache.GetReferences(path, message, i * 1f / objects.Length, (i + 1) * 1f / objects.Length, ref Cancel);

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

                if (objects[i] is ScriptableObject || objects[i] is MonoScript)
                {
                    Type msType = null;
                    if (objects[i] is ScriptableObject)
                    {
                        msType = (objects[i] as ScriptableObject).GetType();
                    }

                    if (objects[i] is MonoScript)
                    {
                        msType = (objects[i] as MonoScript).GetClass();
                    }

                    if (msType != null)
                    {
                        msType
                        .GetFields(ReflectionUtils.BIND_FLAGS)
                        .ToList()
                        .ForEach(f =>
                        {
                            if (scriptsMap.ContainsKey(f.FieldType.ToString()))
                            {
                                references.Add(scriptsMap[f.FieldType.ToString()]);
                            }
                        });
                    }
                }

                if (Cancel)
                {
                    break;
                }
            }

            if (!Cancel)
            {
                SelectReferences(references.ToList());
            }
            else
            {
                EditorUtility.ClearProgressBar();
            }
        }
예제 #15
0
        private static void AddNewImportAssets(string assetPath)
        {
            Utility.DebugLog(string.Format("New: {0}", assetPath));

            if (!File.Exists(assetPath) && Directory.Exists(assetPath))
            {
                return;
            }

            if (Utility.IsStreamingAssetsFile(assetPath))
            {
                APStreamingAssetsFile file = APResources.GetStreamingAssetFile(assetPath);
                APCache.Add(APAssetType.StreamingAssets, file.Id, file);
                SyncManager.AddedAssets.Enqueue(file);
                return;
            }
            else if (Utility.IsCodeFile(assetPath))
            {
                APCodeFile codeFile = APResources.GetCodeFile(assetPath);
                APCache.Add(APAssetType.Script, codeFile.Id, codeFile);
                SyncManager.AddedAssets.Enqueue(codeFile);
                return;
            }

            var guid = AssetDatabase.AssetPathToGUID(assetPath);

            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));

            APAsset asset = null;

            // if new path
            //
            if (obj is Texture)
            {
                if (obj is MovieTextureType)
                {
                    var movie = APResources.GetAPAssetByPath(APAssetType.MovieTexture, guid);
                    if (movie != null)
                    {
                        APCache.SetValue(APAssetType.MovieTexture, movie.Id, movie);
                    }
                    SyncManager.AddedAssets.Enqueue(movie);
                    return;
                }

                asset = APResources.GetAPAssetByPath(APAssetType.Texture, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Texture, asset.Id, asset);
                }
            }
            else if (Utility.IsModels(obj, assetPath))
            {
                AddModelInCache(assetPath);
                return;
            }
            else if (obj is AnimationClip)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.AnimationClip, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.AnimationClip, asset.Id, asset);
                }
            }
            else if (obj is AudioClip)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.AudioClip, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.AudioClip, asset.Id, asset);
                }
            }
            else if (obj is Font)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.Font, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Font, asset.Id, asset);
                }
            }
            else if (obj is Shader)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.Shader, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Shader, asset.Id, asset);
                }
            }
            else if (obj is Material || obj is PhysicMaterial || obj is PhysicsMaterial2D)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.Material, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Material, asset.Id, asset);
                }
            }
            else if (Utility.IsPrefab(assetPath))
            {
                asset = APResources.GetAPAssetByPath(APAssetType.Prefab, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Prefab, asset.Id, asset);
                }
            }
            else
            {
                if (assetPath.ToLower().StartsWith("assets"))
                {
                    asset = APResources.GetOtherFile(assetPath);
                    if (asset != null)
                    {
                        APCache.Add(APAssetType.Others, asset.Id, asset);
                    }
                }
            }

            if (asset != null)
            {
                SyncManager.AddedAssets.Enqueue(asset);
            }

            Utility.DebugLog("New object type = " + obj);
        }