public void MoveTo(AbsPath newPath) { string msg = AssetDatabase.ValidateMoveAsset(Path, newPath.PathStr.GetPathUnderProjectFolder()); (msg == "").Assert(msg); AssetDatabase.MoveAsset(Path, newPath.PathStr.GetPathUnderProjectFolder()); (msg == "").Assert(msg); }
public void SaveTIfExist() { Path.GetDirectoryName(AbsPath).CheckOrCreateDir(); AbsPath.CheckOrCreateFile(); using (FileStream stream = new FileStream(AbsPath, FileMode.OpenOrCreate)) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(stream, instance); } }
protected override void OnCreate(AbsPath path) { if (path.Extension == "" || allowedExtensions.Contains(path.Extension)) { RelPath relPath = path.ReplaceAsRelativePath(srcFolder); AbsPath destPath = destFolder.Combine(relPath); Console.WriteLine($"create '{relPath}' (from '{path.PathStr}' to '{destPath.PathStr}')"); path.CopyToFiltered(destPath, allowedExtensions); } }
protected override void OnDelete(AbsPath path) { if (path.Extension == "" || allowedExtensions.Contains(path.Extension)) { RelPath relPath = path.ReplaceAsRelativePath(srcFolder); Console.WriteLine($"delete '{relPath}'"); AbsPath destPath = destFolder.Combine(relPath); destPath.Delete(); } }
public void SaveTIfExist() { Path.GetDirectoryName(AbsPath).CheckOrCreateDir(); AbsPath.CheckOrCreateFile(); XmlSerializer xs = new XmlSerializer(typeof(T)); using (FileStream stream = new FileStream(AbsPath, FileMode.OpenOrCreate)) { xs.Serialize(stream, instance); } }
protected override void OnRename(AbsPath oldPath, AbsPath newPath) { // todo: test oldPath.Extension == "" for directory? if ((oldPath.Extension == "" && newPath.Extension == "") || (allowedExtensions.Contains(oldPath.Extension) && allowedExtensions.Contains(newPath.Extension))) { RelPath relOldPath = oldPath.ReplaceAsRelativePath(srcFolder); RelPath relNewPath = newPath.ReplaceAsRelativePath(srcFolder); AbsPath destOldPath = destFolder.Combine(relOldPath); AbsPath destNewPath = destFolder.Combine(relNewPath); Console.WriteLine($"rename '{relOldPath}' as '{relNewPath}' (from '{destOldPath}' to '{destNewPath}')"); destOldPath.RenameFullPath(destNewPath.PathStr); } }
protected override void OnChange(AbsPath path) { if (allowedExtensions.Contains(path.Extension)) { RelPath relPath = path.ReplaceAsRelativePath(srcFolder); Console.WriteLine($"change '{relPath}'"); AbsPath destPath = destFolder.Combine(relPath); if (path is FilePath srcFile) { if (destPath.Exists) { destPath.Delete(); } srcFile.CopyToFiltered(destPath, allowedExtensions); } } }
//============================================================ private static AbsPath GetPathByString(string fullPathStr) { AbsPath path; if (System.IO.Directory.Exists(fullPathStr)) { path = new FolderPath(fullPathStr); } else if (System.IO.File.Exists(fullPathStr)) { path = new FilePath(fullPathStr); } else { path = new AbsPath(fullPathStr); } return(path); }
//============================================================ public AssetFileProxy CopyTo(AbsPath path) { AssetDatabase.CopyAsset(Path, path.PathStr.GetPathUnderProjectFolder()).Assert(); return(new AssetFileProxy(new FilePath(path.PathStr))); }
public static void ImportPackage(AbsPath path, bool interactive = true) { AssetDatabase.ImportPackage(path.PathStr, interactive); }
public static AssetFileProxy CreateAssetFolder(this AbsPath path) { string dirGuid = AssetDatabase.CreateFolder(path.PathStr.GetParentPath().GetPathUnderProjectFolder(), path.FileName); return(new AssetFileProxy(new FilePath(path))); }
public static AssetFileProxy CreateAsset(this AbsPath path, UnityEngine.Object obj) { AssetDatabase.CreateAsset(obj, path.PathStr); return(new AssetFileProxy(new FilePath(path))); }
//public event Action<AbsolutePath> OnCreate; //public event Action<AbsolutePath, AbsolutePath> OnRename; //public event Action<AbsolutePath> OnChange; //public event Action<AbsolutePath> OnDelete; //============================================================ // following are only called/reported for most ancestor directory or file // called when create new file or for destination of moving file protected virtual void OnCreate(AbsPath path) { }
public void SaveTIfExist() { string jsonContent = instance.ToNewtonJson(); AbsPath.WriteTextAssetContentStr(jsonContent); }
// called when delete file or for source of moving file protected virtual void OnDelete(AbsPath path) { }
// called when any the watching directory's direct child file or directory is renamed or create or delete (including moving) // not called when child file's content is modified protected virtual void OnChange(AbsPath path) { }
// called only when in-place rename the basename of the wathcing file // not called when move file from one place to another protected virtual void OnRename(AbsPath oldPath, AbsPath newPath) { }