代码优化

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);
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();
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.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
@@ -170,5 +171,21 @@ namespace XCharts.Runtime
}
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 isIconActive { get; private set; }
public bool isAnimationEnd { get; internal set; }
public Rect rect { get; set; }
internal RectTransform objectRect
{

View File

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

View File

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