UI update 02
This commit is contained in:
@@ -0,0 +1,337 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Grid component.
|
||||
/// ||Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart can be drawn in grid.
|
||||
/// ||网格组件。
|
||||
/// 直角坐标系内绘图网格。可以在网格上绘制折线图,柱状图,散点图。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(GridCoordHandler), true)]
|
||||
public class GridCoord : CoordSystem, IUpdateRuntimeData, ISerieContainer
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField][Since("v3.8.0")] private int m_LayoutIndex = -1;
|
||||
[SerializeField] private float m_Left = 0.11f;
|
||||
[SerializeField] private float m_Right = 0.08f;
|
||||
[SerializeField] private float m_Top = 0.22f;
|
||||
[SerializeField] private float m_Bottom = 0.14f;
|
||||
[SerializeField] private Color32 m_BackgroundColor;
|
||||
[SerializeField] private bool m_ShowBorder = false;
|
||||
[SerializeField] private float m_BorderWidth = 0f;
|
||||
[SerializeField] private Color32 m_BorderColor;
|
||||
|
||||
public GridCoordContext context = new GridCoordContext();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the grid in rectangular coordinate.
|
||||
/// ||是否显示直角坐标系网格。
|
||||
/// </summary>
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The index of the grid layout component to which the grid belongs.
|
||||
/// The default is -1, which means that it does not belong to any grid layout component.
|
||||
/// When this value is set, the left, right, top, and bottom properties will be invalid.
|
||||
/// ||网格所属的网格布局组件的索引。默认为-1,表示不属于任何网格布局组件。当设置了该值时,left、right、top、bottom属性将失效。
|
||||
/// </summary>
|
||||
public int layoutIndex
|
||||
{
|
||||
get { return m_LayoutIndex; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_LayoutIndex, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the left side of the container.
|
||||
/// ||grid 组件离容器左侧的距离。
|
||||
/// </summary>
|
||||
public float left
|
||||
{
|
||||
get { return m_Left; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the right side of the container.
|
||||
/// ||grid 组件离容器右侧的距离。
|
||||
/// </summary>
|
||||
public float right
|
||||
{
|
||||
get { return m_Right; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the top side of the container.
|
||||
/// ||grid 组件离容器上侧的距离。
|
||||
/// </summary>
|
||||
public float top
|
||||
{
|
||||
get { return m_Top; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the bottom side of the container.
|
||||
/// ||grid 组件离容器下侧的距离。
|
||||
/// </summary>
|
||||
public float bottom
|
||||
{
|
||||
get { return m_Bottom; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Background color of grid, which is transparent by default.
|
||||
/// ||网格背景色,默认透明。
|
||||
/// </summary>
|
||||
public Color32 backgroundColor
|
||||
{
|
||||
get { return m_BackgroundColor; }
|
||||
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to show the grid border.
|
||||
/// ||是否显示网格边框。
|
||||
/// </summary>
|
||||
public bool showBorder
|
||||
{
|
||||
get { return m_ShowBorder; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ShowBorder, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Border width of grid.
|
||||
/// ||网格边框宽。
|
||||
/// </summary>
|
||||
public float borderWidth
|
||||
{
|
||||
get { return m_BorderWidth; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The color of grid border.
|
||||
/// ||网格边框颜色。
|
||||
/// </summary>
|
||||
public Color32 borderColor
|
||||
{
|
||||
get { return m_BorderColor; }
|
||||
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
var chartX = chart.chartX;
|
||||
var chartY = chart.chartY;
|
||||
var chartWidth = chart.chartWidth;
|
||||
var chartHeight = chart.chartHeight;
|
||||
if (layoutIndex >= 0)
|
||||
{
|
||||
var layout = chart.GetChartComponent<GridLayout>(layoutIndex);
|
||||
if (layout != null)
|
||||
{
|
||||
layout.UpdateRuntimeData(chart);
|
||||
layout.UpdateGridContext(index, ref chartX, ref chartY, ref chartWidth, ref chartHeight);
|
||||
}
|
||||
}
|
||||
var actualLeft = left <= 1 ? left * chartWidth : left;
|
||||
var actualBottom = bottom <= 1 ? bottom * chartHeight : bottom;
|
||||
var actualTop = top <= 1 ? top * chartHeight : top;
|
||||
var actualRight = right <= 1 ? right * chartWidth : right;
|
||||
context.x = chartX + actualLeft;
|
||||
context.y = chartY + actualBottom;
|
||||
context.width = chartWidth - actualLeft - actualRight;
|
||||
context.height = chartHeight - actualTop - actualBottom;
|
||||
context.position = new Vector3(context.x, context.y);
|
||||
context.center = new Vector3(context.x + context.width / 2, context.y + context.height / 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the pointer is in the grid.
|
||||
/// ||指针是否在网格内。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsPointerEnter()
|
||||
{
|
||||
return context.isPointerEnter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given position is in the grid.
|
||||
/// ||给定的位置是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(Vector3 pos)
|
||||
{
|
||||
return Contains(pos.x, pos.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given position is in the grid.
|
||||
/// ||给定的位置是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <param name="isYAxis"></param>
|
||||
/// <returns></returns>
|
||||
[Since("v3.7.0")]
|
||||
public bool Contains(Vector3 pos, bool isYAxis)
|
||||
{
|
||||
return isYAxis ? ContainsY(pos.y) : ContainsX(pos.x);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given position is in the grid.
|
||||
/// ||给定的位置是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(float x, float y)
|
||||
{
|
||||
return ContainsX(x) && ContainsY(y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given x is in the grid.
|
||||
/// ||给定的x是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <returns></returns>
|
||||
[Since("v3.7.0")]
|
||||
public bool ContainsX(float x)
|
||||
{
|
||||
return x >= context.x - 0.01f && x <= context.x + context.width + 0.01f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given y is in the grid.
|
||||
/// ||给定的y是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
[Since("v3.7.0")]
|
||||
public bool ContainsY(float y)
|
||||
{
|
||||
return y >= context.y - 0.01f && y <= context.y + context.height + 0.01f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamp the position of pos to the grid.
|
||||
/// ||将位置限制在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
[Since("v3.7.0")]
|
||||
public void Clamp(ref Vector3 pos)
|
||||
{
|
||||
ClampX(ref pos);
|
||||
ClampY(ref pos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamp the x position of pos to the grid.
|
||||
/// ||将位置的X限制在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
[Since("v3.7.0")]
|
||||
public void ClampX(ref Vector3 pos)
|
||||
{
|
||||
if (pos.x < context.x) pos.x = context.x;
|
||||
else if (pos.x > context.x + context.width) pos.x = context.x + context.width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamp the y position of pos to the grid.
|
||||
/// ||将位置的Y限制在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
[Since("v3.7.0")]
|
||||
public void ClampY(ref Vector3 pos)
|
||||
{
|
||||
if (pos.y < context.y) pos.y = context.y;
|
||||
else if (pos.y > context.y + context.height) pos.y = context.y + context.height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a given line segment will not intersect the Grid boundary at all.
|
||||
/// ||判断给定的线段是否与Grid边界是否完全不会相交。
|
||||
/// </summary>
|
||||
/// <param name="sp"></param>
|
||||
/// <param name="ep"></param>
|
||||
/// <returns></returns>
|
||||
[Since("v3.10.0")]
|
||||
public bool NotAnyIntersect(Vector3 sp, Vector3 ep)
|
||||
{
|
||||
if (sp.x < context.x && ep.x < context.x)
|
||||
return true;
|
||||
if (sp.x > context.x + context.width && ep.x > context.x + context.width)
|
||||
return true;
|
||||
if (sp.y < context.y && ep.y < context.y)
|
||||
return true;
|
||||
if (sp.y > context.y + context.height && ep.y > context.y + context.height)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给定的线段和Grid边界的交点
|
||||
/// </summary>
|
||||
/// <param name="sp"></param>
|
||||
/// <param name="ep"></param>
|
||||
/// <returns></returns>
|
||||
public bool BoundaryPoint(Vector3 sp, Vector3 ep, ref Vector3 point)
|
||||
{
|
||||
if (Contains(sp) && Contains(ep))
|
||||
return false;
|
||||
if (sp.x < context.x && ep.x < context.x)
|
||||
return false;
|
||||
if (sp.x > context.x + context.width && ep.x > context.x + context.width)
|
||||
return false;
|
||||
if (sp.y < context.y && ep.y < context.y)
|
||||
return false;
|
||||
if (sp.y > context.y + context.height && ep.y > context.y + context.height)
|
||||
return false;
|
||||
var lb = new Vector3(context.x, context.y);
|
||||
var lt = new Vector3(context.x, context.y + context.height);
|
||||
var rt = new Vector3(context.x + context.width, context.y + context.height);
|
||||
var rb = new Vector3(context.x + context.width, context.y);
|
||||
if (UGLHelper.GetIntersection(sp, ep, rb, rt, ref point))
|
||||
return true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lt, rt, ref point))
|
||||
return true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lb, rb, ref point))
|
||||
return true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lb, lt, ref point))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给定的线段和Grid边界的交点
|
||||
/// </summary>
|
||||
/// <param name="sp"></param>
|
||||
/// <param name="ep"></param>
|
||||
/// <returns></returns>
|
||||
public bool BoundaryPoint(Vector3 sp, Vector3 ep, ref List<Vector3> point)
|
||||
{
|
||||
if (Contains(sp) && Contains(ep))
|
||||
return false;
|
||||
var lb = new Vector3(context.x, context.y);
|
||||
var lt = new Vector3(context.x, context.y + context.height);
|
||||
var rt = new Vector3(context.x + context.width, context.y + context.height);
|
||||
var rb = new Vector3(context.x + context.width, context.y);
|
||||
var flag = false;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lb, lt, ref point))
|
||||
flag = true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lt, rt, ref point))
|
||||
flag = true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lb, rb, ref point))
|
||||
flag = true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, rb, rt, ref point))
|
||||
flag = true;
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f99c74cc7f2c44bfcae9f5c40e6b7c46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class GridCoordContext : MainComponentContext
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float width;
|
||||
public float height;
|
||||
public Vector3 position;
|
||||
public Vector3 center;
|
||||
public bool isPointerEnter;
|
||||
public List<ChartLabel> endLabelList = new List<ChartLabel>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a7c139761fe64d93be4c65619a0fd38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,95 @@
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class GridCoordHandler : MainComponentHandler<GridCoord>
|
||||
{
|
||||
public override void InitComponent()
|
||||
{
|
||||
var grid = component;
|
||||
grid.painter = chart.painter;
|
||||
grid.refreshComponent = delegate ()
|
||||
{
|
||||
grid.UpdateRuntimeData(chart);
|
||||
chart.OnCoordinateChanged();
|
||||
};
|
||||
grid.refreshComponent();
|
||||
}
|
||||
|
||||
public override void CheckComponent(StringBuilder sb)
|
||||
{
|
||||
var grid = component;
|
||||
if (grid.left >= chart.chartWidth)
|
||||
sb.Append("warning:grid->left > chartWidth\n");
|
||||
if (grid.right >= chart.chartWidth)
|
||||
sb.Append("warning:grid->right > chartWidth\n");
|
||||
if (grid.top >= chart.chartHeight)
|
||||
sb.Append("warning:grid->top > chartHeight\n");
|
||||
if (grid.bottom >= chart.chartHeight)
|
||||
sb.Append("warning:grid->bottom > chartHeight\n");
|
||||
if (grid.left + grid.right >= chart.chartWidth)
|
||||
sb.Append("warning:grid.left + grid.right > chartWidth\n");
|
||||
if (grid.top + grid.bottom >= chart.chartHeight)
|
||||
sb.Append("warning:grid.top + grid.bottom > chartHeight\n");
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (chart.isPointerInChart)
|
||||
{
|
||||
component.context.isPointerEnter = component.Contains(chart.pointerPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
component.context.isPointerEnter = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawBase(VertexHelper vh)
|
||||
{
|
||||
DrawBackground(vh, component);
|
||||
if (!SeriesHelper.IsAnyClipSerie(chart.series))
|
||||
{
|
||||
DrawCoord(vh, component);
|
||||
}
|
||||
}
|
||||
public override void DrawUpper(VertexHelper vh)
|
||||
{
|
||||
if (SeriesHelper.IsAnyClipSerie(chart.series))
|
||||
{
|
||||
DrawCoord(vh, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(VertexHelper vh, GridCoord grid)
|
||||
{
|
||||
if (!grid.show) return;
|
||||
if (!ChartHelper.IsClearColor(grid.backgroundColor))
|
||||
{
|
||||
var p1 = new Vector2(grid.context.x, grid.context.y);
|
||||
var p2 = new Vector2(grid.context.x, grid.context.y + grid.context.height);
|
||||
var p3 = new Vector2(grid.context.x + grid.context.width, grid.context.y + grid.context.height);
|
||||
var p4 = new Vector2(grid.context.x + grid.context.width, grid.context.y);
|
||||
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, grid.backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCoord(VertexHelper vh, GridCoord grid)
|
||||
{
|
||||
if (!grid.show) return;
|
||||
if (grid.showBorder)
|
||||
{
|
||||
var borderWidth = grid.borderWidth == 0 ? chart.theme.axis.lineWidth * 2 : grid.borderWidth;
|
||||
var borderColor = ChartHelper.IsClearColor(grid.borderColor) ?
|
||||
chart.theme.axis.lineColor :
|
||||
grid.borderColor;
|
||||
UGL.DrawBorder(vh, grid.context.center, grid.context.width - borderWidth,
|
||||
grid.context.height - borderWidth, borderWidth, borderColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e22a9b603e57459f97040b285f3936a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class GridLayoutContext : MainComponentContext
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float width;
|
||||
public float height;
|
||||
public float eachWidth;
|
||||
public float eachHeight;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7265c042ebd33458eb12c112d46d9a60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class GridLayoutHandler : MainComponentHandler<GridLayout>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b1c1f0fa475b484286b0b2c688dc3c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Grid layout component. Used to manage the layout of multiple `GridCoord`, and the number of rows and columns of the grid can be controlled by `row` and `column`.
|
||||
/// ||网格布局组件。用于管理多个`GridCoord`的布局,可以通过`row`和`column`来控制网格的行列数。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(GridLayoutHandler), true)]
|
||||
public class GridLayout : MainComponent, IUpdateRuntimeData
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float m_Left = 0.1f;
|
||||
[SerializeField] private float m_Right = 0.08f;
|
||||
[SerializeField] private float m_Top = 0.22f;
|
||||
[SerializeField] private float m_Bottom = 0.12f;
|
||||
[SerializeField] private int m_Row = 2;
|
||||
[SerializeField] private int m_Column = 2;
|
||||
[SerializeField] private Vector2 m_Spacing = Vector2.zero;
|
||||
[SerializeField] protected bool m_Inverse = false;
|
||||
|
||||
public GridLayoutContext context = new GridLayoutContext();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the grid in rectangular coordinate.
|
||||
/// ||是否显示直角坐标系网格。
|
||||
/// </summary>
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the left side of the container.
|
||||
/// ||grid 组件离容器左侧的距离。
|
||||
/// </summary>
|
||||
public float left
|
||||
{
|
||||
get { return m_Left; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the right side of the container.
|
||||
/// ||grid 组件离容器右侧的距离。
|
||||
/// </summary>
|
||||
public float right
|
||||
{
|
||||
get { return m_Right; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the top side of the container.
|
||||
/// ||grid 组件离容器上侧的距离。
|
||||
/// </summary>
|
||||
public float top
|
||||
{
|
||||
get { return m_Top; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the bottom side of the container.
|
||||
/// ||grid 组件离容器下侧的距离。
|
||||
/// </summary>
|
||||
public float bottom
|
||||
{
|
||||
get { return m_Bottom; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the row count of grid layout.
|
||||
/// ||网格布局的行数。
|
||||
/// </summary>
|
||||
public int row
|
||||
{
|
||||
get { return m_Row; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Row, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the column count of grid layout.
|
||||
/// ||网格布局的列数。
|
||||
/// </summary>
|
||||
public int column
|
||||
{
|
||||
get { return m_Column; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Column, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the spacing of grid layout.
|
||||
/// ||网格布局的间距。
|
||||
/// </summary>
|
||||
public Vector2 spacing
|
||||
{
|
||||
get { return m_Spacing; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Spacing, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to inverse the grid layout.
|
||||
/// ||是否反转网格布局。
|
||||
/// </summary>
|
||||
public bool inverse
|
||||
{
|
||||
get { return m_Inverse; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Inverse, value)) SetAllDirty(); }
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
var chartX = chart.chartX;
|
||||
var chartY = chart.chartY;
|
||||
var chartWidth = chart.chartWidth;
|
||||
var chartHeight = chart.chartHeight;
|
||||
var actualLeft = left <= 1 ? left * chartWidth : left;
|
||||
var actualBottom = bottom <= 1 ? bottom * chartHeight : bottom;
|
||||
var actualTop = top <= 1 ? top * chartHeight : top;
|
||||
var actualRight = right <= 1 ? right * chartWidth : right;
|
||||
context.x = chartX + actualLeft;
|
||||
context.y = chartY + actualBottom;
|
||||
context.width = chartWidth - actualLeft - actualRight;
|
||||
context.height = chartHeight - actualTop - actualBottom;
|
||||
context.eachWidth = (context.width - spacing.x * (column - 1)) / column;
|
||||
context.eachHeight = (context.height - spacing.y * (row - 1)) / row;
|
||||
}
|
||||
|
||||
internal void UpdateGridContext(int index, ref float x, ref float y, ref float width, ref float height)
|
||||
{
|
||||
var row = index / m_Column;
|
||||
var column = index % m_Column;
|
||||
|
||||
x = context.x + column * (context.eachWidth + spacing.x);
|
||||
if(m_Inverse)
|
||||
y = context.y + row * (context.eachHeight + spacing.y);
|
||||
else
|
||||
y = context.y + context.height - (row + 1) * context.eachHeight - row * spacing.y;
|
||||
width = context.eachWidth;
|
||||
height = context.eachHeight;
|
||||
}
|
||||
|
||||
internal void UpdateGridContext(int index, ref Vector3 position, ref float width, ref float height)
|
||||
{
|
||||
float x = 0, y = 0;
|
||||
UpdateGridContext(index, ref x, ref y, ref width, ref height);
|
||||
position = new Vector3(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 691ae1f57760b4a948c94f3faa0ef6f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user