#define Graph_And_Chart_PRO using ChartAndGraph; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class GraphEditable : MonoBehaviour { public GraphChart Graph; public string Category; public RectTransform LastPoint; List mDataArray = new List(); const double MaxDistSqr = 0.025 * 0.025; int mMovingPoint = -1; int mLastMovingPoint = -1; void Start() { if (Graph != null) { Graph.OnRedraw.AddListener(Redraw); } } void Redraw() { if (mLastMovingPoint < 0) { if (LastPoint != null) { if (LastPoint.gameObject.activeSelf) LastPoint.gameObject.SetActive(false); } } else { var last = mDataArray[mLastMovingPoint]; Vector3 pos; if (Graph.PointToWorldSpace(out pos, last.x, last.y, Category)) { if (LastPoint != null) { if (LastPoint.gameObject.activeSelf == false) LastPoint.gameObject.SetActive(true); LastPoint.transform.position = pos; } } } } int FindNearPoint(DoubleVector3 position) { int minDist = -1; double currentMinDist = double.PositiveInfinity; for(int i=0; i= 0) { mDataArray.RemoveAt(mLastMovingPoint); mLastMovingPoint = -1; mMovingPoint = -1; } } if(mMovingPoint != -1) { DoubleVector3 ClampedMousePos = mouseChartPos; if (mMovingPoint > 0) ClampedMousePos.x = Math.Max(mDataArray[mMovingPoint - 1].x,ClampedMousePos.x); if (mMovingPoint + 1 < mDataArray.Count) ClampedMousePos.x = Math.Min(mDataArray[mMovingPoint + 1].x, ClampedMousePos.x); mDataArray[mMovingPoint] = ClampedMousePos; } Graph.DataSource.SetCategoryArray(Category, mDataArray, 0, mDataArray.Count); } }