private void GetEditorPerfsValue(string key, object callback) { var value = EditorPrefs.GetString(key); wrap = new CallbackWrapper(callback); wrap.Send(value); }
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); }
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(); } }
/// <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.MODELS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Model); break; case AssetType.AUDIOS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.AudioClip); break; case AssetType.MOVIES: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.MovieTexture); break; case AssetType.FONTS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Font); break; case AssetType.MATERIALS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Material); break; case AssetType.SHADERS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Shader); break; case AssetType.ANIMATIONS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.AnimationClip); break; case AssetType.PREFABS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Prefab); break; case AssetType.STREAMING_ASSETS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.StreamingAssets); break; case AssetType.CODE: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Script); break; case AssetType.BLACKLIST: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Blacklist); break; case AssetType.OTHERS: json = APCache.GetAssetsLitJsonByTypeFromCache(APAssetType.Others); break; case "hierarchy": json = GetHierarchyAssetsListJson(); 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 }