-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from CandyCoded/feature/file-watcher
[feat] File watcher
- Loading branch information
Showing
8 changed files
with
155 additions
and
116 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/FileWatcher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
#if UNITY_EDITOR | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CandyCoded.GitStatus | ||
{ | ||
|
||
[InitializeOnLoad] | ||
public static class FileWatcher | ||
{ | ||
|
||
public delegate void EventHandler(); | ||
|
||
public static event EventHandler UpdateEvent; | ||
|
||
private static readonly FileSystemWatcher _fileSystemWatcher; | ||
|
||
private static bool _changeRegistered; | ||
|
||
static FileWatcher() | ||
{ | ||
|
||
if (_fileSystemWatcher != null) | ||
{ | ||
|
||
return; | ||
|
||
} | ||
|
||
_fileSystemWatcher = new FileSystemWatcher(Application.dataPath); | ||
|
||
_fileSystemWatcher.Created += OnChanged; | ||
_fileSystemWatcher.Changed += OnChanged; | ||
_fileSystemWatcher.Deleted += OnChanged; | ||
|
||
_fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite; | ||
_fileSystemWatcher.Filter = "*.*"; | ||
_fileSystemWatcher.IncludeSubdirectories = true; | ||
_fileSystemWatcher.EnableRaisingEvents = true; | ||
|
||
} | ||
|
||
private static void OnChanged(object sender, FileSystemEventArgs e) | ||
{ | ||
|
||
if (e.FullPath.EndsWith(".meta")) | ||
{ | ||
|
||
return; | ||
|
||
} | ||
|
||
if (!_changeRegistered) | ||
{ | ||
|
||
EditorApplication.update += OnAllChanged; | ||
|
||
_changeRegistered = true; | ||
|
||
} | ||
|
||
} | ||
|
||
private static void OnAllChanged() | ||
{ | ||
|
||
UpdateEvent?.Invoke(); | ||
|
||
EditorApplication.update -= OnAllChanged; | ||
|
||
_changeRegistered = false; | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
#endif |
3 changes: 3 additions & 0 deletions
3
Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/FileWatcher.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/GitStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
#if UNITY_EDITOR | ||
using System; | ||
using UnityEditor; | ||
|
||
namespace CandyCoded.GitStatus | ||
{ | ||
|
||
[InitializeOnLoad] | ||
public static class GitStatus | ||
{ | ||
|
||
public static string branch; | ||
|
||
public static string[] branches; | ||
|
||
public static string[] changedFiles; | ||
|
||
public static string[] untrackedFiles; | ||
|
||
public static DateTime lastUpdated; | ||
|
||
static GitStatus() | ||
{ | ||
|
||
FileWatcher.UpdateEvent -= Update; | ||
FileWatcher.UpdateEvent += Update; | ||
|
||
Update(); | ||
|
||
} | ||
|
||
public static void Update() | ||
{ | ||
|
||
branch = Git.Branch(); | ||
|
||
branches = Git.Branches(); | ||
|
||
changedFiles = Git.ChangedFiles(); | ||
|
||
untrackedFiles = Git.UntrackedFiles(); | ||
|
||
lastUpdated = DateTime.Now; | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
#endif |
3 changes: 3 additions & 0 deletions
3
Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/GitStatus.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters