Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning when deleting empty folders #23

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions Editor/AssetProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Ogxd.ProjectCurator
/// </summary>
public class AssetProcessor : UnityEditor.AssetModificationProcessor
{
private static readonly Queue<Action> _actions = new Queue<Action>();

[InitializeOnLoadMethod]
public static void Init()
{
Expand All @@ -20,20 +22,18 @@ public static void Init()
/// </summary>
private static void OnUpdate()
{
if (Actions.Count > 0) {
while (Actions.Count > 0) {
Actions.Dequeue()?.Invoke();
if (_actions.Count > 0) {
while (_actions.Count > 0) {
_actions.Dequeue()?.Invoke();
}
ProjectCurator.SaveDatabase();
}
}

private static Queue<Action> Actions = new Queue<Action>();

static string[] OnWillSaveAssets(string[] paths)
{
if (ProjectCuratorData.IsUpToDate) {
Actions.Enqueue(() => {
_actions.Enqueue(() => {
foreach (string path in paths) {
var guid = AssetDatabase.AssetPathToGUID(path);
var removedAsset = ProjectCurator.RemoveAssetFromDatabase(guid);
Expand All @@ -46,8 +46,16 @@ static string[] OnWillSaveAssets(string[] paths)

static void OnWillCreateAsset(string assetPath)
{
// Due to an apparent bug in Unity, newly created folders give the
// path of the meta file, instead of the folder itself. Trim the
// .meta off the end in the case that this happens.
//
// .meta files are not assets, so there are no other cases where
// this will have any effect.
assetPath = assetPath.TrimEnd(".meta");

if (ProjectCuratorData.IsUpToDate) {
Actions.Enqueue(() => {
_actions.Enqueue(() => {
var guid = AssetDatabase.AssetPathToGUID(assetPath);
if (guid != string.Empty) {
ProjectCurator.AddAssetToDatabase(guid);
Expand Down
18 changes: 18 additions & 0 deletions Editor/StringUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Ogxd.ProjectCurator {
internal static class StringUtility
{
// https://stackoverflow.com/a/7170953/317135
public static string TrimEnd(
this string input,
string suffixToRemove,
StringComparison comparisonType = StringComparison.CurrentCulture
) {
if (suffixToRemove != null && input.EndsWith(suffixToRemove, comparisonType)) {
return input[0..^suffixToRemove.Length];
}
return input;
}
}
}
rhys-vdw marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions Editor/StringUtility.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.