重命名为xcharts

This commit is contained in:
monitor1394
2018-09-15 06:52:42 +08:00
parent 8400285bd9
commit 1bbdc5065b
17 changed files with 1897 additions and 627 deletions

8
.gitignore vendored
View File

@@ -6,10 +6,10 @@
/UnityPackageManager
/Assets/XLua/Examples
XChart.sln
XChart.csproj
XChart.Editor.csproj
XChart.Plugins.csproj
XCharts.sln
XCharts.csproj
XCharts.Editor.csproj
XCharts.Plugins.csproj
*.vcxproj.filters
*.vcxproj.user

View File

@@ -1,10 +0,0 @@
fileFormatVersion: 2
guid: b2b66dc5a6f882140a070f91bf7cc1c0
folderAsset: yes
timeCreated: 1536101731
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,552 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &447875476
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 447875478}
- component: {fileID: 447875477}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &447875477
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 447875476}
m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &447875478
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 447875476}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &451647821
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 451647825}
- component: {fileID: 451647824}
- component: {fileID: 451647823}
- component: {fileID: 451647822}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &451647822
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 451647821}
m_Enabled: 1
--- !u!124 &451647823
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 451647821}
m_Enabled: 1
--- !u!20 &451647824
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 451647821}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &451647825
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 451647821}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &505350089
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 505350093}
- component: {fileID: 505350092}
- component: {fileID: 505350091}
- component: {fileID: 505350090}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &505350090
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 505350089}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1301386320, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &505350091
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 505350089}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 1
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &505350092
Canvas:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 505350089}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &505350093
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 505350089}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 325.5, y: 197.5, z: 0}
m_LocalScale: {x: 0.81375, y: 0.81375, z: 0.81375}
m_Children:
- {fileID: 2051892027}
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &662856233
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 662856236}
- component: {fileID: 662856235}
- component: {fileID: 662856234}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &662856234
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 662856233}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1077351063, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &662856235
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 662856233}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -619905303, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 5
--- !u!4 &662856236
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 662856233}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1297066859
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1297066860}
- component: {fileID: 1297066862}
- component: {fileID: 1297066861}
m_Layer: 5
m_Name: line_chart
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1297066860
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1297066859}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -277, y: -82.47, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2051892027}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 61.2, y: 0}
m_SizeDelta: {x: 552, y: 100}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1297066861
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1297066859}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b4f38bd00b4648c448cabfc167538f7c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
pointWidth: 15
lineSize: 1
pointSize: 1.5
graduationCount: 4
graduationStep: 10
graduationWidth: 50
backgroundColor: {r: 0, g: 0, b: 0, a: 0.559}
font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
lineList:
- name: FPS
key: fps
lineColor: {r: 0.334077, g: 0.2794118, b: 1, a: 1}
pointColor: {r: 1, g: 1, b: 1, a: 1}
button: {fileID: 0}
- name: RTT
key: rtt
lineColor: {r: 0, g: 0.77205884, b: 0.1650608, a: 1}
pointColor: {r: 1, g: 1, b: 1, a: 1}
button: {fileID: 0}
- name: PING
key: ping
lineColor: {r: 0.89705884, g: 0.04617214, b: 0.8735863, a: 1}
pointColor: {r: 1, g: 1, b: 1, a: 1}
button: {fileID: 0}
--- !u!222 &1297066862
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1297066859}
--- !u!1 &2051892026
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 2051892027}
- component: {fileID: 2051892029}
- component: {fileID: 2051892028}
m_Layer: 5
m_Name: xchart
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2051892027
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2051892026}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1297066860}
m_Father: {fileID: 505350093}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 676.4, y: 164.94}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2051892028
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2051892026}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e6bd57e81d68cac47a78ccb7a452c8d7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!222 &2051892029
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2051892026}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 12689d1e537d28f42ac45e2d2d369377
guid: 3e77b3cfd5a4d2646964841d2b14dcb2
folderAsset: yes
timeCreated: 1536101212
licenseType: Free

View File

@@ -1,7 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using xchart;
using UnityEngine;
using xcharts;
public class Demo : MonoBehaviour
{

View File

@@ -0,0 +1,101 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace xcharts
{
[System.Serializable]
public class BarGroup
{
[SerializeField]
public string name;
[SerializeField]
public Color color;
}
[System.Serializable]
public class BarData
{
[SerializeField]
public string group;
[SerializeField]
public string key;
[SerializeField]
public float value;
}
public class BarChart : MaskableGraphic
{
[SerializeField]
private float keyRectWidth = 50;
[SerializeField]
private float valueRectWidth = 50;
[SerializeField]
private float barWidth = 50;
[SerializeField]
private float barSpace = 20;
[SerializeField]
private Color backgroundColor = Color.black;
[SerializeField]
private List<BarGroup> groupList = new List<BarGroup>();
[SerializeField]
private List<BarData> dataList = new List<BarData>();
private float dataTotal = 0;
private List<Text> keyTextList = new List<Text>();
private List<Text> valueTextList = new List<Text>();
private float chartWid { get { return rectTransform.sizeDelta.x; } }
private float chartHig { get { return rectTransform.sizeDelta.y; } }
void Awake()
{
dataTotal = getDataTotal();
}
void Update()
{
}
private float getDataTotal()
{
float total = 0;
foreach (var data in dataList)
{
total += data.value;
}
return total;
}
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
// draw bg
Vector3 p1 = new Vector3(-keyRectWidth, 0);
Vector3 p2 = new Vector3(chartWid, 0);
Vector3 p3 = new Vector3(chartWid, -chartHig);
Vector3 p4 = new Vector3(-keyRectWidth, -chartHig);
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, backgroundColor);
//draw data bar
dataTotal = getDataTotal();
for(int i=0;i<dataList.Count;i++)
{
BarData data = dataList[i];
float barLen = data.value / dataTotal * (chartWid - valueRectWidth);
float posY = i * (barWidth + barSpace);
p1 = new Vector3(0,-posY);
p2 = new Vector3(barLen, -posY);
p3 = new Vector3(barLen, -(posY + barWidth));
p4 = new Vector3(0, -(posY + barWidth));
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, Color.grey);
}
ChartUtils.DrawLine(vh, new Vector3(0, 0), new Vector3(0, -chartHig), 1.5f, Color.white);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 535d2697503c2a94a887354e22a5414d
timeCreated: 1536795169
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,7 +2,7 @@
using UnityEngine;
using UnityEngine.UI;
namespace xchart
namespace xcharts
{
public static class ChartUtils
{
@@ -89,16 +89,16 @@ namespace xchart
vh.AddUIVertexQuad(vertex);
}
public static void DrawCube(VertexHelper vh, Vector3 p, float size, Color color)
public static void DrawPolygon(VertexHelper vh, Vector3 p, float size, Color color)
{
Vector3 p1 = new Vector3(p.x - size, p.y - size);
Vector3 p2 = new Vector3(p.x + size, p.y - size);
Vector3 p3 = new Vector3(p.x + size, p.y + size);
Vector3 p4 = new Vector3(p.x - size, p.y + size);
DrawCube(vh, p1, p2, p3, p4, color);
DrawPolygon(vh, p1, p2, p3, p4, color);
}
public static void DrawCube(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
Color color)
{
UIVertex[] vertex = new UIVertex[4];

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace xchart
namespace xcharts
{
[System.Serializable]
public class LineData
@@ -155,6 +155,9 @@ namespace xchart
private float lastChartHig = 0;
private float lastGraduationWid = 0;
private float chartWid { get { return rectTransform.sizeDelta.x; } }
private float chartHig { get { return rectTransform.sizeDelta.y; } }
protected override void Awake()
{
base.Awake();
@@ -181,9 +184,7 @@ namespace xchart
private void InitGraduation()
{
float chartHigh = rectTransform.sizeDelta.y;
float graduationHig = chartHigh / graduationCount;
float graduationHig = chartHig / graduationCount;
for (int i = 0; i < MAX_GRADUATION; i++)
{
if (i >= graduationCount + 1)
@@ -207,13 +208,12 @@ namespace xchart
private void InitLineButton()
{
float chartHigh = rectTransform.sizeDelta.y;
for (int i = 0; i < lineList.Count; i++)
{
if (lineList[i].button) continue;
Button btn = ChartUtils.AddButtonObject("button" + i, transform, font, Vector2.zero,
Vector2.zero, Vector2.zero, new Vector2(50, 20));
btn.transform.localPosition = new Vector3(i * 50, chartHigh + 30, 0);
btn.transform.localPosition = new Vector3(i * 50, chartHig + 30, 0);
lineList[i].button = btn;
}
}
@@ -221,10 +221,9 @@ namespace xchart
private void InitHideAndShowButton()
{
if (lineList.Count <= 0) return;
float chartHigh = rectTransform.sizeDelta.y;
btnAll = ChartUtils.AddButtonObject("buttonall", transform, font, Vector2.zero,
Vector2.zero, Vector2.zero, new Vector2(graduationWidth, 20));
btnAll.transform.localPosition = new Vector3(-graduationWidth, chartHigh + 30, 0);
btnAll.transform.localPosition = new Vector3(-graduationWidth, chartHig + 30, 0);
btnAll.GetComponentInChildren<Text>().text = isShowAll ? "HIDE" : "SHOW";
btnAll.GetComponent<Image>().color = backgroundColor;
btnAll.onClick.AddListener(delegate ()
@@ -283,8 +282,7 @@ namespace xchart
public int GetMaxPointCount()
{
Vector2 size = rectTransform.sizeDelta;
int max = (int)(size.x / pointWidth);
int max = (int)(chartWid / pointWidth);
return max;
}
@@ -343,14 +341,13 @@ namespace xchart
private void UpdateMesh()
{
Vector2 size = rectTransform.sizeDelta;
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, (int)size.x - 1);
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, (int)size.x);
int tempWid = (int)chartWid;
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid - 1);
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid);
}
private void CheckLineSizeChange()
{
float chartHig = rectTransform.sizeDelta.y;
if (lastChartHig != chartHig)
{
lastChartHig = chartHig;
@@ -399,24 +396,23 @@ namespace xchart
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
float chartHigh = rectTransform.sizeDelta.y;
int chartWid = (int)(rectTransform.sizeDelta.x / pointWidth) * pointWidth;
int dataRectWid = (int)(chartWid / pointWidth) * pointWidth;
float dataMax = GetAllLineMax();
// draw bg
Vector3 p1 = new Vector3(-graduationWidth, chartHigh + 30);
Vector3 p2 = new Vector3(chartWid + 50, chartHigh + 30);
Vector3 p3 = new Vector3(chartWid + 50, -20);
Vector3 p1 = new Vector3(-graduationWidth, chartHig + 30);
Vector3 p2 = new Vector3(dataRectWid + 50, chartHig + 30);
Vector3 p3 = new Vector3(dataRectWid + 50, -20);
Vector3 p4 = new Vector3(-graduationWidth, -20);
ChartUtils.DrawCube(vh, p1, p2, p3, p4, backgroundColor);
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, backgroundColor);
// draw coordinate
Vector3 coordZero = Vector3.zero;
ChartUtils.DrawLine(vh, new Vector3(chartWid + 5, -5),
new Vector3(chartWid + 5, chartHigh + 0.5f), 1, Color.grey);
ChartUtils.DrawLine(vh, new Vector3(dataRectWid + 5, -5),
new Vector3(dataRectWid + 5, chartHig + 0.5f), 1, Color.grey);
// draw graduation
for (int i = 0; i < graduationList.Count; i++)
{
Vector3 sp = new Vector3(-5, chartHigh * i / (graduationList.Count - 1));
Vector3 ep = new Vector3(chartWid + 5, chartHigh * i / (graduationList.Count - 1));
Vector3 sp = new Vector3(-5, chartHig * i / (graduationList.Count - 1));
Vector3 ep = new Vector3(dataRectWid + 5, chartHig * i / (graduationList.Count - 1));
ChartUtils.DrawLine(vh, sp, ep, 0.5f, Color.grey);
}
@@ -430,7 +426,7 @@ namespace xchart
for (int i = 0; i < line.dataList.Count; i++)
{
float data = line.dataList[i] * chartHigh / dataMax;
float data = line.dataList[i] * chartHig / dataMax;
np = new Vector3(i * pointWidth, data);
if (i > 0)
{
@@ -443,15 +439,15 @@ namespace xchart
for (int i = 0; i < line.dataList.Count; i++)
{
UIVertex[] quadverts = new UIVertex[4];
float data = line.dataList[i] * chartHigh / dataMax;
float data = line.dataList[i] * chartHig / dataMax;
Vector3 p = new Vector3(i * pointWidth, data);
ChartUtils.DrawCube(vh, p, pointSize, line.pointColor);
ChartUtils.DrawPolygon(vh, p, pointSize, line.pointColor);
}
}
//draw x,y axis
float xLen = chartWid + 25;
float yLen = chartHigh + 15;
float xLen = dataRectWid + 25;
float yLen = chartHig + 15;
float xPos = 0;
float yPos = -5;
ChartUtils.DrawLine(vh, new Vector3(xPos, yPos - 1.5f), new Vector3(xPos, yLen), 1.5f, Color.white);

1745
Assets/XCharts/demo.unity Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 746592650003d9247ae6dec89c724e34
guid: a5b436c986812794a9b741314e4a43bd
timeCreated: 1536101749
licenseType: Free
DefaultImporter:

21
LICENSE
View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2018
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,4 +1,4 @@
# XChart
a unity line chart tool
A Simple UGUI Charting Library for Unity
![效果图](demo.png)