private void Create(UnityProjectState state) { assetDatabase = state.AssetDatabase; BaseDirectory = state.BaseDirectory; RootFolder = new Folder(""); folders = new Dictionary<string, Folder> {{RootFolder.RelativePath, RootFolder}}; // Build folder structure from files foreach (var file in assetDatabase.Files) AddFile(file); // Build folder structure from empty folders foreach (var emptyDirectory in assetDatabase.EmptyDirectories) AddEmptyDirectory(emptyDirectory); }
public bool Update(UnityProjectState state) { if (assetDatabase == null || assetDatabase == state.AssetDatabase || BaseDirectory != state.BaseDirectory) { Create(state); return false; } var oldAssetDatabase = assetDatabase; var newAssetDatabase = state.AssetDatabase; assetDatabase = state.AssetDatabase; if (state.RenameHint != null) { RenameFileOrDirectory(state.RenameHint.OldPath, state.RenameHint.newPath); return true; } var addFiles = newAssetDatabase.Files.Where(f => !oldAssetDatabase.Files.Contains(f)).ToArray(); var addEmptyDirectories = newAssetDatabase.EmptyDirectories.Where(f => !oldAssetDatabase.EmptyDirectories.Contains(f)).ToArray(); var removeFiles = oldAssetDatabase.Files.Where(f => !newAssetDatabase.Files.Contains(f)).ToArray(); var removeEmptyDirectories = oldAssetDatabase.EmptyDirectories.Where(f => !newAssetDatabase.EmptyDirectories.Contains(f)).ToArray(); var numChanges = addFiles.Length + addEmptyDirectories.Length + removeFiles.Length + removeEmptyDirectories.Length; if (numChanges == 0) return true; foreach (var file in addFiles) AddFile(file); foreach (var file in removeFiles) RemoveFile(file, addEmptyDirectories); foreach (var directory in addEmptyDirectories) AddEmptyDirectory(directory); foreach (var directory in removeEmptyDirectories) RemoveEmptyDirectory(directory, addEmptyDirectories); return true; }
public UnityProjectState() { Islands = new List<MonoIsland> (); AssetDatabase = new AssetDatabase (); }