graph chart引入&骑行结果弹窗

This commit is contained in:
lishuo committed 2021-04-22 19:29:59 +08:00
1 parent 40d118cea3
commit 96f3644b5b
2374 files changed
+485161 -2410

No files matched your search

@@ -0,0 +1,101 @@
#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>
/// a chart mesh that is used for canvas rendering
/// </summary>
class CanvasChartMesh : ChartMeshBase
{
VertexHelper mVHWrapAround;
List<UIVertex> mListWrapAround;
UIVertex[] mTmpQuad = new UIVertex[4];
bool mTextOnly = false;
public CanvasChartMesh(bool forText)
{
mTextOnly = forText;
}
public CanvasChartMesh(VertexHelper wrapAround)
{
mVHWrapAround = wrapAround;
}
public CanvasChartMesh(List<UIVertex> wrapAround)
{
mListWrapAround = wrapAround;
}
public void WrapAround(VertexHelper wrapAround)
{
Clear();
mVHWrapAround = wrapAround;
mListWrapAround = null;
}
public void WrapAround(List<UIVertex> wrapAround)
{
Clear();
mVHWrapAround = null;
mListWrapAround = wrapAround;
}
public override BillboardText AddText(AnyChart chart, MonoBehaviour prefab, Transform parentTransform, int fontSize,float fontScale, string text, float x, float y, float z,float angle, object userData)
{
if(mTextOnly)
return base.AddText(chart, prefab, parentTransform, fontSize,fontScale, text, x, y, z,angle, userData);
return null;
}
private UIVertex FloorVertex(UIVertex vertex)
{
Vector3 newPosition = new Vector3(Mathf.Floor(vertex.position.x), Mathf.Floor(vertex.position.y), Mathf.Floor(vertex.position.z));
vertex.position = newPosition;
return vertex;
}
public override void AddQuad(UIVertex vLeftTop, UIVertex vRightTop, UIVertex vLeftBottom, UIVertex vRightBottom)
{
if (mListWrapAround != null)
{
mListWrapAround.Add(vLeftTop);
mListWrapAround.Add(vRightTop);
mListWrapAround.Add(vRightBottom);
mListWrapAround.Add(vLeftBottom);
return;
}
if (mVHWrapAround != null)
{
mTmpQuad[0] = vLeftTop;
mTmpQuad[1] = vRightTop;
mTmpQuad[2] = vRightBottom;
mTmpQuad[3] = vLeftBottom;
mVHWrapAround.AddUIVertexQuad(mTmpQuad);
}
}
public override void AddXYRect(Rect rect, int subMeshGroup, float depth)
{
Vector2[] uvs = GetUvs(rect);
UIVertex leftTop = ChartCommon.CreateVertex(new Vector3(rect.xMin, rect.yMin, depth), uvs[0]);
UIVertex rightTop = ChartCommon.CreateVertex(new Vector3(rect.xMax, rect.yMin, depth), uvs[1]);
UIVertex leftBottom = ChartCommon.CreateVertex(new Vector3(rect.xMin, rect.yMax, depth), uvs[2]);
UIVertex rightBottom = ChartCommon.CreateVertex(new Vector3(rect.xMax, rect.yMax, depth), uvs[3]);
AddQuad(leftTop, rightTop, leftBottom, rightBottom);
}
public override void AddXZRect(Rect rect, int subMeshGroup, float yPosition)
{
// this does nothing , canvas are 2d only
}
public override void AddYZRect(Rect rect, int subMeshGroup, float xPosition)
{
// this does nothing , canvas are 2d only
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b390f9a1bdb869d44a447361816a1a7c
timeCreated: 1478748562
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -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>
/// base class for all chart mesh generators
/// </summary>
abstract class ChartMeshBase : IChartMesh
{
List<BillboardText> mText = new List<BillboardText>();
List<BillboardText> mCurrentTexts = new List<BillboardText>();
Dictionary<string, BillboardText> mRecycled = new Dictionary<string, BillboardText>();
List<BillboardText> mCached = new List<BillboardText>();
float innerTile = 1f;
public ChartOrientation Orientation { get; set; }
public float Tile
{
get { return innerTile; }
set
{
innerTile = value;
}
}
public float Offset { get; set; }
public float Length { get; set; }
public bool RecycleText { get; set; }
public ChartMeshBase()
{
Orientation = ChartOrientation.Vertical;
}
public virtual List<BillboardText> CurrentTextObjects
{
get
{
return mCurrentTexts;
}
}
public virtual List<BillboardText> TextObjects
{
get
{
return mText;
}
}
Vector2[][] mUvs = new Vector2[2][]
{
new Vector2[]{ new Vector2(0f,0f),new Vector2(1f,0f),new Vector2(0f,1f), new Vector2(1f,1f)},
new Vector2[]{ new Vector2(0f,1f),new Vector2(0f,0f),new Vector2(1f,1f), new Vector2(1f,0f)}
};
Vector2[] mTmpUv = new Vector2[4];
protected Vector2[] GetUvs(Rect rect)
{
return GetUvs(rect, Orientation);
}
public virtual void Clear()
{
if (RecycleText)
{
for (int i = 0; i < mCurrentTexts.Count; i++)
{
string key = ChartCommon.GetText(mCurrentTexts[i].UIText);
mCurrentTexts[i].SetVisible(false);
mCurrentTexts[i].Recycled = true;
if (key == null || mRecycled.ContainsKey(key))
{
mCached.Add(mCurrentTexts[i]);
continue;
}
mRecycled[key] = mCurrentTexts[i];
}
}
mText.Clear();
mCurrentTexts.Clear();
}
protected Vector2[] GetUvs(Rect rect, ChartOrientation orientaion)
{
Vector2[] arr;
if (Orientation == ChartOrientation.Vertical)
arr = mUvs[0];
else
arr = mUvs[1];
if (Tile <= 0f)
{
for (int i = 0; i < 4; i++)
{
Vector2 uv = arr[i];
mTmpUv[i] = new Vector2(Offset + uv.x * Length, uv.y);
}
return mTmpUv;
}
float length = rect.width;
if (orientaion == ChartOrientation.Horizontal)
length = rect.height;
length /= Math.Abs(Length);
for (int i = 0; i < 4; i++)
{
Vector2 uv = arr[i];
mTmpUv[i] = new Vector2((Offset + uv.x * Length) * length / Tile, uv.y);
}
return mTmpUv;
}
void DestoryBillboard(BillboardText t)
{
t.Recycled = false;
GameObject uiText = t.UIText;
TextDirection d = t.Direction;
if (uiText != null && uiText.gameObject != null)
ChartCommon.SafeDestroy(uiText.gameObject);
if (d != null && d.gameObject != null)
ChartCommon.SafeDestroy(d.gameObject);
if (t != null)
ChartCommon.SafeDestroy(t.gameObject);
}
public void DestoryRecycled()
{
foreach (BillboardText t in mRecycled.Values)
{
mCached.Add(t);
// DestoryBillboard(t);
}
mRecycled.Clear();
}
public virtual BillboardText AddText(AnyChart chart, MonoBehaviour prefab, Transform parentTransform, int fontSize, float fontSharpness, string text, float x, float y, float z, float angle, object userData)
{
BillboardText recycled = null;
if (RecycleText == true)
{
if (mRecycled.TryGetValue(text, out recycled))
{
recycled.SetVisible(true);
recycled.Recycled = false;
mRecycled.Remove(text);
}
else
{
if (mCached.Count > 0)
{
recycled = mCached[mCached.Count - 1];
recycled.SetVisible(true);
recycled.Recycled = false;
mCached.RemoveAt(mCached.Count - 1);
}
else
{
recycled = null;
}
}
}
BillboardText billboardText = ChartCommon.CreateBillboardText(recycled, prefab, parentTransform, text, x, y, z, angle, null, ((IInternalUse)chart).HideHierarchy, fontSize, fontSharpness);
if (billboardText == null)
return null;
billboardText.Recycled = false;
billboardText.UserData = userData;
if (recycled == null)
mText.Add(billboardText);
mCurrentTexts.Add(billboardText);
return billboardText;
}
public abstract void AddQuad(UIVertex vLeftTop, UIVertex vRightTop, UIVertex vLeftBottom, UIVertex vRightBottom);
public abstract void AddXYRect(Rect rect, int subMeshGroup, float depth);
public abstract void AddXZRect(Rect rect, int subMeshGroup, float yPosition);
public abstract void AddYZRect(Rect rect, int subMeshGroup, float xPosition);
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7288ce2a47fcd71438b4d34748c18a6f
timeCreated: 1478748562
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,26 @@
#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>
/// base interface for chart mesh
/// </summary>
interface IChartMesh
{
List<BillboardText> TextObjects {get;}
float Tile { get; set; }
float Offset { get; set;}
float Length { get; set; }
BillboardText AddText(AnyChart chart, MonoBehaviour prefab, Transform parentTransform, int fontSize, float fontScale, string text, float x, float y, float z, float angle, object userData);
void AddYZRect(Rect rect, int subMeshGroup, float xPosition);
void AddXZRect(Rect rect, int subMeshGroup, float yPosition);
void AddXYRect(Rect rect, int subMeshGroup, float depth);
void AddQuad(UIVertex vLeftTop, UIVertex vRightTop, UIVertex vLeftBottom, UIVertex vRightBottom);
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9e1e5ff974185d541afaa05d52f5a791
timeCreated: 1478748562
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,251 @@
#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>
/// chart mesh class for world space charts
/// </summary>
internal class WorldSpaceChartMesh : ChartMeshBase
{
List<Vector3> mVertices;
List<Vector2> mUv;
List<int>[] mTringles;
bool mIsCanvas = false;
public WorldSpaceChartMesh(bool isCanvas)
:this(1)
{
ValidateMesh();
mIsCanvas = isCanvas;
}
public WorldSpaceChartMesh(int groups)
{
ValidateMesh();
mTringles = new List<int>[groups];
}
protected void ValidateMesh()
{
if (mVertices == null)
mVertices = new List<Vector3>();
if (mUv == null)
mUv = new List<Vector2>();
}
public int AddVertex(UIVertex v)
{
return AddVertex(v.position, v.uv0);
}
public override BillboardText AddText(AnyChart chart, MonoBehaviour prefab, Transform parentTransform, int fontSize,float fontScale, string text, float x, float y, float z,float angle, object userData)
{
if(mIsCanvas == false)
return base.AddText(chart, prefab, parentTransform, fontSize,fontScale, text, x, y, z,angle, userData);
return null;
}
public int AddVertex(Vector3 pos,Vector2 uv)
{
if (mVertices.Count != mUv.Count)
throw new InvalidOperationException();
int index = mVertices.Count;
mVertices.Add(pos);
mUv.Add(uv);
return index;
}
public void AddTringle(int x, int y, int z)
{
List<int> tringleList = GetTringlesForGroup(0);
AddTringle(tringleList, x, y, z);
}
protected void AddTringle(List<int> tringleList,int x,int y,int z)
{
tringleList.Add(x);
tringleList.Add(y);
tringleList.Add(z);
}
public override void Clear()
{
base.Clear();
for (int i = 0; i < mTringles.Length; i++)
{
if (mTringles[i] != null)
mTringles[i].Clear();
}
mVertices.Clear();
mUv.Clear();
}
protected List<int> GetTringlesForGroup(int subMeshGroup)
{
List<int> res;
if (mTringles[subMeshGroup] == null)
{
res = new List<int>();
mTringles[subMeshGroup] = res;
}
else
res = mTringles[subMeshGroup];
return res;
}
public override void AddYZRect(Rect rect, int subMeshGroup, float xPosition)
{
if (mIsCanvas == true)
return;
ValidateMesh();
Vector2[] uvs = GetUvs(rect,(Orientation == ChartOrientation.Vertical) ? ChartOrientation.Horizontal : ChartOrientation.Vertical);
int leftTop = AddVertex(new Vector3(xPosition,rect.xMin,rect.yMin), uvs[1]);
int rightTop = AddVertex(new Vector3(xPosition,rect.xMax,rect.yMin), uvs[3]);
int leftBottom = AddVertex(new Vector3(xPosition,rect.xMin,rect.yMax), uvs[0]);
int rightBottom = AddVertex(new Vector3(xPosition,rect.xMax,rect.yMax), uvs[2]);
List<int> tringles = GetTringlesForGroup(subMeshGroup);
AddTringle(tringles, leftTop, rightTop, rightBottom);
AddTringle(tringles, rightBottom, leftBottom, leftTop);
leftTop = AddVertex(new Vector3(xPosition, rect.xMin, rect.yMin), uvs[1]);
rightTop = AddVertex(new Vector3(xPosition, rect.xMax, rect.yMin), uvs[3]);
leftBottom = AddVertex(new Vector3(xPosition, rect.xMin, rect.yMax), uvs[0]);
rightBottom = AddVertex(new Vector3(xPosition, rect.xMax, rect.yMax), uvs[2]);
AddTringle(tringles, rightBottom, rightTop, leftTop);
AddTringle(tringles, leftTop, leftBottom, rightBottom);
}
public override void AddXZRect(Rect rect,int subMeshGroup,float yPosition)
{
if (mIsCanvas == true)
return;
ValidateMesh();
Vector2[] uvs = GetUvs(rect);
int leftTop = AddVertex(new Vector3(rect.xMin, yPosition,rect.yMin), uvs[0]);
int rightTop = AddVertex(new Vector3(rect.xMax,yPosition, rect.yMin), uvs[1]);
int leftBottom = AddVertex(new Vector3(rect.xMin,yPosition, rect.yMax), uvs[2]);
int rightBottom = AddVertex(new Vector3(rect.xMax,yPosition, rect.yMax), uvs[3]);
List<int> tringles = GetTringlesForGroup(subMeshGroup);
AddTringle(tringles, leftTop, rightTop, rightBottom);
AddTringle(tringles, rightBottom, leftBottom, leftTop);
leftTop = AddVertex(new Vector3(rect.xMin, yPosition, rect.yMin), uvs[0]);
rightTop = AddVertex(new Vector3(rect.xMax, yPosition, rect.yMin), uvs[1]);
leftBottom = AddVertex(new Vector3(rect.xMin, yPosition, rect.yMax), uvs[2]);
rightBottom = AddVertex(new Vector3(rect.xMax, yPosition, rect.yMax), uvs[3]);
AddTringle(tringles, rightBottom, rightTop, leftTop);
AddTringle(tringles, leftTop, leftBottom, rightBottom);
}
public override void AddXYRect(Rect rect,int subMeshGroup,float depth)
{
ValidateMesh();
Vector2[] uvs = GetUvs(rect);
int leftTop = AddVertex(new Vector3(rect.xMin, rect.yMin, depth), uvs[0]);
int rightTop = AddVertex(new Vector3(rect.xMax, rect.yMin, depth), uvs[1]);
int leftBottom = AddVertex(new Vector3(rect.xMin, rect.yMax, depth), uvs[2]);
int rightBottom = AddVertex(new Vector3(rect.xMax, rect.yMax, depth), uvs[3]);
List<int> tringles = GetTringlesForGroup(subMeshGroup);
AddTringle(tringles,leftTop, rightTop, rightBottom);
AddTringle(tringles, rightBottom, leftBottom, leftTop);
leftTop = AddVertex(new Vector3(rect.xMin, rect.yMin, depth), uvs[0]);
rightTop = AddVertex(new Vector3(rect.xMax, rect.yMin, depth), uvs[1]);
leftBottom = AddVertex(new Vector3(rect.xMin, rect.yMax, depth), uvs[2]);
rightBottom = AddVertex(new Vector3(rect.xMax, rect.yMax, depth), uvs[3]);
AddTringle(tringles, rightBottom,rightTop , leftTop);
AddTringle(tringles, leftTop, leftBottom, rightBottom);
}
public override void AddQuad(UIVertex vLeftTop,UIVertex vRightTop, UIVertex vLeftBottom, UIVertex vRightBottom)
{
ValidateMesh();
int leftTop = AddVertex(vLeftTop);
int rightTop = AddVertex(vRightTop);
int leftBottom = AddVertex(vLeftBottom);
int rightBottom = AddVertex(vRightBottom);
List<int> tringles = GetTringlesForGroup(0);
AddTringle(tringles, leftTop, rightTop, rightBottom);
AddTringle(tringles, rightBottom, leftBottom, leftTop);
}
Color[] GetColors()
{
Color[] res = new Color[mVertices.Count];
for (int i = 0; i < res.Length; ++i)
res[i] = Color.white;
return res;
}
public void ApplyToMesh(Mesh m)
{
ValidateMesh();
m.Clear();
m.subMeshCount = mTringles.Length;
m.vertices = mVertices.ToArray();
m.colors = GetColors();
m.uv = mUv.ToArray();
for (int i = 0; i < mTringles.Length; i++)
{
if (mTringles[i] == null)
m.SetTriangles(new int[0], i); // set to empt
else
m.SetTriangles(mTringles[i].ToArray(), i);
}
m.RecalculateNormals();
m.RecalculateBounds();
}
public Mesh Generate(Mesh m)
{
ValidateMesh();
if (m == null)
m = new Mesh();
m.subMeshCount = mTringles.Length;
m.SetVertices(mVertices);
m.SetUVs(0,mUv);
m.colors = GetColors();
for (int i = 0; i < mTringles.Length; i++)
{
if (mTringles[i] == null)
m.SetTriangles(new int[0], i); // set to empt
else
m.SetTriangles(mTringles[i], i);
}
m.RecalculateNormals();
m.RecalculateBounds();
return m;
}
public Mesh Generate()
{
ValidateMesh();
Mesh m = new Mesh();
m.subMeshCount = mTringles.Length;
m.vertices = mVertices.ToArray();
m.uv = mUv.ToArray();
m.colors = GetColors();
for (int i=0; i<mTringles.Length; i++)
{
if(mTringles[i] == null)
m.SetTriangles(new int[0],i); // set to empt
else
m.SetTriangles(mTringles[i].ToArray(),i);
}
m.RecalculateNormals();
return m;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ae711d4b861375644a557e54c70a88ad
timeCreated: 1560543266
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: