This commit is contained in:
monitor1394
2022-03-18 08:23:17 +08:00
parent 407b3625d7
commit 4e24ba7922
16 changed files with 166 additions and 114 deletions

View File

@@ -1,33 +0,0 @@
namespace XCharts.Runtime
{
internal static class XAxisPool
{
private static readonly ObjectPool<XAxis> s_ListPool = new ObjectPool<XAxis>(null, null);
public static XAxis Get()
{
return s_ListPool.Get();
}
public static void Release(XAxis toRelease)
{
s_ListPool.Release(toRelease);
}
}
internal static class YAxisPool
{
private static readonly ObjectPool<YAxis> s_ListPool = new ObjectPool<YAxis>(null, null);
public static YAxis Get()
{
return s_ListPool.Get();
}
public static void Release(YAxis toRelease)
{
s_ListPool.Release(toRelease);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3a709ca44e9a445bd86bde1bbfae80de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,6 +7,7 @@ namespace XCharts.Runtime
{
internal class ObjectPool<T> where T : new()
{
private readonly bool m_NewIfEmpty = true;
private readonly Stack<T> m_Stack = new Stack<T>();
private readonly UnityAction<T> m_ActionOnGet;
private readonly UnityAction<T> m_ActionOnRelease;
@@ -15,8 +16,9 @@ namespace XCharts.Runtime
public int countActive { get { return countAll - countInactive; } }
public int countInactive { get { return m_Stack.Count; } }
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease, bool newIfEmpty = true)
{
m_NewIfEmpty = newIfEmpty;
m_ActionOnGet = actionOnGet;
m_ActionOnRelease = actionOnRelease;
}
@@ -26,6 +28,7 @@ namespace XCharts.Runtime
T element;
if (m_Stack.Count == 0)
{
if (!m_NewIfEmpty) return default(T);
element = new T();
countAll++;
}

View File

@@ -1,7 +1,6 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
@@ -37,15 +36,6 @@ namespace XCharts.Runtime
return element;
}
private static GameObject CreateSerieLabel(string name, Transform parent, LabelStyle label, Color color,
float iconWidth, float iconHeight, ThemeStyle theme)
{
var element = ChartHelper.AddSerieLabel(name, parent, label.backgroundWidth, label.backgroundHeight,
color, label.textStyle, theme);
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
return element;
}
public static void Release(GameObject element)
{
if (element == null) return;
@@ -72,5 +62,14 @@ namespace XCharts.Runtime
m_Stack.Clear();
m_ReleaseDic.Clear();
}
private static GameObject CreateSerieLabel(string name, Transform parent, LabelStyle label, Color color,
float iconWidth, float iconHeight, ThemeStyle theme)
{
var element = ChartHelper.AddSerieLabel(name, parent, label.backgroundWidth, label.backgroundHeight,
color, label.textStyle, theme);
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
return element;
}
}
}