#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 mTmpPath = new List(); // List mOfPathTringles = new List(); List mOfPAth = new List(); List mTmpScales = new List(); List mTmpAngles = new List(); List mTmpTringle = new List(); List mTmpUv = new List(); List mVertices = new List(); bool mClosedSmooth = false; // List mNormals = new List(); 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 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; } SetMesh(mVertices, mTmpUv, mTmpTringle); 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