Skip to content

Instantly share code, notes, and snippets.

@maoyeedy
Last active April 23, 2025 20:04
Show Gist options
  • Save maoyeedy/77551790e17397090b7268795654d3cf to your computer and use it in GitHub Desktop.
Save maoyeedy/77551790e17397090b7268795654d3cf to your computer and use it in GitHub Desktop.
[Unity] Hides meta files in Windows Explorer.
#if UNITY_EDITOR
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Editor
{
/// <summary>
/// It runs after each assembly reload.
/// </summary>
[InitializeOnLoad]
public class HideMetaFiles
{
static HideMetaFiles()
{
HideFiles(Application.dataPath, "*.meta");
//HideFiles(Directory.GetParent(Application.dataPath)?.FullName, "*.csproj");
}
private static void HideFiles(string directory, string extension)
{
string[] files = Directory.GetFiles(directory, extension, SearchOption.AllDirectories);
foreach (string filePath in files)
{
SetHiddenAttribute(filePath);
}
Debug.Log($"{extension} files have been hidden in {directory}.");
}
private static void SetHiddenAttribute(string filePath)
{
FileAttributes attributes = File.GetAttributes(filePath);
if ((attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
File.SetAttributes(filePath, attributes | FileAttributes.Hidden);
}
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment