示例#1
0
        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);
        }
示例#2
0
 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);
     }
 }
示例#3
0
 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);
     }
 }
示例#4
0
 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();
     }
 }
示例#5
0
        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);
            }
        }
示例#6
0
 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);
     }
 }
示例#7
0
 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);
         }
     }
 }
示例#8
0
        //============================================================

        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);
        }
示例#9
0
 //============================================================
 public AssetFileProxy CopyTo(AbsPath path)
 {
     AssetDatabase.CopyAsset(Path, path.PathStr.GetPathUnderProjectFolder()).Assert();
     return(new AssetFileProxy(new FilePath(path.PathStr)));
 }
示例#10
0
 public static void ImportPackage(AbsPath path, bool interactive = true)
 {
     AssetDatabase.ImportPackage(path.PathStr, interactive);
 }
示例#11
0
        public static AssetFileProxy CreateAssetFolder(this AbsPath path)
        {
            string dirGuid = AssetDatabase.CreateFolder(path.PathStr.GetParentPath().GetPathUnderProjectFolder(), path.FileName);

            return(new AssetFileProxy(new FilePath(path)));
        }
示例#12
0
 public static AssetFileProxy CreateAsset(this AbsPath path, UnityEngine.Object obj)
 {
     AssetDatabase.CreateAsset(obj, path.PathStr);
     return(new AssetFileProxy(new FilePath(path)));
 }
示例#13
0
        //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)
        {
        }
示例#14
0
        public void SaveTIfExist()
        {
            string jsonContent = instance.ToNewtonJson();

            AbsPath.WriteTextAssetContentStr(jsonContent);
        }
示例#15
0
 // called when delete file or for source of moving file
 protected virtual void OnDelete(AbsPath path)
 {
 }
示例#16
0
 // 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)
 {
 }
示例#17
0
 // 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)
 {
 }