using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
namespace Coffee.UIExtensions.Editors
{
///
/// Remove deprecated files in old .unitypackage, after compiling.
///
public class DeprecatedRemover
{
///
/// GUIDs of deprecated files.
///
static readonly List DeprecatedFiles = new List()
{
"156b57fee6ef941958e66a129ce387e2", // UICustomEffect.cs
"a4961e148a8cd4fe0b84dddc2741894a", // UICustomEffectEditor.cs
"7b1ed09bdf5e54042b5cd1fbe69361bf", // MaterialBundle.cs
};
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod]
static void RemoveFiles()
{
// The deprecated file path that exists.
var files = DeprecatedFiles.Select(x => AssetDatabase.GUIDToAssetPath(x))
.Where(x => File.Exists(x))
.ToArray();
if (files.Any())
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("[{0}] {1} files have been removed.\n", typeof(DeprecatedRemover).Name, files.Length);
foreach (var path in files)
{
AssetDatabase.DeleteAsset(path);
sb.AppendFormat(" - {0}\n", path);
}
AssetDatabase.Refresh();
UnityEngine.Debug.Log(sb);
}
}
#endif
}
}