Ejemplo n.º 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);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 9
0
 //============================================================
 public AssetFileProxy CopyTo(AbsPath path)
 {
     AssetDatabase.CopyAsset(Path, path.PathStr.GetPathUnderProjectFolder()).Assert();
     return(new AssetFileProxy(new FilePath(path.PathStr)));
 }
Ejemplo n.º 10
0
 public static void ImportPackage(AbsPath path, bool interactive = true)
 {
     AssetDatabase.ImportPackage(path.PathStr, interactive);
 }
Ejemplo n.º 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)));
        }
Ejemplo n.º 12
0
 public static AssetFileProxy CreateAsset(this AbsPath path, UnityEngine.Object obj)
 {
     AssetDatabase.CreateAsset(obj, path.PathStr);
     return(new AssetFileProxy(new FilePath(path)));
 }
Ejemplo n.º 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)
        {
        }
Ejemplo n.º 14
0
        public void SaveTIfExist()
        {
            string jsonContent = instance.ToNewtonJson();

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