mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
优化主题Theme的导入和字体自动刷新 (#148)
This commit is contained in:
@@ -35,10 +35,11 @@
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2021.06.12) Optimized import of `Theme` and automatic font refresh (#148)
|
||||||
* (2021.06.10) Fixed compatibility issues with `Unity` version (#154)
|
* (2021.06.10) Fixed compatibility issues with `Unity` version (#154)
|
||||||
* (2021.06.05) Improved Candlestickchart support for inverse (#152)
|
* (2021.06.05) Improved Candlestickchart support for inverse (#152)
|
||||||
* (2021.06.04) Optimized auto-refresh of custom `Theme` (#148)
|
* (2021.06.04) Optimized auto-refresh of custom `Theme` (#148)
|
||||||
* (2021.06.04) Fixed `Gauge` having an abnormal pointer position when the minimum value is negative
|
* (2021.06.04) Fixed `Gauge` having an abnormal pointer position when the minimum value is negative (#153)
|
||||||
|
|
||||||
## v2.2.0
|
## v2.2.0
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,11 @@
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2021.06.12) 优化主题`Theme`的导入和字体自动刷新 (#148)
|
||||||
* (2021.06.10) 修复`Unity`版本兼容问题 (#154)
|
* (2021.06.10) 修复`Unity`版本兼容问题 (#154)
|
||||||
* (2021.06.05) 完善`CandlestickChart`对`inverse`的支持 (#152)
|
* (2021.06.05) 完善`CandlestickChart`对`inverse`的支持 (#152)
|
||||||
* (2021.06.04) 优化自定义主题`Theme`的自动刷新 (#148)
|
* (2021.06.04) 优化自定义主题`Theme`的自动刷新 (#148)
|
||||||
* (2021.06.04) 修复`Gauge`在最小值为负数时指针指示位置异常的问题
|
* (2021.06.04) 修复`Gauge`在最小值为负数时指针指示位置异常的问题 (#153)
|
||||||
|
|
||||||
## v2.2.0
|
## v2.2.0
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,6 @@ namespace XCharts
|
|||||||
btnRect.y = m_DrawRect.y - EditorGUIUtility.singleLineHeight - 3;
|
btnRect.y = m_DrawRect.y - EditorGUIUtility.singleLineHeight - 3;
|
||||||
btnRect.width = btnWidth;
|
btnRect.width = btnWidth;
|
||||||
var chart = prop.serializedObject.targetObject as BaseChart;
|
var chart = prop.serializedObject.targetObject as BaseChart;
|
||||||
var lastFont = chart.theme.font;
|
|
||||||
#if dUI_TextMeshPro
|
|
||||||
var lastTMPFont = chart.theme.tmpFont;
|
|
||||||
#endif
|
|
||||||
if (GUI.Button(btnRect, new GUIContent("Reset", "Reset to theme default color")))
|
if (GUI.Button(btnRect, new GUIContent("Reset", "Reset to theme default color")))
|
||||||
{
|
{
|
||||||
chart.theme.ResetTheme();
|
chart.theme.ResetTheme();
|
||||||
@@ -60,8 +56,18 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
#if dUI_TextMeshPro
|
#if dUI_TextMeshPro
|
||||||
PropertyField(prop, "m_TMPFont");
|
PropertyField(prop, "m_TMPFont");
|
||||||
|
if(chart.theme.tmpFont == null && !string.IsNullOrEmpty(chart.theme.tmpFontName))
|
||||||
|
{
|
||||||
|
var msg = string.Format("Can't find theme font asset:{0} in project.", chart.theme.tmpFontName);
|
||||||
|
EditorGUILayout.HelpBox(msg, MessageType.Error);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
PropertyField(prop, "m_Font");
|
PropertyField(prop, "m_Font");
|
||||||
|
if (chart.theme.font == null && !string.IsNullOrEmpty(chart.theme.fontName))
|
||||||
|
{
|
||||||
|
var msg = string.Format("Can't find theme font asset:{0} in project.", chart.theme.fontName);
|
||||||
|
EditorGUILayout.HelpBox(msg, MessageType.Error);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
PropertyField(prop, "m_ContrastColor");
|
PropertyField(prop, "m_ContrastColor");
|
||||||
PropertyField(prop, "m_BackgroundColor");
|
PropertyField(prop, "m_BackgroundColor");
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
using UnityEngine;
|
/************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||||
|
/* https://github.com/monitor1394 */
|
||||||
|
/* */
|
||||||
|
/************************************************/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
/************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||||
|
/* https://github.com/monitor1394 */
|
||||||
|
/* */
|
||||||
|
/************************************************/
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -63,7 +70,8 @@ namespace XCharts
|
|||||||
private static bool IsThemeAsset(string assetPath)
|
private static bool IsThemeAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (!assetPath.EndsWith(".json")) return false;
|
if (!assetPath.EndsWith(".json")) return false;
|
||||||
if (!assetPath.StartsWith("XTheme")) return false;
|
var assetName = Path.GetFileNameWithoutExtension(assetPath);
|
||||||
|
if (!assetName.StartsWith(XChartsSettings.THEME_ASSET_NAME_PREFIX)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
Assets/XCharts/Editor/Utility/XChartsBuild.cs
Normal file
28
Assets/XCharts/Editor/Utility/XChartsBuild.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||||
|
/* https://github.com/monitor1394 */
|
||||||
|
/* */
|
||||||
|
/************************************************/
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.Build;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
public class XChartsBuild : IPreprocessBuild, IPostprocessBuild
|
||||||
|
{
|
||||||
|
public int callbackOrder => 1;
|
||||||
|
|
||||||
|
public void OnPostprocessBuild(BuildTarget target, string path)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPreprocessBuild(BuildTarget target, string path)
|
||||||
|
{
|
||||||
|
XThemeMgr.ExportAllCustomTheme();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/XCharts/Editor/Utility/XChartsBuild.cs.meta
Normal file
11
Assets/XCharts/Editor/Utility/XChartsBuild.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: df212e63c528e40fa9e8fffcd868ab7d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -637,6 +637,7 @@ namespace XCharts
|
|||||||
public void UpdateTheme(ChartTheme theme)
|
public void UpdateTheme(ChartTheme theme)
|
||||||
{
|
{
|
||||||
m_Theme.CopyTheme(theme);
|
m_Theme.CopyTheme(theme);
|
||||||
|
SetAllComponentDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
[SerializeField] private Theme m_Theme = Theme.Default;
|
[SerializeField] private Theme m_Theme = Theme.Default;
|
||||||
[SerializeField] private string m_ThemeName = Theme.Default.ToString();
|
[SerializeField] private string m_ThemeName = Theme.Default.ToString();
|
||||||
|
[SerializeField] private string m_FontName;
|
||||||
|
[SerializeField] private string m_TMPFontName;
|
||||||
|
[SerializeField] private int m_FontInstacneId;
|
||||||
|
[SerializeField] private int m_TMPFontInstanceId;
|
||||||
[SerializeField] private Font m_Font;
|
[SerializeField] private Font m_Font;
|
||||||
#if dUI_TextMeshPro
|
#if dUI_TextMeshPro
|
||||||
[SerializeField] private TMP_FontAsset m_TMPFont;
|
[SerializeField] private TMP_FontAsset m_TMPFont;
|
||||||
@@ -75,6 +79,12 @@ namespace XCharts
|
|||||||
[SerializeField] private VisualMapTheme m_VisualMap;
|
[SerializeField] private VisualMapTheme m_VisualMap;
|
||||||
[SerializeField] private SerieTheme m_Serie;
|
[SerializeField] private SerieTheme m_Serie;
|
||||||
|
|
||||||
|
private ChartTheme()
|
||||||
|
{
|
||||||
|
m_FontName = "Arial";
|
||||||
|
m_TMPFontName = "LiberationSans SDF";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the theme of chart.
|
/// the theme of chart.
|
||||||
/// 主题类型。
|
/// 主题类型。
|
||||||
@@ -110,6 +120,27 @@ namespace XCharts
|
|||||||
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
|
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string fontName
|
||||||
|
{
|
||||||
|
get { return m_FontName; }
|
||||||
|
set { if (PropertyUtil.SetClass(ref m_FontName, value)) SetComponentDirty(); }
|
||||||
|
}
|
||||||
|
public int fontInstanceId
|
||||||
|
{
|
||||||
|
get { return m_FontInstacneId; }
|
||||||
|
set { if (PropertyUtil.SetStruct(ref m_FontInstacneId, value)) SetComponentDirty(); }
|
||||||
|
}
|
||||||
|
public string tmpFontName
|
||||||
|
{
|
||||||
|
get { return m_TMPFontName; }
|
||||||
|
set { if (PropertyUtil.SetClass(ref m_TMPFontName, value)) SetComponentDirty(); }
|
||||||
|
}
|
||||||
|
public int tmpFontInstanceId
|
||||||
|
{
|
||||||
|
get { return m_TMPFontInstanceId; }
|
||||||
|
set { if (PropertyUtil.SetStruct(ref m_TMPFontInstanceId, value)) SetComponentDirty(); }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The color list of palette. If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series.
|
/// The color list of palette. If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series.
|
||||||
/// 调色盘颜色列表。如果系列没有设置颜色,则会依次循环从该列表中取颜色作为系列颜色。
|
/// 调色盘颜色列表。如果系列没有设置颜色,则会依次循环从该列表中取颜色作为系列颜色。
|
||||||
@@ -139,11 +170,14 @@ namespace XCharts
|
|||||||
get { return m_TMPFont; }
|
get { return m_TMPFont; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (PropertyUtil.SetClass(ref m_TMPFont, value))
|
m_TMPFont = value;
|
||||||
|
if(value)
|
||||||
{
|
{
|
||||||
SetComponentDirty();
|
m_TMPFontName = value.name;
|
||||||
SyncTMPFontToSubComponent();
|
m_TMPFontInstanceId = value.GetInstanceID();
|
||||||
}
|
}
|
||||||
|
SetComponentDirty();
|
||||||
|
SyncTMPFontToSubComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -156,11 +190,14 @@ namespace XCharts
|
|||||||
get { return m_Font; }
|
get { return m_Font; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (PropertyUtil.SetClass(ref m_Font, value))
|
m_Font = value;
|
||||||
|
if (value)
|
||||||
{
|
{
|
||||||
SetComponentDirty();
|
m_FontName = value.name;
|
||||||
SyncFontToSubComponent();
|
m_FontInstacneId = value.GetInstanceID();
|
||||||
}
|
}
|
||||||
|
SetComponentDirty();
|
||||||
|
SyncFontToSubComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,9 +299,13 @@ namespace XCharts
|
|||||||
m_Theme = theme.theme;
|
m_Theme = theme.theme;
|
||||||
m_ThemeName = theme.themeName;
|
m_ThemeName = theme.themeName;
|
||||||
#if dUI_TextMeshPro
|
#if dUI_TextMeshPro
|
||||||
m_TMPFont = theme.tmpFont;
|
tmpFont = theme.tmpFont;
|
||||||
#endif
|
#endif
|
||||||
m_Font = theme.m_Font;
|
font = theme.font;
|
||||||
|
m_FontName = theme.fontName;
|
||||||
|
m_FontInstacneId = theme.fontInstanceId;
|
||||||
|
m_TMPFontName = theme.tmpFontName;
|
||||||
|
m_TMPFontInstanceId = theme.tmpFontInstanceId;
|
||||||
m_ContrastColor = theme.contrastColor;
|
m_ContrastColor = theme.contrastColor;
|
||||||
m_BackgroundColor = theme.m_BackgroundColor;
|
m_BackgroundColor = theme.m_BackgroundColor;
|
||||||
m_Common.Copy(theme.common);
|
m_Common.Copy(theme.common);
|
||||||
@@ -438,6 +479,22 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SyncFontName()
|
||||||
|
{
|
||||||
|
if (font)
|
||||||
|
{
|
||||||
|
m_FontName = font.name;
|
||||||
|
m_FontInstacneId = font.GetInstanceID();
|
||||||
|
}
|
||||||
|
#if dUI_TextMeshPro
|
||||||
|
if (tmpFont)
|
||||||
|
{
|
||||||
|
m_TMPFontName = tmpFont.name;
|
||||||
|
m_TMPFontInstanceId = tmpFont.GetInstanceID();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public void SyncFontToSubComponent()
|
public void SyncFontToSubComponent()
|
||||||
{
|
{
|
||||||
common.font = font;
|
common.font = font;
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ namespace XCharts
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the font of text。
|
/// the font of text.
|
||||||
/// 字体。
|
/// 字体。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Font font
|
public Font font
|
||||||
{
|
{
|
||||||
get { return m_Font; }
|
get { return m_Font; }
|
||||||
set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
|
set { m_Font = value; SetComponentDirty(); }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the color of text.
|
/// the color of text.
|
||||||
@@ -69,7 +69,7 @@ namespace XCharts
|
|||||||
public TMP_FontAsset tmpFont
|
public TMP_FontAsset tmpFont
|
||||||
{
|
{
|
||||||
get { return m_TMPFont; }
|
get { return m_TMPFont; }
|
||||||
set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
|
set { m_TMPFont = value; SetComponentDirty(); }
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -216,10 +216,6 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_Theme.font == null)
|
|
||||||
{
|
|
||||||
m_Theme.font = XChartsSettings.font;
|
|
||||||
}
|
|
||||||
if (m_Theme.colorPalette.Count == 0)
|
if (m_Theme.colorPalette.Count == 0)
|
||||||
{
|
{
|
||||||
m_Theme.ResetTheme();
|
m_Theme.ResetTheme();
|
||||||
|
|||||||
@@ -241,10 +241,6 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if dUI_TextMeshPro
|
#if dUI_TextMeshPro
|
||||||
public void SetAlignment(TextAlignmentOptions alignment)
|
|
||||||
{
|
|
||||||
if (m_TMPText != null) m_TMPText.alignment = alignment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFont(TMP_FontAsset font)
|
public void SetFont(TMP_FontAsset font)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,21 +3,23 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Reflection;
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
#endif
|
#endif
|
||||||
|
#if dUI_TextMeshPro
|
||||||
|
using TMPro;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace XCharts
|
namespace XCharts
|
||||||
{
|
{
|
||||||
public static class XThemeMgr
|
public static class XThemeMgr
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 重新加载主题列表
|
/// 重新加载主题列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void ReloadThemeList()
|
public static void ReloadThemeList()
|
||||||
{
|
{
|
||||||
//Debug.Log("LoadThemesFromResources");
|
|
||||||
XChartsMgr.Instance.m_ThemeDict.Clear();
|
XChartsMgr.Instance.m_ThemeDict.Clear();
|
||||||
XChartsMgr.Instance.m_ThemeNames.Clear();
|
XChartsMgr.Instance.m_ThemeNames.Clear();
|
||||||
AddTheme(ChartTheme.Default);
|
AddTheme(ChartTheme.Default);
|
||||||
@@ -28,10 +30,69 @@ namespace XCharts
|
|||||||
if (json != null && !string.IsNullOrEmpty(json.text))
|
if (json != null && !string.IsNullOrEmpty(json.text))
|
||||||
{
|
{
|
||||||
var theme = JsonUtility.FromJson<ChartTheme>(json.text);
|
var theme = JsonUtility.FromJson<ChartTheme>(json.text);
|
||||||
|
theme.font = GetCustomThemeFont(theme);
|
||||||
|
#if dUI_TextMeshPro
|
||||||
|
theme.tmpFont = GetCustomThemeTMPFont(theme);
|
||||||
|
#endif
|
||||||
AddTheme(theme);
|
AddTheme(theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Debug.Log("LoadThemesFromResources DONE: theme count=" + m_ThemeDict.Keys.Count);
|
}
|
||||||
|
|
||||||
|
private static Font GetCustomThemeFont(ChartTheme theme)
|
||||||
|
{
|
||||||
|
Font font = null;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (string.IsNullOrEmpty(theme.fontName)) return null;
|
||||||
|
if (theme.fontName.Equals("Arial")) return Resources.GetBuiltinResource<Font>("Arial.ttf");
|
||||||
|
var guids = AssetDatabase.FindAssets("t:Font");
|
||||||
|
foreach (var guid in guids)
|
||||||
|
{
|
||||||
|
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||||
|
var tempFont = AssetDatabase.LoadAssetAtPath<Font>(assetPath);
|
||||||
|
if (tempFont.name.Equals(theme.fontName))
|
||||||
|
{
|
||||||
|
font = tempFont;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
font = FindObjectByInstanceId(theme.fontInstanceId) as Font;
|
||||||
|
#endif
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if dUI_TextMeshPro
|
||||||
|
private static TMP_FontAsset GetCustomThemeTMPFont(ChartTheme theme)
|
||||||
|
{
|
||||||
|
TMP_FontAsset font = null;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (!string.IsNullOrEmpty(theme.tmpFontName)){
|
||||||
|
//TODO: how to find TMP_FontAsset asset
|
||||||
|
var guids = AssetDatabase.FindAssets("t:Texture");
|
||||||
|
foreach (var guid in guids)
|
||||||
|
{
|
||||||
|
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||||
|
if(!assetPath.EndsWith(".asset"))continue;
|
||||||
|
var tempFont = AssetDatabase.LoadAssetAtPath<TMP_FontAsset>(assetPath);
|
||||||
|
if (tempFont && tempFont.name.Equals(theme.tmpFontName))
|
||||||
|
{
|
||||||
|
font = tempFont;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
font = FindObjectByInstanceId(theme.fontInstanceId) as TMP_FontAsset;
|
||||||
|
#endif
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public static Object FindObjectByInstanceId(int instanceId)
|
||||||
|
{
|
||||||
|
return (Object)typeof(Object).GetMethod("FindObjectFromInstanceID",
|
||||||
|
BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { instanceId });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddTheme(ChartTheme theme)
|
public static void AddTheme(ChartTheme theme)
|
||||||
@@ -42,10 +103,6 @@ namespace XCharts
|
|||||||
XChartsMgr.Instance.m_ThemeDict.Add(theme.themeName, theme);
|
XChartsMgr.Instance.m_ThemeDict.Add(theme.themeName, theme);
|
||||||
XChartsMgr.Instance.m_ThemeNames.Add(theme.themeName);
|
XChartsMgr.Instance.m_ThemeNames.Add(theme.themeName);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError("Theme name is exist:" + theme.themeName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChartTheme GetTheme(string themeName)
|
public static ChartTheme GetTheme(string themeName)
|
||||||
@@ -62,6 +119,16 @@ namespace XCharts
|
|||||||
return XChartsMgr.Instance.m_ThemeNames;
|
return XChartsMgr.Instance.m_ThemeNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<ChartTheme> GetThemeList()
|
||||||
|
{
|
||||||
|
var list = new List<ChartTheme>();
|
||||||
|
foreach (var theme in XChartsMgr.Instance.m_ThemeDict.Values)
|
||||||
|
{
|
||||||
|
list.Add(theme);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool ContainsTheme(string themeName)
|
public static bool ContainsTheme(string themeName)
|
||||||
{
|
{
|
||||||
return XChartsMgr.Instance.m_ThemeNames.Contains(themeName);
|
return XChartsMgr.Instance.m_ThemeNames.Contains(themeName);
|
||||||
@@ -69,7 +136,6 @@ namespace XCharts
|
|||||||
|
|
||||||
public static void SwitchTheme(BaseChart chart, string themeName)
|
public static void SwitchTheme(BaseChart chart, string themeName)
|
||||||
{
|
{
|
||||||
Debug.Log("SwitchTheme:" + themeName);
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (XChartsMgr.Instance.m_ThemeDict.Count == 0)
|
if (XChartsMgr.Instance.m_ThemeDict.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -82,8 +148,7 @@ namespace XCharts
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var target = XChartsMgr.Instance.m_ThemeDict[themeName];
|
var target = XChartsMgr.Instance.m_ThemeDict[themeName];
|
||||||
chart.theme.CopyTheme(target);
|
chart.UpdateTheme(target);
|
||||||
chart.RefreshAllComponent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ExportTheme(ChartTheme theme, string themeNewName)
|
public static bool ExportTheme(ChartTheme theme, string themeNewName)
|
||||||
@@ -94,22 +159,9 @@ namespace XCharts
|
|||||||
newtheme.theme = Theme.Custom;
|
newtheme.theme = Theme.Custom;
|
||||||
newtheme.themeName = themeNewName;
|
newtheme.themeName = themeNewName;
|
||||||
|
|
||||||
if (!Directory.Exists(Application.dataPath + "/XCharts"))
|
ExportTheme(newtheme);
|
||||||
{
|
var themeAssetName = XChartsSettings.THEME_ASSET_NAME_PREFIX + theme.themeName;
|
||||||
Directory.CreateDirectory(Application.dataPath + "/XCharts");
|
var obj = Resources.Load<TextAsset>(themeAssetName);
|
||||||
}
|
|
||||||
if (!Directory.Exists(Application.dataPath + "/XCharts/Resources"))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(Application.dataPath + "/XCharts/Resources");
|
|
||||||
}
|
|
||||||
var themeFileName = "XTheme-" + newtheme.themeName;
|
|
||||||
var assetPath = string.Format("Assets/XCharts/Resources/{0}", themeFileName);
|
|
||||||
var filePath = string.Format("{0}/../{1}.json", Application.dataPath, assetPath);
|
|
||||||
var json = JsonUtility.ToJson(newtheme, true);
|
|
||||||
File.WriteAllText(filePath, json);
|
|
||||||
AssetDatabase.SaveAssets();
|
|
||||||
AssetDatabase.Refresh();
|
|
||||||
var obj = Resources.Load<TextAsset>(themeFileName);
|
|
||||||
XChartsSettings.AddJsonTheme(obj);
|
XChartsSettings.AddJsonTheme(obj);
|
||||||
ReloadThemeList();
|
ReloadThemeList();
|
||||||
return true;
|
return true;
|
||||||
@@ -118,9 +170,48 @@ namespace XCharts
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool ExportTheme(ChartTheme theme)
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
theme.SyncFontName();
|
||||||
|
var themeAssetName = XChartsSettings.THEME_ASSET_NAME_PREFIX + theme.themeName;
|
||||||
|
var themeAssetPath = Application.dataPath + "/../" + XChartsSettings.THEME_ASSET_FOLDER;
|
||||||
|
if (!Directory.Exists(themeAssetPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(themeAssetPath);
|
||||||
|
}
|
||||||
|
var assetPath = string.Format("{0}/{1}", XChartsSettings.THEME_ASSET_FOLDER, themeAssetName);
|
||||||
|
var themeAssetFilePath = string.Format("{0}/{1}.json", themeAssetPath, themeAssetName);
|
||||||
|
var json = JsonUtility.ToJson(theme, true);
|
||||||
|
File.WriteAllText(themeAssetFilePath, json);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ExportAllCustomTheme()
|
||||||
|
{
|
||||||
|
var list = new List<ChartTheme>();
|
||||||
|
foreach (var theme in XChartsMgr.Instance.m_ThemeDict.Values)
|
||||||
|
{
|
||||||
|
if (theme.theme == Theme.Custom)
|
||||||
|
{
|
||||||
|
list.Add(theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var theme in list)
|
||||||
|
{
|
||||||
|
ExportTheme(theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetThemeAssetPath(string themeName)
|
public static string GetThemeAssetPath(string themeName)
|
||||||
{
|
{
|
||||||
return string.Format("Assets/XCharts/Resources/XTheme-{0}.json", themeName);
|
return string.Format("{0}/{1}{2}.json", XChartsSettings.THEME_ASSET_FOLDER,
|
||||||
|
XChartsSettings.THEME_ASSET_NAME_PREFIX, themeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,9 +30,6 @@ namespace XCharts
|
|||||||
public string homepage = "";
|
public string homepage = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
[InitializeOnLoad]
|
|
||||||
#endif
|
|
||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
public class XChartsMgr : MonoBehaviour
|
public class XChartsMgr : MonoBehaviour
|
||||||
{
|
{
|
||||||
@@ -67,19 +64,13 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private XChartsMgr()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static XChartsMgr()
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
EditorApplication.delayCall += () =>
|
[InitializeOnLoadMethod]
|
||||||
{
|
private static void OnInitializeOnLoadMethod()
|
||||||
var mgr = XChartsMgr.Instance;
|
{
|
||||||
};
|
XThemeMgr.ReloadThemeList();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ using System.Collections.Generic;
|
|||||||
#if dUI_TextMeshPro
|
#if dUI_TextMeshPro
|
||||||
using TMPro;
|
using TMPro;
|
||||||
#endif
|
#endif
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
using UnityEditor;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace XCharts
|
namespace XCharts
|
||||||
{
|
{
|
||||||
@@ -21,6 +24,8 @@ namespace XCharts
|
|||||||
#endif
|
#endif
|
||||||
public class XChartsSettings : ScriptableObject
|
public class XChartsSettings : ScriptableObject
|
||||||
{
|
{
|
||||||
|
public readonly static string THEME_ASSET_NAME_PREFIX = "XTheme-";
|
||||||
|
public readonly static string THEME_ASSET_FOLDER = "Assets/XCharts/Resources";
|
||||||
|
|
||||||
[SerializeField] private Font m_Font = null;
|
[SerializeField] private Font m_Font = null;
|
||||||
#if dUI_TextMeshPro
|
#if dUI_TextMeshPro
|
||||||
@@ -145,7 +150,6 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return s_Instance;
|
return s_Instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,6 +160,11 @@ namespace XCharts
|
|||||||
if (!Instance.m_CustomThemes.Contains(theme))
|
if (!Instance.m_CustomThemes.Contains(theme))
|
||||||
{
|
{
|
||||||
Instance.m_CustomThemes.Add(theme);
|
Instance.m_CustomThemes.Add(theme);
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
EditorUtility.SetDirty(Instance);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user