Skip to content

Instantly share code, notes, and snippets.

@matniedoba
Last active October 31, 2023 09:59
Show Gist options
  • Save matniedoba/1e09ccea78aa8fe78bbe79eb3fad0e1c to your computer and use it in GitHub Desktop.
Save matniedoba/1e09ccea78aa8fe78bbe79eb3fad0e1c to your computer and use it in GitHub Desktop.
// Put this into your Assets folder
// The best place is to put it in a Scripts/ Editor Scripts folder
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class NotifyForLockedFiles : UnityEditor.AssetModificationProcessor
{
public static string[] OnWillSaveAssets(string[] paths)
{
List<string> pathsToSave = new List<string>();
for (int i = 0; i < paths.Length; ++i)
{
FileInfo info = new FileInfo(paths[i]);
if (info.IsReadOnly)
UnityEditor.EditorUtility.DisplayDialog("File locked",
paths[i] + " is locked by Anchorpoint to prevent conflicts.",
"Ok");
else
pathsToSave.Add(paths[i]);
}
return pathsToSave.ToArray();
}
}
@matniedoba
Copy link
Author

This is a Editor Script for Unity, so that it respects read-only files and does not save over them. This is important when locking files using version control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment