代码优化

This commit is contained in:
monitor1394
2022-12-22 21:51:08 +08:00
parent a5aa630b74
commit d7cfda2521
6 changed files with 25 additions and 17 deletions

View File

@@ -631,15 +631,5 @@ namespace XCharts.Runtime
SerieHelper.GetItemColor(out color, out toColor, serie, null, m_Theme); SerieHelper.GetItemColor(out color, out toColor, serie, null, m_Theme);
return color; return color;
} }
/// <summary>
/// 保存图表为图片。
/// </summary>
/// <param name="imageType">type of image: png, jpg, exr</param>
/// <param name="savePath">save path</param>
public void SaveAsImage(string imageType = "png", string savePath = "")
{
StartCoroutine(SaveAsImageSync(imageType, savePath));
}
} }
} }

View File

@@ -746,11 +746,5 @@ namespace XCharts.Runtime
InitComponentHandlers(); InitComponentHandlers();
InitSerieHandlers(); InitSerieHandlers();
} }
private IEnumerator SaveAsImageSync(string imageType, string path)
{
yield return new WaitForEndOfFrame();
ChartHelper.SaveAsImage(rectTransform, canvas, imageType, path);
}
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
@@ -170,5 +171,21 @@ namespace XCharts.Runtime
} }
return true; return true;
} }
/// <summary>
/// 保存图表为图片。
/// </summary>
/// <param name="imageType">type of image: png, jpg, exr</param>
/// <param name="savePath">save path</param>
public void SaveAsImage(string imageType = "png", string savePath = "")
{
StartCoroutine(SaveAsImageSync(imageType, savePath));
}
private IEnumerator SaveAsImageSync(string imageType, string path)
{
yield return new WaitForEndOfFrame();
ChartHelper.SaveAsImage(rectTransform, canvas, imageType, path);
}
} }
} }

View File

@@ -40,6 +40,7 @@ namespace XCharts.Runtime
public bool hideIconIfTextEmpty { set { m_HideIconIfTextEmpty = value; } } public bool hideIconIfTextEmpty { set { m_HideIconIfTextEmpty = value; } }
public bool isIconActive { get; private set; } public bool isIconActive { get; private set; }
public bool isAnimationEnd { get; internal set; } public bool isAnimationEnd { get; internal set; }
public Rect rect { get; set; }
internal RectTransform objectRect internal RectTransform objectRect
{ {

View File

@@ -51,7 +51,7 @@ namespace XCharts.Runtime
Init(); Init();
} }
internal void CheckRefresh() public void CheckRefresh()
{ {
if (m_Refresh && gameObject.activeSelf) if (m_Refresh && gameObject.activeSelf)
{ {

View File

@@ -324,14 +324,20 @@ namespace XCharts.Runtime
if (background == null) return; if (background == null) return;
if (imageStyle.show) if (imageStyle.show)
{ {
background.gameObject.SetActive(true);
background.sprite = imageStyle.sprite; background.sprite = imageStyle.sprite;
background.color = imageStyle.color; background.color = imageStyle.color;
background.type = imageStyle.type; background.type = imageStyle.type;
if (imageStyle.width > 0 && imageStyle.height > 0)
{
background.rectTransform.sizeDelta = new Vector2(imageStyle.width, imageStyle.height);
}
} }
else else
{ {
background.sprite = null; background.sprite = null;
background.color = Color.clear; background.color = Color.clear;
background.gameObject.SetActive(false);
} }
} }