using System; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; namespace GitMerge { public class ConflictWatcher { private static FileSystemWatcher watcher; private static FileSystemEventArgs e; public ConflictWatcher() { string assetPath = Application.dataPath; watcher = new FileSystemWatcher(assetPath); watcher.IncludeSubdirectories = true; watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName; watcher.Changed += OnFileChanged; watcher.EnableRaisingEvents = true; } public event Action OnConflict; private void OnFileChanged(object sender, FileSystemEventArgs _e) { e = _e; EditorApplication.update += CheckWindow; } private void CheckWindow() { AssetDatabase.Refresh(); EditorApplication.update -= CheckWindow; var path = e.FullPath; var relativePath = "Assets" + path.Substring(Application.dataPath.Length); if (!path.EndsWith(".unity") && !path.EndsWith(".prefab")) return; // Found it UnityEngine.Object asset; try { asset = AssetDatabase.LoadAssetAtPath(relativePath); } catch (Exception exception) { Debug.Log(exception); throw; } Debug.Log("asset" + asset); if (asset != null) { Debug.Log("Found asset" + asset.GetType()); bool isBroken = asset is BrokenPrefabAsset; // Open merge conflict window if (isBroken) { OnConflict?.Invoke(relativePath); } } } static bool IsOpenForEdit(string[] paths, List outNotEditablePaths, StatusQueryOptions statusQueryOptions) { Debug.Log("IsOpenForEdit:"); // TODO: Do locking/unlocking here foreach (var path in paths) { // Check for lock Debug.Log(path); } return true; } } }