diff --git a/Assets/ZXL/Scripts/Manager/ZFileSystem.cs b/Assets/ZXL/Scripts/Manager/ZFileSystem.cs new file mode 100644 index 0000000..c5151f9 --- /dev/null +++ b/Assets/ZXL/Scripts/Manager/ZFileSystem.cs @@ -0,0 +1,7 @@ +namespace ZXL.Manager +{ + public class ZFileSystem + { + + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Manager/ZFileSystem.cs.meta b/Assets/ZXL/Scripts/Manager/ZFileSystem.cs.meta new file mode 100644 index 0000000..9ce9729 --- /dev/null +++ b/Assets/ZXL/Scripts/Manager/ZFileSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 63f2843889a64090a60431d1d84b908c +timeCreated: 1734501412 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS.meta b/Assets/ZXL/Scripts/Test/FS.meta new file mode 100644 index 0000000..9a97daf --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ea24213f7e924534aee9ed7f26f0ac48 +timeCreated: 1734501440 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/Directory.cs b/Assets/ZXL/Scripts/Test/FS/Directory.cs new file mode 100644 index 0000000..a3e0092 --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/Directory.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +namespace ZXLA +{ + class Directory : FileSystemObject + { + private List _childList; + + public Directory(string path, int depth, bool isDisplay = true) : base(path, depth, isDisplay) + { + fileType = FileObjectType.Directory; + _childList = new List(); + } + + public void AddChild(string child) + { + _childList.Add(child); + } + + public void RemoveChild(string child) + { + _childList.Remove(child); + } + + public List GetChildren() + { + return _childList; + } + + public void Rename(string newPath) + { + } + + public void MoveTo(string newPath) + { + } + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/Directory.cs.meta b/Assets/ZXL/Scripts/Test/FS/Directory.cs.meta new file mode 100644 index 0000000..f3e0b65 --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/Directory.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a73e26494a0a4a6ea696904f8b266978 +timeCreated: 1734501469 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/File.cs b/Assets/ZXL/Scripts/Test/FS/File.cs new file mode 100644 index 0000000..6a9fe82 --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/File.cs @@ -0,0 +1,10 @@ +namespace ZXLA +{ + class File : FileSystemObject + { + public File(string path, int depth, bool isDisplay = true) : base(path, depth, isDisplay) + { + fileType = FileObjectType.File; + } + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/File.cs.meta b/Assets/ZXL/Scripts/Test/FS/File.cs.meta new file mode 100644 index 0000000..4183eea --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/File.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d048818bfa77481cae5bc70c5e944327 +timeCreated: 1734501462 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/FileSystem.cs b/Assets/ZXL/Scripts/Test/FS/FileSystem.cs new file mode 100644 index 0000000..75c621d --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/FileSystem.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using ZXL; + +namespace ZXLA +{ + public enum FileOperationType + { + Create, + Rename, + Move, + Delete, + } + + public enum FileObjectType + { + File, + Directory + } + + public class FileSystem : MonoBehaviour, IFileSystem + { + private SortedDictionary dic = new SortedDictionary(); + public event Action OnCeateFile; + public event Action OnCeateDirectory; + public event Action OnFileSystemChanged; + + public void CreateFile(string path, int parentDepth) + { + dic.Add(path, new File(path, parentDepth + 1)); + OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.File, FileOperationType.Create, null, + path, null, null)); + } + + public bool FileExists(string path) + { + return dic.ContainsKey(path); + } + + public void RenameFile(string path, string newName) + { + var fileSystemObject = TmpFile(path); + DeleteFileInternal(path); + + var s = path.Split("/")[^1]; + var replace = path.Replace(s, newName); + dic.Add(replace, new File(replace, fileSystemObject.depth + 1, fileSystemObject.isDisplay)); + OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.File, + FileOperationType.Rename, null, replace, null, null)); + } + + public void MoveFile(string oldPath, string newPath) + { + var fileSystemObject = TmpFile(oldPath); + DeleteFileInternal(oldPath); + dic.Add(newPath, new File(newPath, fileSystemObject.depth + 1, fileSystemObject.isDisplay)); + OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.File, + FileOperationType.Move, null, newPath, null, null)); + } + + public void DeleteFile(string path) + { + DeleteFileInternal(path); + OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.File, FileOperationType.Delete, null, + path, null, null)); + } + + /// + /// 缓存一下 + /// + FileSystemObject tmpFileSystemObject; + + FileSystemObject TmpFile(string path) + { + tmpFileSystemObject = new FileSystemObject(null, -1); + tmpFileSystemObject.path = dic[path].path; + tmpFileSystemObject.depth = dic[path].depth; + tmpFileSystemObject.fileType = dic[path].fileType; + tmpFileSystemObject.isDisplay = dic[path].isDisplay; + return tmpFileSystemObject; + } + + private void DeleteFileInternal(string path) + { + dic.Remove(path); + } + + private List tmpFileSystemObjects; + + FileSystemObject TmpDirectory(string path) + { + tmpFileSystemObject = new FileSystemObject(null, -1); + tmpFileSystemObject.path = dic[path].path; + tmpFileSystemObject.depth = dic[path].depth; + tmpFileSystemObject.fileType = dic[path].fileType; + tmpFileSystemObject.isDisplay = dic[path].isDisplay; + return tmpFileSystemObject; + } + + List TmpDirectoryWithFiles(string path) + { + tmpFileSystemObjects ??= new List(); + tmpFileSystemObjects.Clear(); + + var keys = dic.Keys.ToListPooled(); + var indexOf = keys.IndexOf(path); + for (int i = indexOf + 1; i < keys.Count; i++) + { + if (dic[keys[i]] is not File) + break; + var fileSystemObject = TmpFile(keys[i]); + tmpFileSystemObjects.Add(fileSystemObject); + DeleteFileInternal(keys[i]); + } + + keys.Free(); + return tmpFileSystemObjects; + } + + public void CreateDirectory(string path, int parentDepth) + { + dic.Add(path, new Directory(path, parentDepth + 1)); + OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.Directory, FileOperationType.Create, + null, path, null, null)); + } + + public bool DirectoryExists(string path) + { + return dic.ContainsKey(path); + } + + public void RenameDirectory(string path, string newName) + { + var s = path.Split("/")[^1]; + var replace = path.Replace(s, newName); + var fileSystemObject = TmpDirectory(path); + dic.Remove(path); + dic.Add(replace, fileSystemObject); + OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.Directory, FileOperationType.Rename, + null, replace, null, null)); + } + + public void MoveDirectory(string oldPath, string newPath) + { + var tmpDirectoryWithFiles = TmpDirectoryWithFiles(oldPath); + DeleteDirectory(oldPath); + + var depth = dic[newPath].depth; + foreach (var tmpDirectoryWithFile in tmpDirectoryWithFiles) + { + var replace = tmpDirectoryWithFile.path.Replace(oldPath, newPath); + var tmp = new FileSystemObject(replace, depth + 1, tmpDirectoryWithFile.isDisplay); + dic.Add(replace, tmp); + } + } + + public void DeleteDirectory(string path) + { + var keys = dic.Keys.ToListPooled(); + var indexOf = keys.IndexOf(path); + for (int i = indexOf + 1; i < keys.Count; i++) + { + if (dic[keys[i]] is not File) + break; + DeleteFileInternal(keys[i]); + } + + keys.Free(); + dic.Remove(path); + OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.Directory, FileOperationType.Delete, + null, path, null, null)); + } + + public IReadOnlyDictionary GetAllObjects() + { + return this.dic; + } + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FileSystem.cs.meta b/Assets/ZXL/Scripts/Test/FS/FileSystem.cs.meta similarity index 100% rename from Assets/ZXL/Scripts/Test/FileSystem.cs.meta rename to Assets/ZXL/Scripts/Test/FS/FileSystem.cs.meta diff --git a/Assets/ZXL/Scripts/Test/FileSystemItem.cs b/Assets/ZXL/Scripts/Test/FS/FileSystemItem.cs similarity index 100% rename from Assets/ZXL/Scripts/Test/FileSystemItem.cs rename to Assets/ZXL/Scripts/Test/FS/FileSystemItem.cs diff --git a/Assets/ZXL/Scripts/Test/FileSystemItem.cs.meta b/Assets/ZXL/Scripts/Test/FS/FileSystemItem.cs.meta similarity index 100% rename from Assets/ZXL/Scripts/Test/FileSystemItem.cs.meta rename to Assets/ZXL/Scripts/Test/FS/FileSystemItem.cs.meta diff --git a/Assets/ZXL/Scripts/Test/FS/FileSystemObject.cs b/Assets/ZXL/Scripts/Test/FS/FileSystemObject.cs new file mode 100644 index 0000000..8735c8f --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/FileSystemObject.cs @@ -0,0 +1,19 @@ +namespace ZXLA +{ + public class FileSystemObject + { + public string path; + public int depth; + public bool isDisplay; + public FileObjectType fileType; + + public string name; + + public FileSystemObject(string path, int depth, bool isDisplay = true) + { + this.path = path; + this.depth = depth; + this.isDisplay = isDisplay; + } + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/FileSystemObject.cs.meta b/Assets/ZXL/Scripts/Test/FS/FileSystemObject.cs.meta new file mode 100644 index 0000000..059f9be --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/FileSystemObject.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f8e4580806ac4499b6753aee0ac8ff60 +timeCreated: 1734501454 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/FileSystemOperation.cs b/Assets/ZXL/Scripts/Test/FS/FileSystemOperation.cs new file mode 100644 index 0000000..fa7d054 --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/FileSystemOperation.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace ZXLA +{ + public class FileSystemOperation + { + public FileObjectType FileObjectType { get; } + public FileOperationType FileOperationType { get; } + public string OldPath { get; } + public string NewPath { get; } + public IReadOnlyList OldPaths { get; } + public IReadOnlyList NewPaths { get; } + + public FileSystemOperation(FileObjectType fileObjectType, FileOperationType fileOperationType, string oldPath, + string newPath, IReadOnlyList oldPaths, IReadOnlyList newPaths) + { + FileObjectType = fileObjectType; + FileOperationType = fileOperationType; + OldPath = oldPath; + NewPath = newPath; + OldPaths = oldPaths; + NewPaths = newPaths; + } + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/FileSystemOperation.cs.meta b/Assets/ZXL/Scripts/Test/FS/FileSystemOperation.cs.meta new file mode 100644 index 0000000..17c813b --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/FileSystemOperation.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 161d78b2cedf4a46a6fd6e281ace7f3d +timeCreated: 1734501489 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FileSystemUIDisplay.cs b/Assets/ZXL/Scripts/Test/FS/FileSystemUIDisplay.cs similarity index 100% rename from Assets/ZXL/Scripts/Test/FileSystemUIDisplay.cs rename to Assets/ZXL/Scripts/Test/FS/FileSystemUIDisplay.cs diff --git a/Assets/ZXL/Scripts/Test/FileSystemUIDisplay.cs.meta b/Assets/ZXL/Scripts/Test/FS/FileSystemUIDisplay.cs.meta similarity index 100% rename from Assets/ZXL/Scripts/Test/FileSystemUIDisplay.cs.meta rename to Assets/ZXL/Scripts/Test/FS/FileSystemUIDisplay.cs.meta diff --git a/Assets/ZXL/Scripts/Test/FS/IFileSystem.cs b/Assets/ZXL/Scripts/Test/FS/IFileSystem.cs new file mode 100644 index 0000000..550ee1e --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/IFileSystem.cs @@ -0,0 +1,23 @@ +using System; + +namespace ZXLA +{ + public interface IFileSystem + { + // event Action OnCreateFile; + // event Action OnCreateDirectory; + event Action OnFileSystemChanged; + + void CreateFile(string path, int parentDepth); + bool FileExists(string path); + void RenameFile(string path, string newName); + void MoveFile(string oldPath, string newPath); + void DeleteFile(string path); + + void CreateDirectory(string path, int parentDepth); + bool DirectoryExists(string path); + void RenameDirectory(string path, string newName); + void MoveDirectory(string oldPath, string newPath); + void DeleteDirectory(string path); + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FS/IFileSystem.cs.meta b/Assets/ZXL/Scripts/Test/FS/IFileSystem.cs.meta new file mode 100644 index 0000000..63e9cd2 --- /dev/null +++ b/Assets/ZXL/Scripts/Test/FS/IFileSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 589df65e86a744b8b56776720fbfad21 +timeCreated: 1734501482 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Test/FileSystem.cs b/Assets/ZXL/Scripts/Test/FileSystem.cs deleted file mode 100644 index fec49a5..0000000 --- a/Assets/ZXL/Scripts/Test/FileSystem.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using ZXL; - -namespace ZXLA -{ - public enum FileOperationType - { - Create, - Delete - } - - public enum FileObjectType - { - File, - Directory - } - - public class FileSystemOperation - { - public FileObjectType FileObjectType { get; } - public FileOperationType FileOperationType { get; } - public string OldPath { get; } - public string NewPath { get; } - public IReadOnlyList OldPaths { get; } - public IReadOnlyList NewPaths { get; } - - public FileSystemOperation(FileObjectType fileObjectType, FileOperationType fileOperationType, string oldPath, string newPath, IReadOnlyList oldPaths, IReadOnlyList newPaths) - { - FileObjectType = fileObjectType; - FileOperationType = fileOperationType; - OldPath = oldPath; - NewPath = newPath; - OldPaths = oldPaths; - NewPaths = newPaths; - } - } - - public class FileSystem : MonoBehaviour - { - private SortedDictionary dic = new SortedDictionary(); - public event Action OnCeateFile; - public event Action OnCeateDirectory; - public event Action OnFileSystemChanged; - - public void CreateFile(string path, int parentDepth) - { - dic.Add(path, new File() { path = path, depth = parentDepth + 1 }); - OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.File, FileOperationType.Create, null, path, null, null)); - } - - public void CreateDirectory(string path, int parentDepth) - { - dic.Add(path, new Directory() { path = path, depth = parentDepth + 1 }); - OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.Directory, FileOperationType.Create, null, path, null, null)); - } - - public void DeleteDirectory(string path) - { - var keys = dic.Keys.ToListPooled(); - var indexOf = keys.IndexOf(path); - for (int i = indexOf + 1; i < keys.Count; i++) - { - if (dic[keys[i]] is not File) - break; - DeleteFileInternal(keys[i]); - } - - keys.Free(); - dic.Remove(path); - OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.Directory, FileOperationType.Delete, null, path, null, null)); - } - - public void DeleteFile(string path) - { - DeleteFileInternal(path); - OnFileSystemChanged?.Invoke(new FileSystemOperation(FileObjectType.File, FileOperationType.Delete, null, path, null, null)); - } - - private void DeleteFileInternal(string path) - { - dic.Remove(path); - } - - public IReadOnlyDictionary GetAllObjects() - { - return this.dic; - } - } - - public class FileSystemObject - { - public string path; - public int depth; - public bool isDisplay; - public FileObjectType fileType; - } - - class File : FileSystemObject - { - private void Awake() - { - fileType = FileObjectType.File; - } - } - - class Directory : FileSystemObject - { - private void Awake() - { - fileType = FileObjectType.Directory; - } - } -} \ No newline at end of file diff --git a/EditorTool3D.sln b/EditorTool3D.sln index 1831563..c5b206a 100644 --- a/EditorTool3D.sln +++ b/EditorTool3D.sln @@ -1,19 +1,19 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor", "Assembly-CSharp-Editor.csproj", "{17979be4-dee9-189e-5d07-fdd058a166b7}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{005d29ad-e0bd-eb88-4469-295a9a5f266c}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor", "Assembly-CSharp-Editor.csproj", "{17979be4-dee9-189e-5d07-fdd058a166b7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {17979be4-dee9-189e-5d07-fdd058a166b7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {17979be4-dee9-189e-5d07-fdd058a166b7}.Debug|Any CPU.Build.0 = Debug|Any CPU {005d29ad-e0bd-eb88-4469-295a9a5f266c}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {005d29ad-e0bd-eb88-4469-295a9a5f266c}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17979be4-dee9-189e-5d07-fdd058a166b7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17979be4-dee9-189e-5d07-fdd058a166b7}.Debug|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/EditorTool3D.sln.DotSettings.user b/EditorTool3D.sln.DotSettings.user index 7ad4c3e..435a05b 100644 --- a/EditorTool3D.sln.DotSettings.user +++ b/EditorTool3D.sln.DotSettings.user @@ -1,2 +1,4 @@  + ForceIncluded + ForceIncluded ForceIncluded \ No newline at end of file