Skip to content

Instantly share code, notes, and snippets.

@CSaratakij
Created March 28, 2022 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CSaratakij/920ad62438bebf75a31869b978b3a87b to your computer and use it in GitHub Desktop.
Save CSaratakij/920ad62438bebf75a31869b978b3a87b to your computer and use it in GitHub Desktop.
Asset Import Logger (for re-import issue)
  1. Put these scripts to "Assets/Editor" folder
  2. Enable in context menu "Help" -> "Toggle asset import log"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class AssetImportLogger : AssetPostprocessor
{
public const string IS_ENABLE_KEY = "KEY_ASSET_IMPORT_LOGGER_IS_ENABLE";
public const string IS_START_KEY = "KEY_ASSET_IMPORT_LOGGER_IS_START";
public const string LOG_FORMAT = "path '{0}'";
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
bool isEnable = EditorPrefs.GetBool(IS_ENABLE_KEY, false);
if (!isEnable)
{
return;
}
bool isStart = EditorPrefs.GetBool(IS_START_KEY, false);
if (isStart)
{
EditorPrefs.SetBool(IS_START_KEY, false);
//Debug.Log("=============================================");
}
}
private void OnPreprocessAsset()
{
bool isEnable = EditorPrefs.GetBool(IS_ENABLE_KEY, false);
if (!isEnable)
{
return;
}
bool isStart = EditorPrefs.GetBool(IS_START_KEY, false);
if (!isStart)
{
EditorPrefs.SetBool(IS_START_KEY, true);
Debug.Log("=============== Asset Import Logger ===============");
}
Debug.Log(string.Format(LOG_FORMAT, assetPath));
}
}
using UnityEditor;
[InitializeOnLoad]
public static class AssetImportLoggerMenu
{
private const string MENU_NAME = "Help/Toggle asset import log";
public static bool IsEnabled = false;
static AssetImportLoggerMenu()
{
IsEnabled = EditorPrefs.GetBool(AssetImportLogger.IS_ENABLE_KEY, false);
}
[MenuItem(MENU_NAME)]
private static void ToggleEnable()
{
IsEnabled = !IsEnabled;
EditorPrefs.SetBool(AssetImportLogger.IS_ENABLE_KEY, IsEnabled);
}
[MenuItem(MENU_NAME, true)]
private static bool ToggleEnableValidate()
{
Menu.SetChecked(MENU_NAME, IsEnabled);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment