Last active
April 23, 2025 20:04
-
-
Save maoyeedy/77551790e17397090b7268795654d3cf to your computer and use it in GitHub Desktop.
[Unity] Hides meta files in Windows Explorer.
This file contains hidden or 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
#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