public static void FindRGBA() { TextureImporterFormat[] formatConfig = new TextureImporterFormat[] { TextureImporterFormat.RGBA32, TextureImporterFormat.RGB24, TextureImporterFormat.ARGB32, }; HashSet <TextureImporterFormat> filter = new HashSet <TextureImporterFormat>(formatConfig); foreach (string atlasFile in EditorResourcePaths.GetAllAtlasFiles()) { if (atlasFile.EndsWith(LOW_ATLAS_SUFFIX)) { continue; } SpriteAtlas spriteAtlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlasFile); for (int i = 2; i < PLATFORMS.Length; i++) { TextureImporterPlatformSettings patformSettings = SpriteAtlasExtensions.GetPlatformSettings(spriteAtlas, PLATFORMS[i]); if (patformSettings.overridden && filter.Contains(patformSettings.format)) { DebugUtil.LogWarning("高清图集 : " + atlasFile); break; } } } DebugUtil.Log("FindRGBA Done!"); }
static HashSet <string> GetSelectionsBySamples(List <PathPattern> fileSamples, List <PathPattern> dirSamples) { List <PathPattern> samples = new List <PathPattern>(); samples.AddRange(fileSamples); samples.AddRange(dirSamples); HashSet <string> hash = new HashSet <string>(); for (int i = 0; i < samples.Count; i++) { PathPattern sample = samples[i]; if (!Directory.Exists(sample.dir)) { DebugUtil.LogWarning("The directory isn't exist : " + sample.dir); continue; } string[] entries; if (i < fileSamples.Count) { entries = FilePathTools.SelectEntries(FilePathTools.GetFiles(sample.dir, sample.regex, sample.searchOption), FILTER_META_REGEX); } else { entries = FilePathTools.GetDirectories(sample.dir, sample.regex, sample.searchOption); } hash.UnionWith(entries); DebugUtil.Log("\"" + EditorCommonUtils.NormalizeDirectory(sample.dir) + sample.regex + "\" match " + (i < fileSamples.Count ? "files" : "directories") + " : " + entries.Length); } return(hash); }
static void CheckConflictBySelect() { foreach (string file in EditorResourcePaths.GetFileSelections()) { string text = System.IO.File.ReadAllText(file); if (text.IndexOf(">>>>>>>") != -1) { DebugUtil.LogWarning(file + " is Conflict"); } } }
static void CheckAlphaBySelect() { foreach (string file in EditorResourcePaths.GetTextureFiles(EditorResourcePaths.GetFileSelections())) { Texture2D texture = EditorCommonUtils.ReadTexture(file); if (ContainAlpha(texture)) { DebugUtil.LogWarning("该图片包含透明通道: " + file); } } }
public static void CheckETC2() { foreach (string file in EditorResourcePaths.GetSpriteFiles()) { Texture2D texture = EditorCommonUtils.ReadTexture(file); if (texture.width % 4 != 0 || texture.height % 4 != 0) { DebugUtil.LogWarning("该图片不满足Android的压缩格式 : " + file); } } DebugUtil.Log("CheckETC2 Done!"); }
public static byte[] ReadBytes(string name) { try { return(File.ReadAllBytes(name)); } catch (Exception e) { DebugUtil.LogWarning("Read bytes failed : " + name + "\n" + e); return(null); } }
public static bool WriteBytes(string name, byte[] bytes) { try { CreateDirectory(Path.GetDirectoryName(name)); File.WriteAllBytes(name, bytes); return(true); } catch (Exception e) { DebugUtil.LogWarning("Write bytes failed : " + name + "\n" + e); return(false); } }
static void DumpExtraFontDeps() { //预制件资源只能依赖英文字体,导出依赖了其它字体的预制件 Dictionary <string, HashSet <string> > errors = new Dictionary <string, HashSet <string> >(); Object cur = Selection.activeObject; string path = AssetDatabase.GetAssetPath(cur); if (!Directory.Exists(path)) { DebugUtil.LogError("请选择文件夹!!!"); } string[] prefabs = AssetDatabase.FindAssets("t:Prefab", new[] { path }); foreach (var p in prefabs) { string[] deps = AssetDatabase.GetDependencies(AssetDatabase.GUIDToAssetPath(p)); foreach (var d in deps) { Object obj = AssetDatabase.LoadMainAssetAtPath(d); if (obj.GetType() == typeof(TMPro.TMP_FontAsset) && !obj.name.ToLower().Equals("LocaleFont_En SDF".ToLower()) && !obj.name.ToLower().Equals("LiberationSans SDF".ToLower()))//有其他跟友好的识别是否是英文? { HashSet <string> sets; if (!errors.TryGetValue(d, out sets)) { sets = new HashSet <string>(); errors.Add(d, sets); } sets.Add(p); } } } if (errors.Count == 0) { DebugUtil.Log("空"); } else { foreach (var p in errors) { DebugUtil.LogWarning(string.Format("字体:{0}", p.Key)); foreach (var d in p.Value) { DebugUtil.Log(AssetDatabase.GUIDToAssetPath(d)); } } } }
public Type Notification <Type>() where Type : Subject <Type>, new() { var notification = container.Trigger <Type>(); if (notification != null) { return(notification); } else { // Dummy notification DebugUtil.LogWarning("No one subscribes to the notification: " + typeof(Type).Name); return(new Type()); } }
static void CheckPrefabBySelect() { var atlasSprites = EditorResourcePaths.GetAllSpriteFilesInAtlas(); foreach (string file in EditorResourcePaths.GetFileSelections()) { if (file.EndsWith(".prefab")) { var sprites = EditorResourcePaths.GetDependencies(new string[] { file }, EditorResourcePaths.PNG_REGEX); foreach (var sprite in sprites) { if (!atlasSprites.Contains(sprite)) { DebugUtil.LogWarning(file + " 包含散图 " + sprite); } } } } }
private static void CallActivityFunction(string methodName, params object[] args) { #if UNITY_ANDROID if (Application.platform != RuntimePlatform.Android) { return; } try { AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity"); jo.Call(methodName, args); //jo.Call("runOnUiThread", new AndroidJavaRunnable(() => { jo.Call(methodName, args); })); } catch (System.Exception ex) { DebugUtil.LogWarning(ex.Message); } #endif }
public static bool CreateDirectory(string path) { if (string.IsNullOrEmpty(path)) { return(true); } try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } return(true); } catch (Exception e) { DebugUtil.LogWarning("Create directory failed : " + path + "\n" + e); return(false); } }
static void FindReferencesBySelect() { var dependenciesDict = new Dictionary <string, HashSet <string> >(); foreach (var prefab in EditorResourcePaths.GetAllPrefabFiles()) { dependenciesDict[prefab] = new HashSet <string>(AssetDatabase.GetDependencies(prefab, false)); } HashSet <string> fileSet = new HashSet <string>(EditorResourcePaths.GetFileSelections()); foreach (string file in fileSet) { foreach (string prefab in dependenciesDict.Keys) { if (!fileSet.Contains(prefab) && dependenciesDict[prefab].Contains(file)) { DebugUtil.LogWarning(file + " References By " + prefab); } } } }
public static bool Subscribe <Type>(this GameObject _this, IEventHandler <Type> handler) where Type : Subject <Type>, new() { if (_this != null) { UnitySubject nc = _this.GetComponent <UnitySubject>(); if (nc) { return(nc.Subscribe <Type>(handler)); } else { DebugUtil.LogWarning("[GameObject_UnitySubject] This game object does not have UnitySubject component. " + _this); return(false); } } else { DebugUtil.LogWarning("[GameObject_UnitySubject] The game object is null."); return(false); } }
public static bool MoveFile(string srcPath, string destPath) { if (srcPath == destPath) { return(true); } try { CreateDirectory(Path.GetDirectoryName(destPath)); if (File.Exists(srcPath)) { File.Delete(destPath); File.Move(srcPath, destPath); } return(true); } catch (Exception e) { DebugUtil.LogWarning("Move file failed : " + srcPath + " --> " + destPath + "\n" + e); return(false); } }
public static Type Notification <Type>(this GameObject _this) where Type : Subject <Type>, new() { if (_this != null) { UnitySubject nc = _this.GetComponent <UnitySubject>(); if (nc) { Type ret = nc.Notification <Type>(); return(ret); } else { DebugUtil.LogWarning("[GameObject_UnitySubject] This game object does not have UnitySubject component. " + _this); } } else { DebugUtil.LogWarning("[GameObject_UnitySubject] The game object is null."); } // return a dummy instance as fallback, which should not happened under any circumstances, theoretically return(new Type()); }