작업 조건 분석 기능 개발
This commit is contained in:
185
Assets/Chart And Graph/Script/PieChart/CanvasPieChart.cs
Normal file
185
Assets/Chart And Graph/Script/PieChart/CanvasPieChart.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// canvas pie chart component
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[Serializable]
|
||||
public class CanvasPieChart : PieChart, ICanvas
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("prefab for the pie item. must contain a PieCanvasGenerator component")]
|
||||
private PieCanvasGenerator prefab;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("the thickness of the guideline between each slice and it's label")]
|
||||
private float lineThickness = 1f;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The line spacing for each category label line")]
|
||||
private float lineSpacing = 20f;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The line material for each category label line")]
|
||||
private Material lineMaterial;
|
||||
|
||||
[SerializeField]
|
||||
private bool fitToContainer;
|
||||
|
||||
public RectTransform Container;
|
||||
public Text Title;
|
||||
public Text Info;
|
||||
public Image Image;
|
||||
|
||||
public CanvasPieChart()
|
||||
{
|
||||
radius = 40f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// prefab for the pie item. must contain a PieCanvasGenerator component
|
||||
/// </summary>
|
||||
public PieCanvasGenerator Prefab
|
||||
{
|
||||
get { return prefab; }
|
||||
set
|
||||
{
|
||||
prefab = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public bool FitToContainer
|
||||
{
|
||||
get { return fitToContainer; }
|
||||
set
|
||||
{
|
||||
fitToContainer = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsCanvas
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
protected override float InnerDepthLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
protected override float OuterDepthLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
protected override Material LineMaterialLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return lineMaterial;
|
||||
}
|
||||
}
|
||||
protected override float LineThicknessLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return lineThickness;
|
||||
}
|
||||
}
|
||||
protected override float LineSpacingLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return lineSpacing;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The line spacing for eacg category label line
|
||||
/// </summary>
|
||||
public float LineSpacing
|
||||
{
|
||||
get { return lineSpacing; }
|
||||
set
|
||||
{
|
||||
lineSpacing = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
protected override void ValidateProperties()
|
||||
{
|
||||
base.ValidateProperties();
|
||||
if (lineSpacing < 0f)
|
||||
lineSpacing = 0f;
|
||||
if (lineThickness < 1f)
|
||||
lineThickness = 1f;
|
||||
}
|
||||
/// <summary>
|
||||
/// the thickness of the guideline between each slice and it's label
|
||||
/// </summary>
|
||||
public float LineThickness
|
||||
{
|
||||
get { return lineThickness; }
|
||||
set
|
||||
{
|
||||
lineThickness = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The line material for each category label line
|
||||
/// </summary>
|
||||
public Material LineMaterial
|
||||
{
|
||||
get { return lineMaterial; }
|
||||
set
|
||||
{
|
||||
lineMaterial = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public override void InternalGenerateChart()
|
||||
{
|
||||
if(FitToContainer)
|
||||
{
|
||||
var rect = GetComponent<RectTransform>();
|
||||
if(rect != null)
|
||||
{
|
||||
float finalRadius = Math.Min(rect.rect.size.x, rect.rect.size.y)*0.5f;
|
||||
radius = finalRadius;
|
||||
}
|
||||
}
|
||||
base.InternalGenerateChart();
|
||||
if (TextController != null && TextController.gameObject)
|
||||
TextController.gameObject.transform.SetAsLastSibling();
|
||||
}
|
||||
protected override IPieGenerator PreparePieObject(out GameObject pieObject)
|
||||
{
|
||||
if(Prefab == null)
|
||||
pieObject = new GameObject();
|
||||
else
|
||||
pieObject = GameObject.Instantiate(Prefab.gameObject);
|
||||
ChartCommon.HideObject(pieObject, hideHierarchy);
|
||||
ChartCommon.EnsureComponent<RectTransform>(pieObject);
|
||||
ChartCommon.EnsureComponent <CanvasRenderer>(pieObject);
|
||||
return ChartCommon.EnsureComponent<PieCanvasGenerator>(pieObject);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad4d11f0b40946e4787e4581407e3b51
|
||||
timeCreated: 1480086761
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Chart And Graph/Script/PieChart/IPieGenerator.cs
Normal file
16
Assets/Chart And Graph/Script/PieChart/IPieGenerator.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// base interface for pie mesh generators
|
||||
/// </summary>
|
||||
public interface IPieGenerator
|
||||
{
|
||||
void Generate(float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerDepth,float innerDepth);
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/PieChart/IPieGenerator.cs.meta
Normal file
12
Assets/Chart And Graph/Script/PieChart/IPieGenerator.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad7eedda43a6caa4e87c9c232f667b1c
|
||||
timeCreated: 1480006550
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
106
Assets/Chart And Graph/Script/PieChart/PieCanvasGenerator.cs
Normal file
106
Assets/Chart And Graph/Script/PieChart/PieCanvasGenerator.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// generates a pie mesh for use with canvas charts
|
||||
/// </summary>
|
||||
public class PieCanvasGenerator : Image, IPieGenerator, ICanvasRaycastFilter
|
||||
{
|
||||
bool mPopulated = false;
|
||||
float mStartAngle;
|
||||
float mAngleSpan;
|
||||
float mRadius;
|
||||
float mInnerRadius;
|
||||
int mSegements;
|
||||
|
||||
#pragma warning disable 0672
|
||||
|
||||
protected override void OnFillVBO(List<UIVertex> vbo)
|
||||
{
|
||||
vbo.Clear();
|
||||
if (mPopulated == false)
|
||||
return;
|
||||
CanvasChartMesh mesh = new CanvasChartMesh(vbo);
|
||||
FillChartMesh(mesh);
|
||||
}
|
||||
|
||||
#pragma warning restore 0672
|
||||
|
||||
#if (!UNITY_5_2_0) && (!UNITY_5_2_1)
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
vh.Clear();
|
||||
if (mPopulated == false)
|
||||
return;
|
||||
CanvasChartMesh mesh = new CanvasChartMesh(vh);
|
||||
FillChartMesh(mesh);
|
||||
}
|
||||
#endif
|
||||
#pragma warning disable 0672
|
||||
#if !UNITY_2017_1_OR_NEWER
|
||||
protected override void OnPopulateMesh(Mesh m)
|
||||
{
|
||||
m.Clear();
|
||||
if (mPopulated == false)
|
||||
return;
|
||||
WorldSpaceChartMesh chartmesh = new WorldSpaceChartMesh(true);
|
||||
FillChartMesh(chartmesh);
|
||||
chartmesh.ApplyToMesh(m);
|
||||
}
|
||||
#endif
|
||||
#pragma warning restore 0672
|
||||
|
||||
void FillChartMesh(IChartMesh mesh)
|
||||
{
|
||||
PieMesh.Generate2dMesh(mesh, mStartAngle, mAngleSpan, mRadius, mInnerRadius, mSegements);
|
||||
}
|
||||
|
||||
public void Generate(float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerdepth,float innerdepth)
|
||||
{
|
||||
float maxRad = Mathf.Max(radius, innerRadius)*2f;
|
||||
rectTransform.sizeDelta = new Vector2(maxRad,maxRad);
|
||||
mPopulated = true;
|
||||
mStartAngle = startAngle;
|
||||
mAngleSpan = angleSpan;
|
||||
mRadius = radius;
|
||||
mInnerRadius = innerRadius;
|
||||
mSegements = segments;
|
||||
SetAllDirty();
|
||||
Rebuild(CanvasUpdate.PreRender);
|
||||
}
|
||||
|
||||
public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
|
||||
{
|
||||
Vector2 localPoint;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, sp, eventCamera, out localPoint);
|
||||
|
||||
float sqrMag =localPoint.sqrMagnitude;
|
||||
float maxRad = mRadius;
|
||||
float minRad = mInnerRadius;
|
||||
|
||||
if(mRadius < mInnerRadius)
|
||||
{
|
||||
maxRad = mInnerRadius;
|
||||
minRad = mRadius;
|
||||
}
|
||||
|
||||
if (sqrMag > maxRad * maxRad)
|
||||
return false;
|
||||
if (sqrMag < minRad * minRad)
|
||||
return false;
|
||||
float angle = Mathf.Atan2(localPoint.y, localPoint.x);
|
||||
float delta = (angle - mStartAngle);
|
||||
delta -= Mathf.Floor(delta / (Mathf.PI * 2f)) *Mathf.PI*2f;
|
||||
if (delta > mAngleSpan)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c52ecc5ece3ab64fa56f251452f252f
|
||||
timeCreated: 1479835948
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
778
Assets/Chart And Graph/Script/PieChart/PieChart.cs
Normal file
778
Assets/Chart And Graph/Script/PieChart/PieChart.cs
Normal file
@@ -0,0 +1,778 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// Pie chart class
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
[Serializable]
|
||||
public abstract class PieChart : AnyChart
|
||||
{
|
||||
public class PieEventArgs
|
||||
{
|
||||
public PieEventArgs(string category,double value,Vector3 labelPos)
|
||||
{
|
||||
Value = value;
|
||||
Category = category;
|
||||
LabelPosition = labelPos;
|
||||
}
|
||||
public double Value { get; private set; }
|
||||
public string Category { get; private set; }
|
||||
public Vector3 LabelPosition { get; private set; }
|
||||
}
|
||||
|
||||
bool mQuick = false;
|
||||
[Serializable]
|
||||
public class PieEvent : UnityEvent<PieEventArgs>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// occures when a pie item is clicked
|
||||
/// </summary>
|
||||
public PieEvent PieClicked = new PieEvent();
|
||||
|
||||
/// <summary>
|
||||
/// occures when a pie item is hovered
|
||||
/// </summary>
|
||||
public PieEvent PieHovered = new PieEvent();
|
||||
|
||||
/// <summary>
|
||||
/// occurs when no pie is hovered any longer
|
||||
/// </summary>
|
||||
public UnityEvent NonHovered = new UnityEvent();
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The number of mesh segements in each pie slice")]
|
||||
private int meshSegements = 20;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The start angle of the pie chart")]
|
||||
private float startAngle =0;
|
||||
|
||||
[SerializeField]
|
||||
[Range(0f,360f)]
|
||||
[Tooltip("The angle span of the pie chart")]
|
||||
private float angleSpan = 360;
|
||||
|
||||
[SerializeField]
|
||||
[Range(0f, 360f)]
|
||||
[Tooltip("The spacing angle of the pie chart")]
|
||||
private float spacingAngle;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The outer radius of the pie chart")]
|
||||
protected float radius;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The inner radius of the pie chart")]
|
||||
private float torusRadius;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The extrusion of each pie slice")]
|
||||
private float extrusion;
|
||||
|
||||
|
||||
[HideInInspector]
|
||||
[SerializeField]
|
||||
private PieData Data = new PieData();
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("draw the pie in a clockwise order ")]
|
||||
private bool clockWise = false;
|
||||
|
||||
|
||||
GameObject mFixPositionPie = null;
|
||||
public bool ClockWise
|
||||
{
|
||||
get { return clockWise; }
|
||||
set
|
||||
{
|
||||
clockWise = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override IChartData DataLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return Data;
|
||||
}
|
||||
}
|
||||
public PieData DataSource
|
||||
{
|
||||
get { return Data; }
|
||||
}
|
||||
|
||||
protected abstract float LineSpacingLink
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
protected abstract float LineThicknessLink
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
protected abstract Material LineMaterialLink
|
||||
{
|
||||
get;
|
||||
}
|
||||
protected override float TotalDepthLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
protected override float TotalHeightLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return (radius+extrusion) * 2f;
|
||||
}
|
||||
}
|
||||
|
||||
protected override float TotalWidthLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return (radius + extrusion) * 2f;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The number of mesh segements in each pie slice
|
||||
/// </summary>
|
||||
public int MeshSegements
|
||||
{
|
||||
get { return meshSegements; }
|
||||
set
|
||||
{
|
||||
meshSegements = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The angle span of the pie chart
|
||||
/// </summary>
|
||||
public float AngleSpan
|
||||
{
|
||||
get { return angleSpan; }
|
||||
set
|
||||
{
|
||||
angleSpan = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The spacing angle of the pie chart
|
||||
/// </summary>
|
||||
public float SpacingAngle
|
||||
{
|
||||
get { return spacingAngle; }
|
||||
set
|
||||
{
|
||||
spacingAngle = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
public override bool SupportRealtimeGeneration
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The outer radius of the pie chart
|
||||
/// </summary>
|
||||
public float Radius
|
||||
{
|
||||
get { return radius; }
|
||||
set
|
||||
{
|
||||
radius = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The inner radius of the pie chart
|
||||
/// </summary>
|
||||
public float TorusRadius
|
||||
{
|
||||
get { return torusRadius; }
|
||||
set
|
||||
{
|
||||
torusRadius = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The start angle of the pie chart
|
||||
/// </summary>
|
||||
public float StartAngle
|
||||
{
|
||||
get { return startAngle; }
|
||||
set
|
||||
{
|
||||
startAngle = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The extrusion of each pie slice
|
||||
/// </summary>
|
||||
public float Extrusion
|
||||
{
|
||||
get { return extrusion; }
|
||||
set
|
||||
{
|
||||
extrusion = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDidApplyAnimationProperties()
|
||||
{
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
protected abstract float InnerDepthLink
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
protected abstract float OuterDepthLink
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
protected override LegenedData LegendInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
LegenedData legend = new LegenedData();
|
||||
if (Data == null)
|
||||
return legend;
|
||||
foreach (var column in ((IInternalPieData)Data).InternalDataSource.Columns)
|
||||
{
|
||||
var item = new LegenedData.LegenedItem();
|
||||
item.Name = column.Name;
|
||||
if (column.Material != null)
|
||||
item.Material = column.Material.Normal;
|
||||
else
|
||||
item.Material = null;
|
||||
legend.AddLegenedItem(item);
|
||||
}
|
||||
return legend;
|
||||
}
|
||||
}
|
||||
|
||||
public PieChart()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class PieObject
|
||||
{
|
||||
public string category;
|
||||
public float StartAngle;
|
||||
public float AngleSpan;
|
||||
public float Value;
|
||||
public GameObject TopObject;
|
||||
public IPieGenerator Generator;
|
||||
public BillboardText ItemLabel;
|
||||
public BillboardText CategoryLabel;
|
||||
public CanvasLines ItemLine = null;
|
||||
public CanvasLines CategoryLine = null;
|
||||
public Vector3 LabelPosition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the bars generated for the chart
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
Dictionary<string, PieObject> mPies = new Dictionary<string, PieObject>();
|
||||
|
||||
void HookEvents()
|
||||
{
|
||||
Data.ProperyUpdated -= Data_ProperyUpdated;
|
||||
Data.ProperyUpdated += Data_ProperyUpdated;
|
||||
((IInternalPieData)Data).InternalDataSource.DataStructureChanged -= MDataSource_DataStructureChanged;
|
||||
((IInternalPieData)Data).InternalDataSource.DataStructureChanged += MDataSource_DataStructureChanged;
|
||||
((IInternalPieData)Data).InternalDataSource.DataValueChanged -= MDataSource_DataValueChanged;
|
||||
((IInternalPieData)Data).InternalDataSource.DataValueChanged += MDataSource_DataValueChanged;
|
||||
}
|
||||
|
||||
private void Data_ProperyUpdated()
|
||||
{
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected void QuickInvalidate()
|
||||
{
|
||||
if (Invalidating)
|
||||
return;
|
||||
Invalidate();
|
||||
mQuick = true;
|
||||
}
|
||||
|
||||
public override void Invalidate()
|
||||
{
|
||||
base.Invalidate();
|
||||
mQuick = false;
|
||||
}
|
||||
|
||||
private void MDataSource_DataValueChanged(object sender, DataSource.ChartDataSourceBase.DataValueChangedEventArgs e)
|
||||
{
|
||||
QuickInvalidate();
|
||||
// GeneratePie(true);
|
||||
}
|
||||
|
||||
private void MDataSource_DataStructureChanged(object sender, EventArgs e)
|
||||
{
|
||||
Invalidate();
|
||||
// GenerateChart();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
if (ChartCommon.IsInEditMode == false)
|
||||
{
|
||||
HookEvents();
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnValidate()
|
||||
{
|
||||
base.OnValidate();
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
HookEvents();
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void ClearChart()
|
||||
{
|
||||
base.ClearChart();
|
||||
mPies.Clear();
|
||||
mFixPositionPie = null;
|
||||
}
|
||||
|
||||
Vector3 AlignTextPosition(AlignedItemLabels labels,PieObject obj,out CanvasLines.LineSegement line,float modifiedRaidus)
|
||||
{
|
||||
line = null;
|
||||
float angle = obj.StartAngle + obj.AngleSpan * 0.5f;
|
||||
Vector3 position = new Vector3(labels.Seperation,labels.Location.Breadth,labels.Location.Depth);
|
||||
position = Quaternion.AngleAxis(angle, Vector3.forward) * position;
|
||||
float alignRadius = (modifiedRaidus + TorusRadius) * 0.5f;
|
||||
Vector3 atAngle = (Vector3)ChartCommon.FromPolar(angle, 1f);
|
||||
if (labels.Alignment == ChartLabelAlignment.Top)
|
||||
{
|
||||
alignRadius = Mathf.Max(modifiedRaidus, TorusRadius);
|
||||
Vector3 basePosition = atAngle * alignRadius;
|
||||
Vector3 end = basePosition + position;
|
||||
end -= (position.normalized * LineSpacingLink);
|
||||
Vector4[] arr = new Vector4[] { basePosition, end };
|
||||
arr[0].w = -1f;
|
||||
arr[1].w = -1f;
|
||||
line = new CanvasLines.LineSegement(arr);
|
||||
}
|
||||
|
||||
position += atAngle * alignRadius;
|
||||
return position;
|
||||
}
|
||||
|
||||
private CanvasLines AddLineRenderer(GameObject topObject, CanvasLines.LineSegement line)
|
||||
{
|
||||
GameObject obj = ChartCommon.CreateCanvasChartItem();
|
||||
obj.transform.SetParent(topObject.transform);
|
||||
obj.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
obj.transform.localPosition = new Vector3(0f, 0f, 0f);
|
||||
obj.transform.localRotation = Quaternion.identity;
|
||||
ChartCommon.EnsureComponent<CanvasRenderer>(obj);
|
||||
CanvasLines lines = obj.AddComponent<CanvasLines>();
|
||||
lines.raycastTarget = false;
|
||||
var lst = new List<CanvasLines.LineSegement>();
|
||||
lst.Add(line);
|
||||
lines.SetLines(lst);
|
||||
lines.Thickness = LineThicknessLink;
|
||||
lines.material = LineMaterialLink;
|
||||
return lines;
|
||||
}
|
||||
public void SelectPieObject(string category,bool selected = true)
|
||||
{
|
||||
PieObject dataObject;
|
||||
if (mPies.TryGetValue(category, out dataObject))
|
||||
{
|
||||
var events = dataObject.TopObject.GetComponentInChildren<ChartItemEvents>();
|
||||
if(events != null)
|
||||
{
|
||||
events.Select(selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GeneratePie(bool update)
|
||||
{
|
||||
if (mFixPositionPie == null)
|
||||
update = false;
|
||||
if (update == false)
|
||||
ClearChart();
|
||||
else
|
||||
EnsureTextController();
|
||||
if (((IInternalPieData)Data).InternalDataSource == null)
|
||||
return;
|
||||
|
||||
double[,] data = ((IInternalPieData)Data).InternalDataSource.getRawData();
|
||||
int rowCount = data.GetLength(0);
|
||||
int columnCount = data.GetLength(1);
|
||||
|
||||
if (rowCount != 1) // row count for pie must be 1
|
||||
return;
|
||||
|
||||
double total = 0.0;
|
||||
|
||||
for (int i = 0; i < columnCount; ++i)
|
||||
{
|
||||
double val = Math.Max(data[0, i], 0);
|
||||
total += val;
|
||||
}
|
||||
|
||||
float start = startAngle;
|
||||
if (clockWise)
|
||||
start -= angleSpan;
|
||||
float totalGaps = columnCount * spacingAngle;
|
||||
float spanWithoutGaps = angleSpan - totalGaps;
|
||||
|
||||
if (spanWithoutGaps < 0f)
|
||||
spanWithoutGaps = 0f;
|
||||
|
||||
if (mFixPositionPie == null)
|
||||
{
|
||||
mFixPositionPie = new GameObject("FixPositionPie", typeof(ChartItem));
|
||||
ChartCommon.HideObject(mFixPositionPie, hideHierarchy);
|
||||
mFixPositionPie.transform.SetParent(transform, false);
|
||||
if (IsCanvas)
|
||||
{
|
||||
var rectTrans = mFixPositionPie.AddComponent<RectTransform>();
|
||||
rectTrans.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rectTrans.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rectTrans.pivot = new Vector2(0.5f, 0.5f);
|
||||
rectTrans.anchoredPosition = new Vector2(0.5f, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < columnCount; ++i)
|
||||
{
|
||||
object userData = ((IInternalPieData)Data).InternalDataSource.Columns[i].UserData;
|
||||
float radiusScale = 1f;
|
||||
float depthScale = 1f;
|
||||
float depthOffset = 0f;
|
||||
if (userData != null && userData is PieData.CategoryData)
|
||||
{
|
||||
radiusScale = ((PieData.CategoryData)userData).RadiusScale;
|
||||
depthScale = ((PieData.CategoryData)userData).DepthScale;
|
||||
depthOffset = ((PieData.CategoryData)userData).DepthOffset;
|
||||
}
|
||||
if (radiusScale <= 0.001f)
|
||||
radiusScale = 1f;
|
||||
if (depthScale <= 0.001f)
|
||||
depthScale = 1f;
|
||||
string name = ((IInternalPieData)Data).InternalDataSource.Columns[i].Name;
|
||||
double amount = Math.Max(data[0, i], 0);
|
||||
if (amount == 0f)
|
||||
continue;
|
||||
float weight = (float)(amount / total);
|
||||
float currentSpan = spanWithoutGaps * weight;
|
||||
GameObject pieObject = null;
|
||||
IPieGenerator generator = null;
|
||||
PieObject dataObject;
|
||||
CanvasLines.LineSegement line;
|
||||
float modifiedRadius = Mathf.Max(radius * radiusScale, torusRadius);
|
||||
// float modifiedDepth = d
|
||||
float lineAngle = start + currentSpan * 0.5f;
|
||||
if (mPies.TryGetValue(name, out dataObject))
|
||||
{
|
||||
dataObject.StartAngle = start;
|
||||
dataObject.AngleSpan = currentSpan;
|
||||
generator = dataObject.Generator;
|
||||
if (dataObject.ItemLabel)
|
||||
{
|
||||
Vector3 labelPos = AlignTextPosition(mItemLabels, dataObject, out line, modifiedRadius);
|
||||
dataObject.ItemLabel.transform.localPosition = labelPos;
|
||||
string toSet = ChartAdancedSettings.Instance.FormatFractionDigits(mItemLabels.FractionDigits, amount, CustomNumberFormat);
|
||||
toSet = mItemLabels.TextFormat.Format(toSet, name, "");
|
||||
ChartCommon.UpdateTextParams(dataObject.ItemLabel.UIText, toSet);
|
||||
if (dataObject.ItemLine != null)
|
||||
{
|
||||
var lst = new List<CanvasLines.LineSegement>();
|
||||
lst.Add(line);
|
||||
dataObject.ItemLine.SetLines(lst);
|
||||
}
|
||||
}
|
||||
if (dataObject.CategoryLabel != null)
|
||||
{
|
||||
Vector3 labelPos = AlignTextPosition(mCategoryLabels, dataObject, out line, modifiedRadius);
|
||||
dataObject.CategoryLabel.transform.localPosition = labelPos;
|
||||
if (dataObject.CategoryLine != null)
|
||||
{
|
||||
var lst = new List<CanvasLines.LineSegement>();
|
||||
lst.Add(line);
|
||||
dataObject.CategoryLine.SetLines(lst);
|
||||
}
|
||||
}
|
||||
Vector2 add = ChartCommon.FromPolar(start + currentSpan * 0.5f, Extrusion);
|
||||
dataObject.TopObject.transform.localPosition = new Vector3(add.x, add.y, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
GameObject topObject = new GameObject();
|
||||
if (IsCanvas)
|
||||
topObject.AddComponent<RectTransform>();
|
||||
ChartCommon.HideObject(topObject, hideHierarchy);
|
||||
topObject.AddComponent<ChartItem>();
|
||||
topObject.transform.SetParent(mFixPositionPie.transform);
|
||||
topObject.transform.localPosition = new Vector3();
|
||||
topObject.transform.localRotation = Quaternion.identity;
|
||||
topObject.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
|
||||
generator = PreparePieObject(out pieObject);
|
||||
|
||||
ChartCommon.EnsureComponent<ChartItem>(pieObject);
|
||||
ChartMaterialController control = ChartCommon.EnsureComponent<ChartMaterialController>(pieObject);
|
||||
control.Materials = Data.GetMaterial(name);
|
||||
control.Refresh();
|
||||
dataObject = new PieObject();
|
||||
dataObject.StartAngle = start;
|
||||
dataObject.AngleSpan = currentSpan;
|
||||
dataObject.TopObject = topObject;
|
||||
dataObject.Generator = generator;
|
||||
dataObject.category = name;
|
||||
var pieInfo = pieObject.AddComponent<PieInfo>();
|
||||
pieInfo.pieObject = dataObject;
|
||||
pieObject.transform.SetParent(topObject.transform);
|
||||
Vector2 add = ChartCommon.FromPolar(start + currentSpan * 0.5f, Extrusion);
|
||||
pieObject.transform.localPosition = new Vector3(0f, 0f, 0f);
|
||||
pieObject.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
pieObject.transform.localRotation = Quaternion.identity;
|
||||
mPies.Add(name,dataObject);
|
||||
|
||||
topObject.transform.localPosition = new Vector3(add.x, add.y, 0f);
|
||||
CharItemEffectController effect = ChartCommon.EnsureComponent<CharItemEffectController>(pieObject);
|
||||
effect.WorkOnParent = true;
|
||||
effect.InitialScale = false;
|
||||
|
||||
ChartItemEvents[] events = pieObject.GetComponentsInChildren<ChartItemEvents>();
|
||||
|
||||
for (int j = 0; j < events.Length; ++j)
|
||||
{
|
||||
if (events[j] == null)
|
||||
continue;
|
||||
InternalItemEvents comp = (InternalItemEvents)events[j];
|
||||
comp.Parent = this;
|
||||
comp.UserData = dataObject;
|
||||
}
|
||||
|
||||
if (mItemLabels)
|
||||
{
|
||||
Vector3 labelPosItem = AlignTextPosition(mItemLabels, dataObject, out line, modifiedRadius);
|
||||
dataObject.LabelPosition = labelPosItem;
|
||||
if (line != null && IsUnderCanvas)
|
||||
dataObject.ItemLine = AddLineRenderer(topObject, line);
|
||||
string toSet = ChartAdancedSettings.Instance.FormatFractionDigits(mItemLabels.FractionDigits, amount, CustomNumberFormat);
|
||||
toSet = mItemLabels.TextFormat.Format(toSet, name, "");
|
||||
|
||||
BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, topObject.transform, toSet, labelPosItem.x, labelPosItem.y, labelPosItem.z, lineAngle, topObject.transform, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness);
|
||||
dataObject.ItemLabel = billboard;
|
||||
TextController.AddText(billboard);
|
||||
}
|
||||
|
||||
|
||||
if (mCategoryLabels != null)
|
||||
{
|
||||
Vector3 labelPos = AlignTextPosition(mCategoryLabels, dataObject, out line, modifiedRadius);
|
||||
if (line != null && IsUnderCanvas)
|
||||
dataObject.CategoryLine = AddLineRenderer(topObject, line);
|
||||
string toSet = name;
|
||||
toSet = mCategoryLabels.TextFormat.Format(toSet, "", "");
|
||||
BillboardText billboard = ChartCommon.CreateBillboardText(null,mCategoryLabels.TextPrefab, topObject.transform, toSet, labelPos.x, labelPos.y, labelPos.z, lineAngle, topObject.transform, hideHierarchy, mCategoryLabels.FontSize, mCategoryLabels.FontSharpness);
|
||||
dataObject.CategoryLabel = billboard;
|
||||
TextController.AddText(billboard);
|
||||
}
|
||||
|
||||
}
|
||||
float maxDepth = Mathf.Max(OuterDepthLink, InnerDepthLink);
|
||||
float depthSize = maxDepth * depthScale;
|
||||
if (pieObject != null)
|
||||
{
|
||||
float depthStart = (maxDepth - depthSize) * 0.5f;
|
||||
pieObject.transform.localPosition = new Vector3(0f, 0f, depthStart - depthSize * depthOffset);
|
||||
}
|
||||
dataObject.Value =(float) data[0, i];
|
||||
generator.Generate(Mathf.Deg2Rad * start, Mathf.Deg2Rad * currentSpan, modifiedRadius, torusRadius, meshSegements, OuterDepthLink * depthScale,InnerDepthLink * depthScale);
|
||||
start += spacingAngle + currentSpan;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract IPieGenerator PreparePieObject(out GameObject pieObject);
|
||||
|
||||
|
||||
protected override void OnLabelSettingChanged()
|
||||
{
|
||||
base.OnLabelSettingChanged();
|
||||
Invalidate();
|
||||
}
|
||||
protected override void OnLabelSettingsSet()
|
||||
{
|
||||
base.OnLabelSettingsSet();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
public override void InternalGenerateChart()
|
||||
{
|
||||
if (gameObject.activeInHierarchy == false)
|
||||
return;
|
||||
base.InternalGenerateChart();
|
||||
GeneratePie(mQuick);
|
||||
mQuick = false;
|
||||
}
|
||||
|
||||
protected override bool HasValues(AxisBase axis)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override double MaxValue(AxisBase axis)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
protected override double MinValue(AxisBase axis)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyChanged()
|
||||
{
|
||||
QuickInvalidate();
|
||||
}
|
||||
|
||||
protected override void OnPropertyUpdated()
|
||||
{
|
||||
base.OnPropertyUpdated();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void ValidateProperties()
|
||||
{
|
||||
base.ValidateProperties();
|
||||
if (extrusion < 0)
|
||||
extrusion = 0f;
|
||||
if (radius < 0f)
|
||||
radius = 0;
|
||||
if (torusRadius < 0f)
|
||||
torusRadius = 0f;
|
||||
if (torusRadius > radius)
|
||||
torusRadius = radius;
|
||||
if (angleSpan < 10f)
|
||||
angleSpan = 10f;
|
||||
if (spacingAngle < 0f)
|
||||
spacingAngle = 0f;
|
||||
}
|
||||
|
||||
public Vector3 GetLabelPosition(string category)
|
||||
{
|
||||
PieObject pie;
|
||||
if (mPies.TryGetValue(category, out pie) == false)
|
||||
return Vector3.zero;
|
||||
if(pie.ItemLabel == null)
|
||||
return Vector3.zero;
|
||||
return pie.ItemLabel.transform.position;
|
||||
}
|
||||
|
||||
PieEventArgs userDataToEventArgs(object userData)
|
||||
{
|
||||
PieObject pie = (PieObject)userData;
|
||||
Vector3 labelPos = new Vector3();
|
||||
try
|
||||
{
|
||||
labelPos = pie.ItemLabel.transform.position;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return new PieEventArgs(pie.category, pie.Value, labelPos);
|
||||
}
|
||||
|
||||
protected override void OnNonHoverted()
|
||||
{
|
||||
base.OnNonHoverted();
|
||||
if (NonHovered != null)
|
||||
NonHovered.Invoke();
|
||||
}
|
||||
|
||||
protected override void OnItemHoverted(object userData)
|
||||
{
|
||||
base.OnItemHoverted(userData);
|
||||
if (PieHovered != null)
|
||||
PieHovered.Invoke(userDataToEventArgs(userData));
|
||||
}
|
||||
|
||||
protected override void OnItemSelected(object userData)
|
||||
{
|
||||
base.OnItemSelected(userData);
|
||||
var args = userDataToEventArgs(userData);
|
||||
if (PieClicked != null)
|
||||
PieClicked.Invoke(args);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected override bool SupportsCategoryLabels
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
protected override bool SupportsGroupLables
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected override bool SupportsItemLabels
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/PieChart/PieChart.cs.meta
Normal file
12
Assets/Chart And Graph/Script/PieChart/PieChart.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 630727875fd8dc345b298e3400ef1e8e
|
||||
timeCreated: 1479726850
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
404
Assets/Chart And Graph/Script/PieChart/PieData.cs
Normal file
404
Assets/Chart And Graph/Script/PieChart/PieData.cs
Normal file
@@ -0,0 +1,404 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using ChartAndGraph.DataSource;
|
||||
using ChartAndGraph.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[Serializable]
|
||||
public class PieData : AbstractChartData, IInternalPieData , IChartData
|
||||
{
|
||||
[Serializable]
|
||||
internal class CategoryData
|
||||
{
|
||||
public string Name;
|
||||
public ChartDynamicMaterial Materials;
|
||||
[Range(0f, 1f)]
|
||||
public float RadiusScale =1f;
|
||||
[Range(0f, 1f)]
|
||||
public float DepthScale = 1f;
|
||||
[Range(0f, 1f)]
|
||||
public float DepthOffset = 0f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
class DataEntry
|
||||
{
|
||||
public string GroupName;
|
||||
public string ColumnName;
|
||||
public double Amount;
|
||||
}
|
||||
|
||||
public PieData()
|
||||
{
|
||||
mDataSource = new ChartSparseDataSource();
|
||||
mDataSource.Rows.Add(new DataSource.ChartDataRow("Pie"));
|
||||
}
|
||||
|
||||
private ChartSparseDataSource mDataSource;
|
||||
ChartSparseDataSource IInternalPieData.InternalDataSource { get { return mDataSource; } }
|
||||
[SerializeField]
|
||||
private CategoryData[] mCategories = new CategoryData[0];
|
||||
[SerializeField]
|
||||
private string[] mGroups = new string[1] { "Pie" };
|
||||
[SerializeField]
|
||||
private DataEntry[] mData = new DataEntry[0];
|
||||
|
||||
public int TotalCategories { get { return mDataSource.Columns.Count; } }
|
||||
|
||||
public void Update()
|
||||
{
|
||||
UpdateSliders();
|
||||
}
|
||||
|
||||
public string GetCategoryName(int index)
|
||||
{
|
||||
return mDataSource.Columns[index].Name;
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
int totalColumns = mDataSource.Columns.Count;
|
||||
mCategories = new CategoryData[totalColumns];
|
||||
for (int i = 0; i < totalColumns; i++)
|
||||
{
|
||||
CategoryData data = new CategoryData();
|
||||
data.Name = mDataSource.Columns[i].Name;
|
||||
data.Materials = mDataSource.Columns[i].Material;
|
||||
object userData = mDataSource.Columns[i].UserData;
|
||||
if (userData != null && userData is CategoryData)
|
||||
{
|
||||
data.RadiusScale = ((CategoryData)userData).RadiusScale;
|
||||
data.DepthScale = ((CategoryData)userData).DepthScale;
|
||||
data.DepthOffset = ((CategoryData)userData).DepthOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.RadiusScale = 1f;
|
||||
data.DepthScale = 1f;
|
||||
data.DepthOffset = 1f;
|
||||
}
|
||||
mCategories[i] = data;
|
||||
}
|
||||
|
||||
int totalRows = mDataSource.Rows.Count;
|
||||
mGroups = new string[totalRows];
|
||||
for (int i = 0; i < totalRows; i++)
|
||||
mGroups[i] = mDataSource.Rows[i].Name;
|
||||
|
||||
double[,] raw = mDataSource.getRawData();
|
||||
int current = 0;
|
||||
mData = new DataEntry[raw.GetLength(0) * raw.GetLength(1)];
|
||||
for (int i = 0; i < raw.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < raw.GetLength(1); ++j)
|
||||
{
|
||||
DataEntry entry = new DataEntry();
|
||||
entry.ColumnName = mDataSource.Columns[j].Name;
|
||||
entry.GroupName = mDataSource.Rows[i].Name;
|
||||
entry.Amount = raw[i, j];
|
||||
mData[current++] = entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event Action ProperyUpdated;
|
||||
|
||||
protected void RaisePropertyUpdated()
|
||||
{
|
||||
if (ProperyUpdated != null)
|
||||
ProperyUpdated();
|
||||
}
|
||||
public bool HasCategory(string category)
|
||||
{
|
||||
try
|
||||
{
|
||||
var col = mDataSource.Columns[category];
|
||||
if (col != null)
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// rename a category. throws an exception on error
|
||||
/// </summary>
|
||||
/// <param name="prevName"></param>
|
||||
/// <param name="newName"></param>
|
||||
public void RenameCategory(string prevName, string newName)
|
||||
{
|
||||
mDataSource.Columns[prevName].Name = newName;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
|
||||
public object StoreCategory(string category)
|
||||
{
|
||||
CategoryData data = (CategoryData)(mDataSource.Columns[category].UserData);
|
||||
data.Materials = mDataSource.Columns[category].Material;
|
||||
return data;
|
||||
}
|
||||
|
||||
public void RestoreCategory(string category, object data)
|
||||
{
|
||||
var toSet = (CategoryData)data;
|
||||
CategoryData current = (CategoryData)(mDataSource.Columns[category].UserData);
|
||||
current.DepthOffset = toSet.DepthOffset;
|
||||
current.Materials = toSet.Materials;
|
||||
current.RadiusScale = toSet.RadiusScale;
|
||||
current.DepthScale = toSet.DepthScale;
|
||||
mDataSource.Columns[category].Material = toSet.Materials;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
|
||||
public void SetCateogryParams(string category, float radiusScale, float depthScale, float depthOffset)
|
||||
{
|
||||
var col = mDataSource.Columns[category];
|
||||
CategoryData data = col.UserData as CategoryData;
|
||||
data.RadiusScale = radiusScale;
|
||||
data.DepthScale = depthScale;
|
||||
data.DepthOffset = depthOffset;
|
||||
}
|
||||
/// <summary>
|
||||
/// call this to suspend chart redrawing while updating the data of the chart
|
||||
/// </summary>
|
||||
public void StartBatch()
|
||||
{
|
||||
mDataSource.SuspendEvents = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// call this after StartBatch , this will apply all the changed made between the StartBatch call to this call
|
||||
/// </summary>
|
||||
public void EndBatch()
|
||||
{
|
||||
mDataSource.SuspendEvents = false;
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
mDataSource = new ChartSparseDataSource();
|
||||
mDataSource.SuspendEvents = true;
|
||||
mDataSource.Clear();
|
||||
if (mCategories == null)
|
||||
mCategories = new CategoryData[0];
|
||||
if (mGroups == null)
|
||||
mGroups = new string[0];
|
||||
if (mData == null)
|
||||
mData = new DataEntry[0];
|
||||
|
||||
for (int i = 0; i < mCategories.Length; i++)
|
||||
AddCategory(mCategories[i].Name, mCategories[i].Materials, mCategories[i].RadiusScale, mCategories[i].DepthScale,mCategories[i].DepthOffset);
|
||||
// for (int i = 0; i < mGroups.Length; i++)
|
||||
// AddGroup(mGroups[i]);
|
||||
mDataSource.Rows.Add(new DataSource.ChartDataRow("Pie"));
|
||||
for (int i = 0; i < mData.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataEntry entry = mData[i];
|
||||
mDataSource.SetValue(entry.ColumnName, entry.GroupName, entry.Amount);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mDataSource.SuspendEvents = false;
|
||||
}
|
||||
|
||||
private void AddGroup(string name)
|
||||
{
|
||||
mDataSource.Rows.Add(new ChartDataRow(name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new category to the pie chart. Each category has it's own material and name. each category corresponds to one pie slice
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the category</param>
|
||||
/// <param name="material">the material of the category</param>
|
||||
public void AddCategory(string name, Material material)
|
||||
{
|
||||
AddCategory(name, new ChartDynamicMaterial(material), 1f,1f,0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// clears the pie chart data
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
string[] groups = mDataSource.Columns.Select(x => x.Name).ToArray();
|
||||
foreach (string s in groups)
|
||||
{
|
||||
RemoveCategory(s);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a new category to the pie chart. Each category has it's own material and name. each category corresponds to one pie slice
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the category</param>
|
||||
/// <param name="material">the dynamic material of the category. dynamic materials allows setting the material for different events</param>
|
||||
public void AddCategory(string name, ChartDynamicMaterial material, float radiusScale,float depthScale,float depthOffset)
|
||||
{
|
||||
radiusScale = Mathf.Clamp(radiusScale, 0f, 1f);
|
||||
ChartDataColumn column = new ChartDataColumn(name);
|
||||
column.Material = material;
|
||||
CategoryData d = new CategoryData();
|
||||
d.RadiusScale = radiusScale;
|
||||
d.DepthScale = depthScale;
|
||||
d.DepthOffset = depthOffset;
|
||||
column.UserData = d;
|
||||
mDataSource.mColumns.Add(column);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets the material for the specified category
|
||||
/// </summary>
|
||||
/// <param name="category">the name of the category</param>
|
||||
/// <param name="material">the material of the category</param>
|
||||
public void SetMaterial(string category, Material material)
|
||||
{
|
||||
SetMaterial(category, new ChartDynamicMaterial(material));
|
||||
|
||||
}
|
||||
|
||||
internal ChartDynamicMaterial GetMaterial(string category)
|
||||
{
|
||||
return mDataSource.Columns[category].Material;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets the material for the specified category
|
||||
/// </summary>
|
||||
/// <param name="category">the name of the category</param>
|
||||
/// <param name="material">the dynamic material of the category. dynamic materials allow setting the material for different events</param>
|
||||
public void SetMaterial(string category, ChartDynamicMaterial material)
|
||||
{
|
||||
mDataSource.Columns[category].Material = material;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// removes a category from the pie chart
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the category to remove</param>
|
||||
public void RemoveCategory(string name)
|
||||
{
|
||||
ChartDataColumn column = mDataSource.Columns[name];
|
||||
RemoveSlider(name, "Pie");
|
||||
mDataSource.Columns.Remove(column);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the value for the specified category
|
||||
/// </summary>
|
||||
/// <param name="category">the category name</param>
|
||||
/// <param name="group">the group name</param>
|
||||
/// <returns></returns>
|
||||
public double GetValue(string category)
|
||||
{
|
||||
return mDataSource.GetValue(category, "Pie");
|
||||
}
|
||||
|
||||
public bool CheckAnimationEnded(float time, AnimationCurve curve)
|
||||
{
|
||||
if (curve.length == 0)
|
||||
return true;
|
||||
return time > curve.keys[curve.length - 1].time;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// used intenally , do not call
|
||||
/// </summary>
|
||||
/// <param name="cats"></param>
|
||||
public object[] StoreAllCategoriesinOrder()
|
||||
{
|
||||
return mCategories.ToArray();
|
||||
}
|
||||
|
||||
private void FixEaseFunction(AnimationCurve curve)
|
||||
{
|
||||
curve.postWrapMode = WrapMode.Once;
|
||||
curve.preWrapMode = WrapMode.Once;
|
||||
}
|
||||
|
||||
public void SlideValue(string category, double slideTo, float timeScale, AnimationCurve curve)
|
||||
{
|
||||
try
|
||||
{
|
||||
RemoveSlider(category, "Pie");
|
||||
string group = "Pie";
|
||||
curve.postWrapMode = WrapMode.Once;
|
||||
curve.preWrapMode = WrapMode.Once;
|
||||
float time = 0f;
|
||||
if (curve.length > 0)
|
||||
time = curve.keys[curve.length - 1].time;
|
||||
Slider s = new Slider();
|
||||
s.category = category;
|
||||
s.group = group;
|
||||
s.from = GetValue(category);
|
||||
s.to = slideTo;
|
||||
s.startTime = Time.time;
|
||||
s.timeScale = timeScale;
|
||||
s.totalTime = time;
|
||||
s.curve = curve;
|
||||
mSliders.Add(s);
|
||||
}
|
||||
catch (ChartException e)
|
||||
{
|
||||
Debug.LogWarning(e.Message);
|
||||
}
|
||||
}
|
||||
public void SlideValue(string category, double slideTo, float time)
|
||||
{
|
||||
try
|
||||
{
|
||||
RemoveSlider(category, "Pie");
|
||||
string group = "Pie";
|
||||
Slider s = new Slider();
|
||||
s.category = category;
|
||||
s.group = group;
|
||||
s.from = GetValue(category);
|
||||
s.to = slideTo;
|
||||
s.startTime = Time.time;
|
||||
s.totalTime = time;
|
||||
mSliders.Add(s);
|
||||
}
|
||||
catch (ChartException e)
|
||||
{
|
||||
Debug.LogWarning(e.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// sets the value for the specified category
|
||||
/// </summary>
|
||||
/// <param name="category">the category name</param>
|
||||
/// <param name="amount">the value of the pie item</param>
|
||||
public void SetValue(string category, double amount)
|
||||
{
|
||||
RemoveSlider(category, "Pie");
|
||||
SetValueInternal(category, "Pie", amount);
|
||||
}
|
||||
|
||||
protected override void SetValueInternal(string column, string row, double value)
|
||||
{
|
||||
try
|
||||
{
|
||||
mDataSource.SetValue(column, "Pie", value);
|
||||
}
|
||||
catch(ChartException e)
|
||||
{
|
||||
Debug.LogWarning(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/PieChart/PieData.cs.meta
Normal file
12
Assets/Chart And Graph/Script/PieChart/PieData.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d94eb6bb667d1d74fbe6497945925540
|
||||
timeCreated: 1480003631
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Chart And Graph/Script/PieChart/PieInfo.cs
Normal file
16
Assets/Chart And Graph/Script/PieChart/PieInfo.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public class PieInfo : MonoBehaviour
|
||||
{
|
||||
public PieChart.PieObject pieObject { get; set; }
|
||||
public string Category { get { return pieObject.category; } }
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/PieChart/PieInfo.cs.meta
Normal file
12
Assets/Chart And Graph/Script/PieChart/PieInfo.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0eeebc076c6f1b24e862592ab006641e
|
||||
timeCreated: 1576867263
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
79
Assets/Chart And Graph/Script/PieChart/PieMesh2D.cs
Normal file
79
Assets/Chart And Graph/Script/PieChart/PieMesh2D.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// pie mesh creation class
|
||||
/// </summary>
|
||||
partial class PieMesh
|
||||
{
|
||||
|
||||
public static void Generate2dPath(List<Vector2> path, List<int> tringles,float startAngle, float angleSpan, float radius, float innerRadius, int segments)
|
||||
{
|
||||
float segmentAngle = angleSpan / segments;
|
||||
float currentAngle = startAngle;
|
||||
|
||||
path.Clear();
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
path.Add(Vector2.zero);
|
||||
path.Add(Vector2.zero);
|
||||
}
|
||||
|
||||
for (int i =0; i <= segments; i++)
|
||||
{
|
||||
currentAngle += segmentAngle;
|
||||
float cos = Mathf.Cos(currentAngle);
|
||||
float sin = Mathf.Sin(currentAngle);
|
||||
|
||||
Vector3 innerVertex = new Vector3(cos * innerRadius, sin * innerRadius, 0f);
|
||||
Vector3 outerVertex = new Vector3(cos * radius, sin * radius, 0f);
|
||||
path[i] = innerVertex;
|
||||
path[path.Count - 1 - i] = outerVertex;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= segments; i++)
|
||||
{
|
||||
tringles.Add(i-1);
|
||||
tringles.Add(i);
|
||||
tringles.Add(path.Count - i);
|
||||
|
||||
tringles.Add(i);
|
||||
tringles.Add(path.Count - i);
|
||||
tringles.Add(path.Count - 1 - i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void Generate2dMesh(IChartMesh mesh, float startAngle,float angleSpan,float radius,float innerRadius,int segments)
|
||||
{
|
||||
float segmentAngle = angleSpan / segments;
|
||||
float currentAngle = startAngle;
|
||||
float segmenUv = 1f / segments;
|
||||
float currentUv = 0f;
|
||||
float cos = Mathf.Cos(currentAngle);
|
||||
float sin = Mathf.Sin(currentAngle);
|
||||
|
||||
UIVertex prevInnerVertex = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, 0f), new Vector2(currentUv, 0f));
|
||||
UIVertex prevOuterVertex = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, 0f), new Vector2(currentUv, 1f));
|
||||
for (int i=1; i<segments+1; i++)
|
||||
{
|
||||
currentUv += segmenUv;
|
||||
currentAngle += segmentAngle;
|
||||
cos = Mathf.Cos(currentAngle);
|
||||
sin = Mathf.Sin(currentAngle);
|
||||
|
||||
UIVertex innerVertex = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, 0f), new Vector2(currentUv, 0f));
|
||||
UIVertex outerVertex = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, 0f), new Vector2(currentUv, 1f));
|
||||
mesh.AddQuad(prevInnerVertex, innerVertex, prevOuterVertex, outerVertex);
|
||||
prevInnerVertex = innerVertex;
|
||||
prevOuterVertex = outerVertex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/PieChart/PieMesh2D.cs.meta
Normal file
12
Assets/Chart And Graph/Script/PieChart/PieMesh2D.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc8f0d84715f171489fa9bc8641220d7
|
||||
timeCreated: 1479729610
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
Assets/Chart And Graph/Script/PieChart/PieMesh3D.cs
Normal file
128
Assets/Chart And Graph/Script/PieChart/PieMesh3D.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// pie mesh creation class
|
||||
/// </summary>
|
||||
partial class PieMesh
|
||||
{
|
||||
public static void Generate3dMesh(WorldSpaceChartMesh mesh, float startAngle, float angleSpan, float radius, float innerRadius, int segments,float outerDepth,float innerDepth)
|
||||
{
|
||||
float maxDepth = Mathf.Max(outerDepth, innerDepth);
|
||||
float bottom = maxDepth * 0.5f;
|
||||
float innerUp = bottom - innerDepth;
|
||||
float outerUp = bottom - outerDepth;
|
||||
//float halfDepth = maxDepth * 0.5f;
|
||||
float segmentAngle = angleSpan / segments;
|
||||
float currentAngle = startAngle;
|
||||
float segmenUv = 1f / segments;
|
||||
float currentUv = 0f;
|
||||
float cos = Mathf.Cos(currentAngle);
|
||||
float sin = Mathf.Sin(currentAngle);
|
||||
|
||||
UIVertex innerV = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, innerUp), new Vector2(currentUv, 0f));
|
||||
UIVertex outerV = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, outerUp), new Vector2(currentUv, 1f));
|
||||
|
||||
int currentInner = mesh.AddVertex(innerV);
|
||||
int currentOuter = mesh.AddVertex(outerV);
|
||||
int prevInnerVertex = mesh.AddVertex(innerV);
|
||||
int prevOuterVertex = mesh.AddVertex(outerV);
|
||||
int prevOpeningVertex = mesh.AddVertex(innerV);
|
||||
int prevClosingVertex = mesh.AddVertex(outerV);
|
||||
innerV.position.z = bottom;
|
||||
outerV.position.z = bottom;
|
||||
|
||||
int currentInnerDeep = mesh.AddVertex(innerV);
|
||||
int currentOuterDeep = mesh.AddVertex(outerV);
|
||||
int prevInnerVertexDeep = mesh.AddVertex(innerV);
|
||||
int prevOuterVertexDeep = mesh.AddVertex(outerV);
|
||||
|
||||
mesh.AddTringle(currentInner, currentOuter,currentOuterDeep);
|
||||
mesh.AddTringle(currentOuterDeep, currentInnerDeep, currentInner);
|
||||
|
||||
int prevOpeningVertexDeep = mesh.AddVertex(innerV);
|
||||
int prevClosingVertexDeep = mesh.AddVertex(outerV);
|
||||
|
||||
for (int i = 1; i <= segments; i++)
|
||||
{
|
||||
currentUv += segmenUv;
|
||||
currentAngle += segmentAngle;
|
||||
cos = Mathf.Cos(currentAngle);
|
||||
sin = Mathf.Sin(currentAngle);
|
||||
|
||||
UIVertex innerVertex = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, innerUp), new Vector2(currentUv, 0f));
|
||||
UIVertex outerVertex = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, outerUp), new Vector2(currentUv, 1f));
|
||||
|
||||
int leftBottom = -1;
|
||||
int rightBottomAdded = -1;
|
||||
if (innerRadius > 0f)
|
||||
{
|
||||
rightBottomAdded = mesh.AddVertex(innerVertex);
|
||||
leftBottom = prevInnerVertex;
|
||||
}
|
||||
|
||||
int leftTop = prevOuterVertex;
|
||||
int rightTop = mesh.AddVertex(outerVertex);
|
||||
int rightBottom = mesh.AddVertex(innerVertex);
|
||||
int rightTopAdded = mesh.AddVertex(outerVertex);
|
||||
|
||||
innerVertex.position.z = bottom;
|
||||
outerVertex.position.z = bottom;
|
||||
|
||||
int leftBottomDeep = -1;
|
||||
if (innerRadius > 0f)
|
||||
leftBottomDeep = prevInnerVertexDeep;
|
||||
|
||||
int leftTopDeep = prevOuterVertexDeep;
|
||||
int rightTopDeep = mesh.AddVertex(outerVertex);
|
||||
int rightBottomDeep = mesh.AddVertex(innerVertex);
|
||||
int rightTopAddedDeep = mesh.AddVertex(outerVertex);
|
||||
|
||||
mesh.AddTringle(rightBottom, rightTop, leftTop);
|
||||
mesh.AddTringle(leftTopDeep, rightTopDeep, rightBottomDeep);
|
||||
|
||||
mesh.AddTringle(prevClosingVertexDeep, prevClosingVertex, rightTopAdded);
|
||||
mesh.AddTringle(rightTopAdded, rightTopAddedDeep, prevClosingVertexDeep);
|
||||
|
||||
prevClosingVertex = rightTopAdded;
|
||||
prevClosingVertexDeep = rightTopAddedDeep;
|
||||
|
||||
if (innerRadius > 0f)
|
||||
{
|
||||
int rightBottomAddedDeep = mesh.AddVertex(innerVertex);
|
||||
mesh.AddTringle(leftTop, leftBottom, rightBottom);
|
||||
mesh.AddTringle(rightBottomDeep, leftBottomDeep, leftTopDeep);
|
||||
|
||||
mesh.AddTringle(rightBottomAdded, prevOpeningVertex, prevOpeningVertexDeep);
|
||||
mesh.AddTringle(prevOpeningVertexDeep, rightBottomAddedDeep, rightBottomAdded);
|
||||
prevOpeningVertexDeep = rightBottomAddedDeep;
|
||||
prevOpeningVertex = rightBottomAdded;
|
||||
}
|
||||
prevInnerVertex = rightBottom;
|
||||
prevOuterVertex = rightTop;
|
||||
prevInnerVertexDeep = rightBottomDeep;
|
||||
prevOuterVertexDeep = rightTopDeep;
|
||||
|
||||
if(i==segments)
|
||||
{
|
||||
rightTopDeep = mesh.AddVertex(outerVertex);
|
||||
rightBottomDeep = mesh.AddVertex(innerVertex);
|
||||
innerVertex.position.z = innerUp;
|
||||
outerVertex.position.z = outerUp;
|
||||
rightTop = mesh.AddVertex(outerVertex);
|
||||
rightBottom = mesh.AddVertex(innerVertex);
|
||||
mesh.AddTringle(rightTopDeep, rightTop, rightBottom);
|
||||
mesh.AddTringle(rightBottom, rightBottomDeep, rightTopDeep);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/PieChart/PieMesh3D.cs.meta
Normal file
12
Assets/Chart And Graph/Script/PieChart/PieMesh3D.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b110db5bdcf93b94ba83d8f973df49f9
|
||||
timeCreated: 1560535843
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
194
Assets/Chart And Graph/Script/PieChart/WorldSpacePieChart.cs
Normal file
194
Assets/Chart And Graph/Script/PieChart/WorldSpacePieChart.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[Serializable]
|
||||
public class WorldSpacePieChart : PieChart
|
||||
{
|
||||
/// <summary>
|
||||
/// If this value is set all the text in the chart will be rendered to this specific camera. otherwise text is rendered to the main camera
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("If this value is set all the text in the chart will be rendered to this specific camera. otherwise text is rendered to the main camera")]
|
||||
private Camera textCamera;
|
||||
|
||||
/// <summary>
|
||||
/// If this value is set all the text in the chart will be rendered to this specific camera. otherwise text is rendered to the main camera
|
||||
/// </summary>
|
||||
public Camera TextCamera
|
||||
{
|
||||
get { return textCamera; }
|
||||
set
|
||||
{
|
||||
textCamera = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The distance from the camera at which the text is at it's original size.
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("The distance from the camera at which the text is at it's original size")]
|
||||
private float textIdleDistance = 20f;
|
||||
|
||||
/// <summary>
|
||||
/// The distance from the camera at which the text is at it's original size.
|
||||
/// </summary>
|
||||
public float TextIdleDistance
|
||||
{
|
||||
get { return textIdleDistance; }
|
||||
set
|
||||
{
|
||||
textIdleDistance = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
protected override Camera TextCameraLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return textCamera;
|
||||
}
|
||||
}
|
||||
public override bool IsCanvas
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected override float TextIdleDistanceLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return textIdleDistance;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("inner depth size of the pie slices")]
|
||||
private float innerDepth = 0f;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("depth")]
|
||||
[Tooltip("outer depth size of the pie slices")]
|
||||
private float outerDepth;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("pie prefab of the pie slices")]
|
||||
private GameObject prefab;
|
||||
|
||||
public WorldSpacePieChart()
|
||||
{
|
||||
radius = 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pie prefab of the pie slices
|
||||
/// </summary>
|
||||
public GameObject Prefab
|
||||
{
|
||||
get { return prefab; }
|
||||
set
|
||||
{
|
||||
prefab = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// depth size of the pie slices
|
||||
/// </summary>
|
||||
|
||||
public float OuterDepth
|
||||
{
|
||||
get { return outerDepth; }
|
||||
set
|
||||
{
|
||||
outerDepth = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public float InnerDepth
|
||||
{
|
||||
get { return outerDepth; }
|
||||
set
|
||||
{
|
||||
outerDepth = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
protected override float InnerDepthLink
|
||||
{
|
||||
get
|
||||
{
|
||||
if(innerDepth <= 0f)
|
||||
{
|
||||
return outerDepth;
|
||||
}
|
||||
return innerDepth;
|
||||
}
|
||||
}
|
||||
protected override float OuterDepthLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return outerDepth;
|
||||
}
|
||||
}
|
||||
|
||||
protected override IPieGenerator PreparePieObject(out GameObject pieObject)
|
||||
{
|
||||
if (Prefab == null)
|
||||
pieObject = new GameObject();
|
||||
else
|
||||
pieObject = GameObject.Instantiate(Prefab);
|
||||
ChartCommon.HideObject(pieObject, hideHierarchy);
|
||||
ChartCommon.EnsureComponent<MeshFilter>(pieObject);
|
||||
ChartCommon.EnsureComponent<MeshRenderer>(pieObject);
|
||||
IPieGenerator gen = pieObject.GetComponent<IPieGenerator>();
|
||||
if (gen != null)
|
||||
return gen;
|
||||
return ChartCommon.EnsureComponent<WorldSpacePieGenerator>(pieObject);
|
||||
}
|
||||
|
||||
protected override void ValidateProperties()
|
||||
{
|
||||
base.ValidateProperties();
|
||||
if (outerDepth < 0f)
|
||||
outerDepth = 0f;
|
||||
if (innerDepth < 0f)
|
||||
innerDepth = 0f;
|
||||
}
|
||||
protected override Material LineMaterialLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
protected override float LineThicknessLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
protected override float LineSpacingLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 604c11209e1fa2f48bda9776a02fec86
|
||||
timeCreated: 1480089492
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// pie generator for world space charts.
|
||||
/// </summary>
|
||||
class WorldSpacePieGenerator : MonoBehaviour,IPieGenerator
|
||||
{
|
||||
MeshRenderer mRenderer;
|
||||
MeshFilter mFilter;
|
||||
Mesh mCleanMesh;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
}
|
||||
|
||||
public void Generate(float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerDepth,float innerDepth)
|
||||
{
|
||||
WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1);
|
||||
float maxDepth = Mathf.Max(outerDepth, innerDepth);
|
||||
if (maxDepth <= 0f)
|
||||
PieMesh.Generate2dMesh(mesh, startAngle, angleSpan, radius, innerRadius, segments);
|
||||
else
|
||||
PieMesh.Generate3dMesh(mesh, startAngle, angleSpan, radius, innerRadius, segments, outerDepth,innerDepth);
|
||||
|
||||
if (mCleanMesh != null)
|
||||
{
|
||||
mCleanMesh.Clear();
|
||||
mesh.ApplyToMesh(mCleanMesh);
|
||||
MeshCollider collider = ChartCommon.EnsureComponent<MeshCollider>(gameObject);
|
||||
if (collider != null)
|
||||
{
|
||||
collider.sharedMesh = null;
|
||||
collider.sharedMesh = mCleanMesh;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Mesh newMesh = mesh.Generate();
|
||||
newMesh.hideFlags = HideFlags.DontSave;
|
||||
if (mFilter == null)
|
||||
mFilter = GetComponent<MeshFilter>();
|
||||
mFilter.sharedMesh = newMesh;
|
||||
MeshCollider collider = ChartCommon.EnsureComponent<MeshCollider>(gameObject);
|
||||
if (collider != null)
|
||||
collider.sharedMesh = newMesh;
|
||||
ChartCommon.CleanMesh(newMesh, ref mCleanMesh);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
ChartCommon.CleanMesh(null, ref mCleanMesh);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be75b1e1d08a4fa488bdd22f165cb7a0
|
||||
timeCreated: 1560548197
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user