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,13 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
public partial class BoxPathGenerator
{
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d0055b3aa042fac4a8cd28c7191b9c88
timeCreated: 1489080637
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,183 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
public partial class BoxPathGenerator : SmoothPathGenerator
{
[Range(0f, 10f)]
public float HeightRatio = 1f;
List<int> mTmpTringle = new List<int>();
List<Vector2> mTmpUv = new List<Vector2>();
List<Vector3> mVertices = new List<Vector3>();
int WriteBox(float thickness, Quaternion rotation, Vector3 center, float u)
{
Vector3 vz = new Vector3(thickness, 0f, 0f);
Vector3 vy = new Vector3(0f, thickness * HeightRatio, 0f);
int index = mVertices.Count;
mVertices.Add(center + (rotation * (vz + vy)));
mVertices.Add(center + (rotation * (-vz + vy)));
mVertices.Add(center + (rotation * (-vz - vy)));
mVertices.Add(center + (rotation * (vz - vy)));
mVertices.Add(mVertices[index]);
mVertices.Add(mVertices[index + 1]);
mVertices.Add(mVertices[index + 2]);
mVertices.Add(mVertices[index + 3]);
mTmpUv.Add(new Vector2(u, 0f));
mTmpUv.Add(new Vector2(u, 1f));
mTmpUv.Add(new Vector2(u, 0f));
mTmpUv.Add(new Vector2(u, 1f));
mTmpUv.Add(new Vector2(u, 0f));
mTmpUv.Add(new Vector2(u, 1f));
mTmpUv.Add(new Vector2(u, 0f));
mTmpUv.Add(new Vector2(u, 1f));
return index;
}
void AddTringles(List<int> tringles, int from, int to)
{
tringles.Add(from + 1);
tringles.Add(to);
tringles.Add(from);
tringles.Add(to + 1);
tringles.Add(to);
tringles.Add(from + 1);
tringles.Add(from + 2);
tringles.Add(to + 5);
tringles.Add(from + 5);
tringles.Add(to + 2);
tringles.Add(to + 5);
tringles.Add(from + 2);
tringles.Add(from + 3);
tringles.Add(to + 6);
tringles.Add(from + 6);
tringles.Add(to + 3);
tringles.Add(to + 6);
tringles.Add(from + 3);
tringles.Add(from + 4);
tringles.Add(to + 7);
tringles.Add(from + 7);
tringles.Add(to + 4);
tringles.Add(to + 7);
tringles.Add(from + 4);
}
public override void Generator(Vector3[] path, float thickness, bool closed)
{
if (EnsureMeshFilter() == false) // No mesh filter attached
return;
Clear();
if (path.Length <= 1)
return;
mTmpTringle.Clear();
mTmpUv.Clear();
mVertices.Clear();
ModifyPath(path, closed);
if (mTmpCenters.Count <= 1)
return;
float currentU = 0f;
if(closed == false)
{
int box = WriteBox(thickness, LookRotation(mTmpCenters[1] - mTmpCenters[0]), mTmpCenters[0], currentU);
mTmpTringle.Add(box + 3);
mTmpTringle.Add(box + 1);
mTmpTringle.Add(box);
mTmpTringle.Add(box + 3);
mTmpTringle.Add(box + 2);
mTmpTringle.Add(box + 1);
}
int prevBoxIndex = WriteBox(thickness, LookRotation(mTmpCenters[1] - mTmpCenters[0]), mTmpCenters[0], currentU);
Quaternion rotation = Quaternion.identity;
Vector3 curr = Vector3.zero;
for (int i = 1; i < mTmpCenters.Count; i++)
{
Vector3 prev = mTmpCenters[i - 1];
curr = mTmpCenters[i];
Vector3 diff = curr - prev;
float size = diff.magnitude;
if (size <= 0.0001f)
{
continue;
}
currentU += size;
rotation = LookRotation(diff);
if (i + 1 < mTmpCenters.Count)
{
Vector3 next = mTmpCenters[i + 1];
// Vector3 nextDiff = next - curr;
Quaternion rotationB = LookRotation(next - curr);
rotation = Quaternion.Lerp(rotation, rotationB, 0.5f);
}
int index = WriteBox(thickness, rotation, curr, currentU);
AddTringles(mTmpTringle, prevBoxIndex, index);
prevBoxIndex = index;
}
if (closed == false)
{
int box = WriteBox(thickness, rotation, curr, currentU);
mTmpTringle.Add(box);
mTmpTringle.Add(box + 1);
mTmpTringle.Add(box + 3);
mTmpTringle.Add(box + 1);
mTmpTringle.Add(box + 2);
mTmpTringle.Add(box + 3);
}
for (int i = 0; i < mTmpUv.Count; i++)
{
Vector2 uv = mTmpUv[i];
uv.x /= currentU;
mTmpUv[i] = uv;
}
Mesh mesh = new Mesh();
mesh.vertices = mVertices.ToArray();
mesh.uv = mTmpUv.ToArray();
mesh.triangles = mTmpTringle.ToArray();
mesh.RecalculateNormals();
SetMesh(mesh);
mTmpTringle.Clear();
mTmpUv.Clear();
mVertices.Clear();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fca453e367915cb419b0927c5a6dd5eb
timeCreated: 1489080637
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
partial class CustomPathGenerator
{
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3412fcef59ea91e47bc4cc8e67afe1de
timeCreated: 1498495715
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,306 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
partial class CustomPathGenerator : SmoothPathGenerator, IPieGenerator , IBarGenerator
{
// List<Vector2> mTmpPath = new List<Vector2>();
// List<Vector2> mOfPathTringles = new List<Vector2>();
List<Vector3> mOfPAth = new List<Vector3>();
List<float> mTmpScales = new List<float>();
List<Quaternion> mTmpAngles = new List<Quaternion>();
List<int> mTmpTringle = new List<int>();
List<Vector2> mTmpUv = new List<Vector2>();
List<Vector3> mVertices = new List<Vector3>();
bool mClosedSmooth = false;
// List<Vector3> mNormals = new List<Vector3>();
int writeItem(Quaternion angle, Vector3 center, float scale, float u)
{
int index = mVertices.Count;
for (int i = 0; i < mOfPAth.Count; i++)
{
Vector3 current = mOfPAth[i] * scale;
current = angle * current;
current += center;
float v = ((float)i) / (float)(mOfPAth.Count - 1);
mTmpUv.Add(new Vector2(u, v));
mVertices.Add(current);
}
return index;
}
void AddTringles(List<int> tringles, int from, int to)
{
if (mOfPAth.Count <= 1)
return;
for (int i = 0; i < mOfPAth.Count; i++)
{
int prev = i - 1;
if (prev < 0)
prev = mOfPAth.Count - 1;
int fromPrev = from + prev;
int toPrev = to + prev;
int fromCurr = from + i;
int toCurr = to + i;
tringles.Add(fromPrev);
tringles.Add(fromCurr);
tringles.Add(toCurr);
tringles.Add(toCurr);
tringles.Add(toPrev);
tringles.Add(fromPrev);
}
}
protected void OfPath(Vector3[] path)
{
ModifyPath(path, true, mOfPAth);
}
Quaternion getAngle(int index, Quaternion def)
{
if (mTmpAngles.Count <= index)
{
return def;
}
return mTmpAngles[index];
}
float getScale(int index)
{
if (mTmpScales.Count <= index)
return 1f;
return mTmpScales[index];
}
public override void Generator(Vector3[] path, float thickness, bool closed)
{
if (EnsureMeshFilter() == false) // No mesh filter attached
return;
Clear();
if (path.Length <= 1)
return;
mTmpTringle.Clear();
mTmpUv.Clear();
mVertices.Clear();
// ModifyPath(path, closed);
mTmpCenters.Clear();
mTmpCenters.AddRange(path);
if (mTmpCenters.Count <= 1)
return;
float currentU = 0f;
int prevItemIndex = writeItem(getAngle(0, LookRotation(mTmpCenters[1] - mTmpCenters[0])), mTmpCenters[0], getScale(0), currentU);
if (closed == false)
{
int item = prevItemIndex;
if (mClosedSmooth == false)
item = writeItem(getAngle(0, LookRotation(mTmpCenters[1] - mTmpCenters[0])), mTmpCenters[0], getScale(0), currentU);
mVertices.Add(mTmpCenters[0]);
mTmpUv.Add(new Vector2(0f, 0.5f));
for (int i = 0; i < mOfPAth.Count; i++)
{
int next = (i + 1) % mOfPAth.Count;
mTmpTringle.Add(item + mOfPAth.Count);
mTmpTringle.Add(item + next);
mTmpTringle.Add(item + i);
}
}
Vector3 curr = Vector3.zero;
Quaternion rotation = Quaternion.identity;
for (int i = 1; i < mTmpCenters.Count; i++)
{
Vector3 prev = mTmpCenters[i - 1];
curr = mTmpCenters[i];
Vector3 diff = curr - prev;
float size = diff.magnitude;
currentU += size;
rotation = LookRotation(diff);
int index = writeItem(getAngle(i, rotation), curr, getScale(i), currentU);
AddTringles(mTmpTringle, prevItemIndex, index);
prevItemIndex = index;
}
if (closed == false)
{
int item = prevItemIndex;
if (mClosedSmooth == false)
item = writeItem(getAngle(mTmpCenters.Count - 1, rotation), curr, getScale(mTmpCenters.Count - 1), 1f);
mVertices.Add(curr);
mTmpUv.Add(new Vector2(1f, 0.5f));
for (int i = 0; i < mOfPAth.Count; i++)
{
int next = (i + 1) % mOfPAth.Count;
mTmpTringle.Add(item + next);
mTmpTringle.Add(item + mOfPAth.Count);
mTmpTringle.Add(item + i);
}
}
for (int i = 0; i < mTmpUv.Count; i++)
{
Vector2 uv = mTmpUv[i];
uv.x /= currentU;
mTmpUv[i] = uv;
}
Mesh mesh = new Mesh();
mesh.vertices = mVertices.ToArray();
mesh.uv = mTmpUv.ToArray();
mesh.triangles = mTmpTringle.ToArray();
mesh.RecalculateNormals();
SetMesh(mesh);
mTmpTringle.Clear();
mTmpUv.Clear();
mVertices.Clear();
}
private float quickBlend(float blend)
{
return Mathf.Sqrt(1- blend* blend);
}
public void Generate(float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerdepth,float innerdepth)
{
mClosedSmooth = false;
float maxDepth = Mathf.Max(innerdepth,outerdepth);
Vector3[] path = new Vector3[] { new Vector3(0f, radius , 0f), new Vector3(0f, innerRadius, 0f), new Vector3(outerdepth, innerRadius, 0f), new Vector3(innerdepth, radius, 0f) };
float midRadius = (innerRadius + radius) * 0.5f;
Vector3 center = new Vector3(maxDepth * 0.5f, midRadius);
for (int j = 0; j < path.Length; j++)
path[j] -= center;
mSkipJoints.Clear();
if (innerRadius <= 0.0001f)
{
mSkipJoints.Add(0);
mSkipJoints.Add(3);
mSkipJoints.Add(4);
}
OfPath(path);
Vector3[] alongPath = new Vector3[segments + 1 ];
float toAngle = startAngle + angleSpan;
if(Mathf.Abs(startAngle - toAngle) < 0.0001f)
{
Generator(new Vector3[0], 0f, false);
return;
}
int i = 0;
mTmpScales.Clear();
mTmpAngles.Clear();
// float dir = Mathf.Sign(angleSpan);
// float minSize = Mathf.Max(0f, 1f - JointSize);
//startAngle = startAngle + dir * JointSize / midRadius;
/* for (; i<JointSmoothing; i++)
{
float blend = 1f - (i / ((float)JointSmoothing));
float angle = startAngle - ((JointSize / midRadius) * blend)* dir;
alongPath[i] = ChartCommon.FromPolarRadians(angle, midRadius);
mTmpAngles.Add(Quaternion.Euler(-90f, 0f, 0f) * Quaternion.Euler(0f, -angle * Mathf.Rad2Deg, 0f) * Quaternion.Euler(0f, 0f, 90f));
mTmpScales.Add(1f);// Mathf.Lerp(0f,1f , quickBlend(blend )));
}*/
// float toJoint = toAngle + dir * (JointSize / midRadius);
// int next = JointSmoothing + segments;
for(i=0 ; i<= segments; i++)
{
float blend = (i) / ((float)segments);
float angle = Mathf.Lerp(startAngle, toAngle, blend);
alongPath[i] = ChartCommon.FromPolarRadians(angle, midRadius);
mTmpAngles.Add(Quaternion.Euler(-90f, 0f, 0f) * Quaternion.Euler(0f, -angle * Mathf.Rad2Deg,0f) * Quaternion.Euler(0f,0f, 90f));
mTmpScales.Add(1f);
}
/* for (i =0 ; i < JointSmoothing; i++)
{
float blend = (i+1) / ((float)JointSmoothing);
float angle = toAngle + ((JointSize / midRadius) * blend) * dir;
alongPath[next+ 1 + i] = ChartCommon.FromPolarRadians(angle, midRadius);
mTmpAngles.Add(Quaternion.Euler(-90f, 0f, 0f) * Quaternion.Euler(0f, -angle * Mathf.Rad2Deg, 0f) * Quaternion.Euler(0f, 0f, 90f));
mTmpScales.Add(Mathf.Lerp(0f,1f, quickBlend(blend) ));
}*/
Generator(alongPath, 0f, false);
}
void IBarGenerator.Generate(float normalizedSize,float scale)
{
mClosedSmooth = false;
Vector3[] path = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 1f), new Vector3(1f, 0f, 1f), new Vector3(1f, 0f, 0f)};
Vector3 center = new Vector3(0.5f, 0f,0.5f);
for (int j = 0; j < path.Length; j++)
path[j] -= center;
mSkipJoints.Clear();
OfPath(path);
Vector3[] alongPath = new Vector3[(JointSmoothing+3)*2];
if (scale < 0.0001f)
{
Generator(new Vector3[0], 0f, false);
return;
}
int i = 0;
mTmpScales.Clear();
mTmpAngles.Clear();
float joint = JointSize / scale;
joint = Math.Min(joint, 0.5f);
float minSize = 1f - JointSize;
for (i=0 ; i<= JointSmoothing+2; i++)
{
float blend = (i / ((float)JointSmoothing));
float pos = joint * blend;
alongPath[i] = new Vector3(0f, pos);
mTmpAngles.Add(Quaternion.identity);
mTmpScales.Add(Mathf.Lerp(minSize,1f,quickBlend(1f-blend)));
}
for (i=0; i <= JointSmoothing+2; i++)
{
float blend = 1f - ((i-2) / ((float)JointSmoothing));
float pos = 1f - joint * blend;
alongPath[i + JointSmoothing +3] = new Vector3(0f, pos);
mTmpAngles.Add(Quaternion.identity);
mTmpScales.Add(Mathf.Lerp(minSize, 1f, quickBlend(1f - blend)));
}
Generator(alongPath, 0f, false);
}
void IBarGenerator.Clear()
{
Clear();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e9f88870c639e2949bc62fb1821bb39e
timeCreated: 1498495715
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,16 @@
#define Graph_And_Chart_PRO
using ChartAndGraph;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
public partial class CylinderPathGenerator
{
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6859cae0c63d44d49a83cc630d5ec33d
timeCreated: 1488383599
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,177 @@
#define Graph_And_Chart_PRO
using ChartAndGraph;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
public partial class CylinderPathGenerator : SmoothPathGenerator
{
public int CircleVertices = 10;
[Range(0.01f,10.0f)]
public float HeightRatio = 1f;
Vector3[] mCircleTemp;
Vector3[] mCurrentCircle;
List<int> mTmpTringle = new List<int>();
List<Vector2> mTmpUv = new List<Vector2>();
List<Vector3> mVertices = new List<Vector3>();
void EnsureCirlce()
{
if(mCircleTemp == null || mCircleTemp.Length !=CircleVertices)
{
mCircleTemp = new Vector3[CircleVertices];
for(int i=0; i<CircleVertices; i++)
{
float intep = ((float)i) / ((float)CircleVertices);
float angle = intep * Mathf.PI * 2f;
mCircleTemp[i] = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0.0f);
}
mCurrentCircle = new Vector3[CircleVertices];
}
}
int WriteCircle(float thickness,Quaternion angle,Vector3 center,float u)
{
EnsureCirlce();
mCircleTemp.CopyTo(mCurrentCircle, 0);
for(int i=0; i< mCurrentCircle.Length; i++)
{
mCurrentCircle[i] *= thickness;
mCurrentCircle[i].y *= HeightRatio;
mCurrentCircle[i] = angle * mCurrentCircle[i];
mCurrentCircle[i] += center;
float v = ((float)i) / (float)(mCurrentCircle.Length - 1);
mTmpUv.Add(new Vector2(u, v));
}
int index = mVertices.Count;
mVertices.AddRange(mCurrentCircle);
return index;
}
void AddTringles(List<int> tringles, int from, int to)
{
if (CircleVertices <= 1)
return;
for (int i = 0; i < CircleVertices; i++)
{
int prev = i - 1;
if (prev < 0)
prev = CircleVertices - 1;
int fromPrev = from + prev;
int toPrev = to + prev;
int fromCurr = from + i;
int toCurr = to + i;
tringles.Add(fromPrev);
tringles.Add(fromCurr);
tringles.Add(toCurr);
tringles.Add(toCurr);
tringles.Add(toPrev);
tringles.Add(fromPrev);
}
}
public override void Generator(Vector3[] path, float thickness, bool closed)
{
if (EnsureMeshFilter() == false) // No mesh filter attached
return;
Clear();
if (path.Length <= 1)
return;
mTmpTringle.Clear();
mTmpUv.Clear();
mVertices.Clear();
ModifyPath(path, closed);
if (mTmpCenters.Count <= 1)
return;
float currentU = 0f;
int prevCircleIndex = WriteCircle(thickness, LookRotation(mTmpCenters[1] - mTmpCenters[0]), mTmpCenters[0], currentU);
if (closed == false)
{
int circle = WriteCircle(thickness, LookRotation(mTmpCenters[1] - mTmpCenters[0]), mTmpCenters[0], currentU);
mVertices.Add(mTmpCenters[0]);
mTmpUv.Add(new Vector2(0f, 0.5f));
for (int i = 0; i < CircleVertices; i++)
{
int next = (i + 1) % CircleVertices;
mTmpTringle.Add(circle + CircleVertices);
mTmpTringle.Add(circle + next);
mTmpTringle.Add(circle + i);
}
}
Vector3 curr = Vector3.zero;
Quaternion rotation = Quaternion.identity;
for (int i=1; i<mTmpCenters.Count; i++)
{
Vector3 prev = mTmpCenters[i - 1];
curr = mTmpCenters[i];
Vector3 diff = curr - prev;
float size = diff.magnitude;
currentU += size;
rotation = LookRotation(diff);
/*if (i + 1 < mTmpCenters.Count)
{
Vector3 next = mTmpCenters[i + 1];
Quaternion rotationB = Quaternion.LookRotation(next - curr, Vector3.up);
rotation = Quaternion.Lerp(rotation, rotationB, 0.5f);
}*/
int index = WriteCircle(thickness, rotation, curr, 0f);
AddTringles(mTmpTringle, prevCircleIndex, index);
prevCircleIndex = index;
}
if (closed == false)
{
int circle = WriteCircle(thickness, rotation, curr, 1f);
mVertices.Add(curr);
mTmpUv.Add(new Vector2(1f, 0.5f));
for (int i = 0; i < CircleVertices; i++)
{
int next = (i + 1) % CircleVertices;
mTmpTringle.Add(circle + next);
mTmpTringle.Add(circle + CircleVertices);
mTmpTringle.Add(circle + i);
}
}
for (int i=0; i<mTmpUv.Count; i++)
{
Vector2 uv = mTmpUv[i];
uv.x /= currentU;
mTmpUv[i] = uv;
}
Mesh mesh = new Mesh();
mesh.vertices = mVertices.ToArray();
mesh.uv = mTmpUv.ToArray();
mesh.triangles = mTmpTringle.ToArray();
mesh.RecalculateNormals();
SetMesh(mesh);
mTmpTringle.Clear();
mTmpUv.Clear();
mVertices.Clear();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4ae9b56b2362a324ea004692a3ce7554
timeCreated: 1488383599
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
public partial class FillPathGenerator
{
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 411b843e6ce35a74dba67c0fa1071b85
timeCreated: 1489167357
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,214 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
public partial class FillPathGenerator : SmoothPathGenerator
{
public bool WithTop = true;
public bool MatchLine = true;
private float mGraphBottom = 0f;
private float mGraphTop = 10f;
private bool StretchFill = false;
List<int> mTmpTringle = new List<int>();
List<Vector2> mTmpUv = new List<Vector2>();
List<Vector3> mVertices = new List<Vector3>();
private bool mHasParent = false;
private int mParentJointSmoothing;
private float mParentJointSize;
protected override float JointSizeLink
{
get
{
if (MatchLine == true && mHasParent)
return mParentJointSize;
return base.JointSizeLink;
}
}
protected override int JointSmoothingLink
{
get
{
if (MatchLine == true && mHasParent)
return mParentJointSmoothing;
return base.JointSmoothingLink;
}
}
public void SetLineSmoothing(bool hasParent,int jointSmoothing , float jointSize)
{
mHasParent = hasParent;
mParentJointSmoothing = jointSmoothing;
mParentJointSize = jointSize;
}
public void SetStrechFill(bool strech)
{
StretchFill = strech;
}
public void SetGraphBounds(float bottom,float top)
{
mGraphBottom = bottom;
mGraphTop = top;
}
int WriteVector(Vector3 position,float thickness,float u)
{
Vector3 v = new Vector3(0, 0, thickness);
Vector3 bottomPosition = new Vector3(position.x, mGraphBottom, position.z);
int index = mVertices.Count;
float vTex = 1f;
if(StretchFill == false)
vTex = Mathf.Abs((position.y - mGraphBottom) / (mGraphBottom - mGraphTop));
mVertices.Add(position - v);
mVertices.Add(position + v);
mVertices.Add(bottomPosition - v);
mVertices.Add(bottomPosition + v);
mVertices.Add(mVertices[index + 2]);
mVertices.Add(mVertices[index + 3]);
mTmpUv.Add(new Vector2(u, vTex));
mTmpUv.Add(new Vector2(u, vTex));
mTmpUv.Add(new Vector2(u, 0f));
mTmpUv.Add(new Vector2(u, 0f));
mTmpUv.Add(new Vector2(u, 0f));
mTmpUv.Add(new Vector2(u, 0f));
if (WithTop)
{
mVertices.Add(mVertices[index]);
mVertices.Add(mVertices[index + 1]);
mTmpUv.Add(new Vector2(u, vTex));
mTmpUv.Add(new Vector2(u, vTex));
}
return index;
}
void AddTringles(List<int> tringles, int from, int to)
{
tringles.Add(from);
tringles.Add(to);
tringles.Add(from +2);
tringles.Add(to);
tringles.Add(to + 2);
tringles.Add(from + 2);
tringles.Add(from + 3);
tringles.Add(to + 1);
tringles.Add(from +1 );
tringles.Add(from + 3);
tringles.Add(to + 3);
tringles.Add(to + 1);
tringles.Add(from + 4);
tringles.Add(to + 4);
tringles.Add(from + 5);
tringles.Add(to + 4);
tringles.Add(to + 5);
tringles.Add(from + 5);
if(WithTop)
{
tringles.Add(from + 7);
tringles.Add(to + 6);
tringles.Add(from + 6);
tringles.Add(from + 7);
tringles.Add(to + 7);
tringles.Add(to + 6);
}
}
public override void Generator(Vector3[] path, float thickness, bool closed)
{
if (EnsureMeshFilter() == false) // No mesh filter attached
return;
Clear();
if (path.Length <= 1)
return;
mTmpTringle.Clear();
mTmpUv.Clear();
mVertices.Clear();
ModifyPath(path, closed);
if (mTmpCenters.Count <= 1)
return;
float currentU = 0f;
int first = WriteVector(mTmpCenters[0], thickness, currentU);
mTmpTringle.Add(first + 2);
mTmpTringle.Add(first + 1);
mTmpTringle.Add(first);
mTmpTringle.Add(first + 1);
mTmpTringle.Add(first + 2);
mTmpTringle.Add(first + 3);
int prevIndex = WriteVector(mTmpCenters[0], thickness, currentU);
for (int i = 1; i < mTmpCenters.Count; i++)
{
Vector3 prev = mTmpCenters[i - 1];
Vector3 curr = mTmpCenters[i];
Vector3 diff = curr - prev;
float size = diff.magnitude;
currentU += size;
int index = WriteVector(curr, thickness, currentU);
AddTringles(mTmpTringle, prevIndex, index);
prevIndex = index;
}
int last = WriteVector(mTmpCenters[mTmpCenters.Count-1], thickness, currentU);
mTmpTringle.Add(last);
mTmpTringle.Add(last + 1);
mTmpTringle.Add(last + 2);
mTmpTringle.Add(last + 3);
mTmpTringle.Add(last + 2);
mTmpTringle.Add(last + 1);
for (int i = 0; i < mTmpUv.Count; i++)
{
Vector2 uv = mTmpUv[i];
uv.x /= currentU;
mTmpUv[i] = uv;
}
Mesh mesh = new Mesh();
mesh.vertices = mVertices.ToArray();
mesh.uv = mTmpUv.ToArray();
mesh.triangles = mTmpTringle.ToArray();
mesh.RecalculateNormals();
SetMesh(mesh);
mTmpTringle.Clear();
mTmpUv.Clear();
mVertices.Clear();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3b68b2a089adb4d479a37880858c5ca9
timeCreated: 1489167357
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
partial class LineRendererPathGenerator
{
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a49e5c9e817d87249af053a56ca8d813
timeCreated: 1488904479
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,67 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
[RequireComponent(typeof(LineRenderer))]
partial class LineRendererPathGenerator : PathGenerator
{
LineRenderer mRenderer;
private void Start()
{
}
public void EnsureRenderer()
{
mRenderer = GetComponent<LineRenderer>();
}
public override void Clear()
{
EnsureRenderer();
if (mRenderer!= null)
{
#if (!UNITY_5_2) && (!UNITY_5_3) && (!UNITY_5_4)
#if !UNITY_5_5
mRenderer.positionCount = 0;
#else
mRenderer.numPositions = 0;
#endif
#else
mRenderer.SetVertexCount(0);
#endif
}
}
public override void Generator(Vector3[] path, float thickness, bool closed)
{
EnsureRenderer();
if (mRenderer != null)
{
#if !UNITY_5_2 && !UNITY_5_3 && !UNITY_5_4
#if !UNITY_5_5
mRenderer.startWidth = thickness;
mRenderer.endWidth = thickness;
mRenderer.positionCount = path.Length;
#else
mRenderer.startWidth = thickness;
mRenderer.endWidth = thickness;
mRenderer.numPositions = path.Length;
#endif
#else
mRenderer.SetWidth(thickness, thickness);
mRenderer.SetVertexCount(path.Length);
#endif
for (int i=0; i< path.Length; i++)
{
mRenderer.SetPosition(i, path[i]);
}
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4a751c7804d410f40bc211f571dc78c5
timeCreated: 1488904479
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,13 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
public abstract partial class PathGenerator
{
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c64343d28c100bd46a0930dc82931a3b
timeCreated: 1488383599
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
public abstract partial class PathGenerator : MonoBehaviour
{
public abstract void Generator(Vector3[] path, float thickness, bool closed);
public abstract void Clear();
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9e6f29678fa702542a3a3be8792e3566
timeCreated: 1488383599
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
partial class PathMultiplier
{
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 17a173f5e7307154787e5e08670e4f1e
timeCreated: 1498398193
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,136 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
partial class PathMultiplier
{
public int JointSmoothing = 2;
public float JointSize = 0.1f;
private List<Vector3> mInnerTmpCenters = new List<Vector3>();
protected List<Vector3> mTmpCenters = new List<Vector3>();
protected List<Vector3> mMultipliedPath = new List<Vector3>();
protected Quaternion LookRotation(Vector3 diff)
{
Vector3 up = new Vector3(diff.y, -diff.x, 0f).normalized;
return Quaternion.LookRotation(diff, up);
}
void AddJointSegments(Vector3 from, Vector3 curr, Vector3 to)
{
if (JointSmoothing <= 0)
{
mInnerTmpCenters.Add(curr);
return;
}
for (int i = 0; i < JointSmoothing; i++)
{
float t = ((float)(i + 1)) / (float)(JointSmoothing + 1);
float invT = 1f - t;
Vector3 point = Vector3.zero;
/* if (t < 0.5f)
point = Vector3.Lerp(from, curr, t / 0.5f);
else
point = Vector3.Lerp(curr, to, (t - 0.5f) / 0.5f);*/
point = (invT * invT * from) + (2 * invT * t * curr) + (t * t * to);
mInnerTmpCenters.Add(point);
}
}
void AddCenters(Vector3 translation,float scale)
{
for(int i=0; i< mTmpCenters.Count; i++)
{
mMultipliedPath.Add((mTmpCenters[i] * scale) + translation);
}
}
public void ApplyToMesh(WorldSpaceChartMesh mesh)
{
}
public void MultiplyPath(Vector3[] path)
{
mMultipliedPath.Clear();
for(int i=0; i<path.Length; i++)
{
AddCenters(path[i],1f);
}
}
public void ModifyPath(Vector3[] path, bool closed)
{
if (path.Length <= 1)
return;
mInnerTmpCenters.Clear();
for (int i = 0; i <= path.Length; i++)
{
// bool closing = false;
if (i == 0 && closed == false)
{
mInnerTmpCenters.Add(path[0]);
continue;
}
if (i >= path.Length - 1)
{
if (closed == false)
continue;
}
int prevIndex = i - 1;
if (prevIndex < 0)
prevIndex = path.Length - 1;
Vector3 prev = path[prevIndex];
// int currIndex = i;
Vector3 curr = path[i % path.Length];
int nextIndex = i + 1;
Vector3 next = path[nextIndex % path.Length];
Vector3 dir1 = (curr - prev);
Vector3 dir2 = (next - curr);
float dirMag1 = dir1.magnitude;
float dirMag2 = dir2.magnitude;
dir1.Normalize();
dir2.Normalize();
float fromSize = Math.Min(JointSize, dirMag1 * 0.5f);
float toSize = Math.Min(JointSize, dirMag2 * 0.5f);
Vector3 from = curr - dir1 * fromSize;
Vector3 to = curr + dir2 * toSize;
Vector3 innerFrom = curr - dir1 * fromSize * 0.7f;
Vector3 innerTo = curr + dir2 * toSize * 0.7f;
if (i > 0)
{
mInnerTmpCenters.Add(from);
mInnerTmpCenters.Add(innerFrom);
AddJointSegments(innerFrom, curr, innerTo);
mInnerTmpCenters.Add(innerTo);
}
mInnerTmpCenters.Add(to);
}
if (closed == false)
mInnerTmpCenters.Add(path[path.Length - 1]);
// else
// mInnerTmpCenters.Add(path[0]);
mTmpCenters.Clear();
mTmpCenters.Add(mInnerTmpCenters[0]);
for (int i = 1; i < mInnerTmpCenters.Count; i++)
{
Vector3 prev = mInnerTmpCenters[i - 1];
Vector3 curr = mInnerTmpCenters[i];
if ((curr - prev).sqrMagnitude < 0.000001)
continue;
mTmpCenters.Add(curr);
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 31c030300564f9e428db825cc16e9a41
timeCreated: 1498398193
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
public abstract partial class SmoothPathGenerator
{
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 08530d15afb626344afebb5cb5580d76
timeCreated: 1489080637
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,173 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
public abstract partial class SmoothPathGenerator : PathGenerator
{
public int JointSmoothing = 2;
public float JointSize = 0.1f;
protected List<int> mSkipJoints = new List<int>();
protected virtual int JointSmoothingLink
{
get { return JointSmoothing; }
}
protected virtual float JointSizeLink
{
get { return JointSize; }
}
private List<Vector3> mInnerTmpCenters = new List<Vector3>();
protected List<Vector3> mTmpCenters = new List<Vector3>();
/// <summary>
/// the mesh filter for this object
/// </summary>
MeshFilter mFilter;
/// <summary>
/// Contains a mesh that was generate for this object only and should be destoryed once the object is cleaned
/// </summary>
Mesh mCleanMesh = null;
public override void Clear()
{
ChartCommon.CleanMesh(null, ref mCleanMesh);
}
public void OnDestroy()
{
Clear();
}
/* public void Update()
{
foreach(Vector3 point in mTmpCenters)
{
Debug.DrawLine(point, point + Vector3.up);
}
}*/
protected bool EnsureMeshFilter()
{
if (mFilter == null)
mFilter = GetComponent<MeshFilter>();
if (mFilter == null)
return false;
return true;
}
public void SetMesh(Mesh mesh)
{
mesh.hideFlags = HideFlags.DontSave;
mFilter.sharedMesh = mesh;
ChartCommon.CleanMesh(mesh, ref mCleanMesh);
MeshCollider collider = GetComponent<MeshCollider>();
if (collider != null)
collider.sharedMesh = mesh;
}
protected Quaternion LookRotation(Vector3 diff)
{
if (diff.sqrMagnitude <= float.Epsilon)
return Quaternion.identity;
Vector3 up = new Vector3(diff.y, -diff.x, 0f).normalized;
return Quaternion.LookRotation(diff, up);
}
void AddJointSegments(Vector3 from, Vector3 curr, Vector3 to)
{
if (JointSmoothingLink <= 0)
{
mInnerTmpCenters.Add(curr);
return;
}
for (int i = 0; i < JointSmoothingLink; i++)
{
float t = ((float)(i + 1)) / (float)(JointSmoothingLink + 1);
float invT = 1f - t;
Vector3 point = Vector3.zero;
/* if (t < 0.5f)
point = Vector3.Lerp(from, curr, t / 0.5f);
else
point = Vector3.Lerp(curr, to, (t - 0.5f) / 0.5f);*/
point = (invT * invT * from) + (2 * invT * t * curr) + (t * t * to);
mInnerTmpCenters.Add(point);
}
}
protected void ModifyPath(Vector3[] path, bool closed,List<Vector3> res)
{
if (path.Length <= 1)
return;
mInnerTmpCenters.Clear();
for (int i = 0; i <= path.Length; i++)
{
// bool closing = false;
if ((i == 0 && closed == false) || mSkipJoints.Contains(i))
{
if(i < path.Length)
mInnerTmpCenters.Add(path[i]);
continue;
}
if (i >= path.Length - 1)
{
if (closed == false)
continue;
}
int prevIndex = i - 1;
if (prevIndex < 0)
prevIndex = path.Length - 1;
Vector3 prev = path[prevIndex];
// int currIndex = i;
Vector3 curr = path[i % path.Length];
int nextIndex = i + 1;
Vector3 next = path[nextIndex % path.Length];
Vector3 dir1 = (curr - prev);
Vector3 dir2 = (next - curr);
float dirMag1 = dir1.magnitude;
float dirMag2 = dir2.magnitude;
dir1.Normalize();
dir2.Normalize();
float fromSize = Math.Min(JointSizeLink, dirMag1 * 0.5f);
float toSize = Math.Min(JointSizeLink, dirMag2 * 0.5f);
Vector3 from = curr - dir1 * fromSize;
Vector3 to = curr + dir2 * toSize;
Vector3 innerFrom = curr - dir1 * fromSize * 0.7f;
Vector3 innerTo = curr + dir2 * toSize * 0.7f;
if (i > 0)
{
mInnerTmpCenters.Add(from);
mInnerTmpCenters.Add(innerFrom);
AddJointSegments(innerFrom, curr, innerTo);
mInnerTmpCenters.Add(innerTo);
}
mInnerTmpCenters.Add(to);
}
if (closed == false)
mInnerTmpCenters.Add(path[path.Length - 1]);
// else
// mInnerTmpCenters.Add(path[0]);
res.Clear();
res.Add(mInnerTmpCenters[0]);
for (int i = 1; i < mInnerTmpCenters.Count; i++)
{
Vector3 prev = mInnerTmpCenters[i - 1];
Vector3 curr = mInnerTmpCenters[i];
if ((curr - prev).sqrMagnitude < 0.000001)
continue;
res.Add(curr);
}
}
protected void ModifyPath(Vector3[] path, bool closed)
{
ModifyPath(path, closed, mTmpCenters);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d6a3fed51af3f884784e1777ad147698
timeCreated: 1489080637
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: