mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
优化和重构Theme,解决引用相同或丢失的问题 #118
This commit is contained in:
60
Editor/Utility/ThemeCheck.cs
Normal file
60
Editor/Utility/ThemeCheck.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class ThemeCheck
|
||||
{
|
||||
public class ThemeAssetPostprocessor : AssetPostprocessor
|
||||
{
|
||||
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
|
||||
string[] movedFromAssetsPaths)
|
||||
{
|
||||
foreach (var assetPath in importedAssets)
|
||||
{
|
||||
CheckAddedAsset(assetPath);
|
||||
}
|
||||
foreach (var assetPath in deletedAssets)
|
||||
{
|
||||
CheckDeletedAsset(assetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckAddedAsset(string assetPath)
|
||||
{
|
||||
if (!IsThemeAsset(assetPath)) return;
|
||||
var obj = AssetDatabase.LoadAssetAtPath<TextAsset>(assetPath);
|
||||
if (XChartsSettings.AddJsonTheme(obj))
|
||||
{
|
||||
XThemeMgr.ReloadThemeList();
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckDeletedAsset(string assetPath)
|
||||
{
|
||||
if (!IsThemeAsset(assetPath)) return;
|
||||
var themes = XChartsSettings.customThemes;
|
||||
var changed = false;
|
||||
|
||||
for (int i = themes.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (themes[i] == null)
|
||||
{
|
||||
themes.RemoveAt(i);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
XThemeMgr.ReloadThemeList();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsThemeAsset(string assetPath)
|
||||
{
|
||||
if (!assetPath.EndsWith(".json")) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user