Esempio n. 1
0
        private void GetEditorPerfsValue(string key, object callback)
        {
            var value = EditorPrefs.GetString(key);

            wrap = new CallbackWrapper(callback);
            wrap.Send(value);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the texture and return the DESC sort order
        /// </summary>
        private void GetResByType(string message, object callback)
        {
#if APLUS_DEV
            var now = DateTime.Now;
#endif
            if (string.IsNullOrEmpty(message))
            {
                throw new Exception("no message provide");
            }

            string json = "[]";

            switch (message.ToLower())
            {
            case AssetType.TEXTURES:
                json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Texture);
                break;

            case AssetType.MOVIES:
                json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.MovieTexture);
                break;

            default:
                break;
            }

            json = CLZF2_Base64(json);
            wrap = new CallbackWrapper(callback);
            wrap.Send(json);

#if APLUS_DEV
            Utility.DebugLog(String.Format("Load Res {0} cost {1} ms", message, (DateTime.Now - now).TotalMilliseconds));
#endif
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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;
                    }
                }

                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();
            }
        }