123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEditor;
- using UnityEngine;
- // Hello World
- // Hello World
- // Hello Here
- // Hello World
- 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<string> 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<UnityEngine.Object>(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<string> outNotEditablePaths, StatusQueryOptions statusQueryOptions)
- {
- Debug.Log("IsOpenForEdit:");
- // TODO: Do locking/unlocking here
- foreach (var path in paths)
- {
- // Check for lock
- Debug.Log(path);
- }
- return true;
- }
- }
- }
|