//----- method ----- private static T GetInstance() { if (instance == null) { instance = LoadInstance(); } if (instance == null) { return(null); } var assetPath = AssetDatabase.GetAssetPath(instance); var path = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); var time = File.GetLastWriteTime(path); var update = !instance.lastWriteTime.HasValue || instance.lastWriteTime.Value != time; if (update) { if (onReload != null) { onReload.OnNext(Unit.Default); } instance = LoadInstance(); instance.lastWriteTime = time; } return(instance); }
private void CalcPerformance(DicingTexture dicingTexture) { calcPerformance = false; if (dicingTexture != null) { var assetPath = AssetDatabase.GetAssetPath(dicingTexture); var fullPath = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); var fileInfo = new FileInfo(fullPath); infoFileSize = (float)fileInfo.Length / MB; } else { return; } var textures = dicingTexture.GetAllDicingSource() .Select(x => AssetDatabase.GUIDToAssetPath(x.guid)) .Select(x => AssetDatabase.LoadMainAssetAtPath(x) as Texture2D) .Where(x => x != null) .ToArray(); // 消費メモリサイズを計測. totalMemSize = 0; textures.ForEach(x => { var mem = Mathf.NextPowerOfTwo(x.width) * Mathf.NextPowerOfTwo(x.height); mem *= !x.alphaIsTransparency ? 3 : 4; totalMemSize += mem; }); totalMemSize /= MB; if (dicingTexture.Texture != null) { var mem = Mathf.NextPowerOfTwo(dicingTexture.Texture.width) * Mathf.NextPowerOfTwo(dicingTexture.Texture.height); mem *= !dicingTexture.Texture.alphaIsTransparency ? 3 : 4; totalAtlasMemSize = (float)mem / MB; } // ファイルサイズ. totalFileSize = 0f; textures.Select(x => AssetDatabase.GetAssetPath(x)) .Select(x => UnityPathUtility.ConvertAssetPathToFullPath(x)) .Select(x => new FileInfo(x)) .ForEach(x => totalFileSize += (float)x.Length / MB); if (dicingTexture.Texture != null) { var assetPath = AssetDatabase.GetAssetPath(dicingTexture.Texture); var fullPath = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); var fileInfo = new FileInfo(fullPath); atlasFileSize = (float)fileInfo.Length / MB; } calcPerformance = true; }
private static Object GenerateScriptableObject(Type type, string assetPath) { assetPath = Path.ChangeExtension(assetPath, AssetFileExtension); var instance = AssetDatabase.LoadAssetAtPath(assetPath, type); if (instance == null) { var path = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); if (!File.Exists(path)) { instance = CreateInstance(type); var directory = Path.GetDirectoryName(path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } AssetDatabase.CreateAsset(instance, assetPath); AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } return(instance); }
// 元になったテクスチャ情報構築. private DicingSourceData[] BuildDicingSourceData(DicingTargetData[] targetDatas) { var result = new List <DicingSourceData>(); foreach (var targetData in targetDatas) { var texture = targetData.texture; var assetPath = AssetDatabase.GetAssetPath(texture); var fullPath = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); var item = new DicingSourceData() { textureName = Path.GetFileNameWithoutExtension(assetPath), guid = AssetDatabase.AssetPathToGUID(assetPath), lastUpdate = File.GetLastWriteTime(fullPath).ToUnixTime(), width = texture.width, height = texture.height, xblock = targetData.bx, yblock = targetData.by, blockIds = targetData.blocks.Select(x => x.blockId).ToArray(), }; result.Add(item); } return(result.ToArray()); }
public long GetFileSize() { if (!fileSize.HasValue) { var filePath = UnityPathUtility.ConvertAssetPathToFullPath(AssetPath); fileSize = File.Exists(filePath) ? new FileInfo(filePath).Length : 0; } return(fileSize.Value); }
public void DeleteInvalidInfo() { var list = new List <ManageInfo>(); for (var i = 0; i < manageInfos.Length; i++) { var manageInfo = manageInfos[i]; if (manageInfo == null) { continue; } if (string.IsNullOrEmpty(manageInfo.guid)) { continue; } var assetPath = AssetDatabase.GUIDToAssetPath(manageInfo.guid); var path = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); var isFolder = AssetDatabase.IsValidFolder(assetPath); if (isFolder) { if (!Directory.Exists(path)) { continue; } } else { if (!File.Exists(path)) { continue; } } list.Add(manageInfo); } if (list.Count != manageInfos.Length) { manageInfos = list.ToArray(); UnityEditorUtility.SaveAsset(this); } }
//----- field ----- //----- property ----- //----- method ----- public static bool GenerateScript(string folderPath, string fileName, string script) { if (!AssetDatabase.IsValidFolder(folderPath)) { return(false); } var projectPath = UnityPathUtility.GetProjectFolderPath(); var folder = PathUtility.Combine(projectPath, folderPath); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var assetPath = PathUtility.Combine(folderPath, fileName); var fullPath = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); var requireUpdate = true; if (File.Exists(fullPath)) { using (var sr = new StreamReader(fullPath, Encoding.UTF8)) { var text = sr.ReadToEnd(); requireUpdate = text != script; } } if (requireUpdate) { File.WriteAllText(fullPath, script, Encoding.UTF8); AssetDatabase.ImportAsset(assetPath); } return(true); }
//----- method ----- private static T GetInstance() { if (instance == null) { instance = LoadInstance(); } if (instance == null) { return(null); } if (string.IsNullOrEmpty(instance.assetFullPath)) { var assetPath = AssetDatabase.GetAssetPath(instance); instance.assetFullPath = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); } var time = File.GetLastWriteTime(instance.assetFullPath); if (instance.lastWriteTime != time) { if (onReload != null) { onReload.OnNext(Unit.Default); } if (instance.lastWriteTime.HasValue) { instance = LoadInstance(); } instance.lastWriteTime = time; } return(instance); }
/// <summary> /// 初回インポートか確認. /// </summary> public bool IsFirstImport(string assetPath) { var firstImport = false; // 登録されていたら初回. firstImport |= firstImportAssets.Contains(assetPath); // .metaがなかったら初回. var metaFilePath = string.Empty; try { metaFilePath = UnityPathUtility.ConvertAssetPathToFullPath(assetPath) + UnityEditorUtility.MetaFileExtension; } catch (Exception) { return(false); } firstImport |= !File.Exists(metaFilePath); return(firstImport); }
// 元になったテクスチャ情報構築. private PatternData[] BuildPatternData(PatternTargetData[] targetDatas) { var result = new List <PatternData>(); foreach (var targetData in targetDatas) { var texture = targetData.texture; var assetPath = AssetDatabase.GetAssetPath(texture); var fullPath = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); var textureName = Path.GetFileNameWithoutExtension(assetPath); var assetGuid = AssetDatabase.AssetPathToGUID(assetPath); var lastUpdate = File.GetLastWriteTime(fullPath).ToUnixTime(); var width = texture.width; var height = texture.height; var blockIds = targetData.blocks.Select(x => x.blockId).ToArray(); var item = new PatternData(textureName, assetGuid, lastUpdate, width, height, targetData.bx, targetData.by, blockIds); result.Add(item); } return(result.OrderBy(x => x.TextureName, new NaturalComparer()).ToArray()); }
public void BuildTextureInfos() { // 選択中テクスチャ. var selectionTextures = Selection.objects != null? Selection.objects.OfType <Texture2D>().ToArray() : new Texture2D[0]; // パック済みのテクスチャは除外. if (selectDicingTexture != null) { selectionTextures = selectionTextures .Where(x => x != selectDicingTexture.Texture) .ToArray(); } var allDicingSource = selectDicingTexture != null? selectDicingTexture.GetAllDicingSource() : new DicingSourceData[0]; var textureInfoByGuid = new Dictionary <string, TextureInfo>(); foreach (var item in allDicingSource) { if (string.IsNullOrEmpty(item.guid)) { continue; } var assetPath = AssetDatabase.GUIDToAssetPath(item.guid); var texture = AssetDatabase.LoadMainAssetAtPath(assetPath) as Texture2D; var info = new TextureInfo(); info.status = texture != null ? TextureStatus.Exist : TextureStatus.Missing; if (info.status == TextureStatus.Exist) { var fullPath = UnityPathUtility.ConvertAssetPathToFullPath(assetPath); var lastUpdate = File.GetLastWriteTime(fullPath).ToUnixTime(); if (item.lastUpdate != lastUpdate) { info.status = TextureStatus.Update; } info.texture = texture; } textureInfoByGuid.Add(item.guid, info); } foreach (var texture in selectionTextures) { var assetPath = AssetDatabase.GetAssetPath(texture); var guid = AssetDatabase.AssetPathToGUID(assetPath); var info = textureInfoByGuid.GetValueOrDefault(guid); if (info == null) { info = new TextureInfo() { status = TextureStatus.Add, texture = texture, }; textureInfoByGuid.Add(guid, info); } else { textureInfoByGuid[guid].status = TextureStatus.Update; } } textureInfos = textureInfoByGuid.Values.ToArray(); CalcPerformance(selectDicingTexture); Repaint(); }