graph chart引入&骑行结果弹窗
This commit is contained in:
1 parent
40d118cea3
commit
96f3644b5b
2374 files changed
+485161
-2410
No files matched your search
@@ -0,0 +1,96 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using ChartAndGraph;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// this is an example of zoom using mouse for the graph chart
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(GraphChart))]
|
||||
public class GraphZoom : MonoBehaviour
|
||||
{
|
||||
GraphChart graph;
|
||||
Vector3 mZoomBasePosition;
|
||||
DoubleVector3 mZoomBaseChartSpace;
|
||||
DoubleVector3 InitalScrolling;
|
||||
DoubleVector3 InitalViewSize;
|
||||
DoubleVector3 InitalViewDirection;
|
||||
DoubleVector3 InitialOrigin;
|
||||
public float errorMargin = 5f;
|
||||
public float ZoomSpeed = 20f;
|
||||
public float MaxViewSize = 10f;
|
||||
public float MinViewSize = 0.1f;
|
||||
float totalZoom = 0;
|
||||
|
||||
// Use this for initialization
|
||||
void Start ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
graph = GetComponent<GraphChart>();
|
||||
}
|
||||
|
||||
void ResetZoomAnchor()
|
||||
{
|
||||
totalZoom = 0;
|
||||
InitalScrolling = new DoubleVector3(graph.HorizontalScrolling, graph.VerticalScrolling);
|
||||
InitalViewSize = new DoubleVector3(graph.DataSource.HorizontalViewSize, graph.DataSource.VerticalViewSize);
|
||||
InitalViewDirection = new DoubleVector3(Math.Sign(InitalViewSize.x), Math.Sign(InitalViewSize.y));
|
||||
InitialOrigin = new DoubleVector3(graph.DataSource.HorizontalViewOrigin, graph.DataSource.VerticalViewOrigin);
|
||||
|
||||
}
|
||||
bool CompareWithError(Vector3 a,Vector3 b)
|
||||
{
|
||||
if (Mathf.Abs(a.x - b.x) > errorMargin)
|
||||
return false;
|
||||
if (Mathf.Abs(a.y - b.y) > errorMargin)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update ()
|
||||
{
|
||||
if (graph == null) // no graph attached to this script for some reason
|
||||
return;
|
||||
Vector2 mousePos = Input.mousePosition;
|
||||
double mouseX, mouseY;
|
||||
graph.PointToClient(mousePos, out mouseX, out mouseY);
|
||||
if (CompareWithError(mousePos, mZoomBasePosition) == false) // the mouse has moved beyond the erroo
|
||||
{
|
||||
mZoomBasePosition = mousePos;
|
||||
graph.PointToClient(mousePos, out mouseX, out mouseY);
|
||||
mZoomBaseChartSpace = new DoubleVector3(mouseX, mouseY);
|
||||
ResetZoomAnchor();
|
||||
}
|
||||
else
|
||||
{
|
||||
mousePos = mZoomBasePosition;
|
||||
}
|
||||
|
||||
float delta = Input.mouseScrollDelta.y;
|
||||
totalZoom += delta; //accumilate the delta change for the currnet positions
|
||||
|
||||
if (delta!=0 && graph.PointToClient(mousePos, out mouseX, out mouseY))
|
||||
{
|
||||
DoubleVector3 ViewCenter = InitialOrigin + InitalScrolling;
|
||||
DoubleVector3 trans = new DoubleVector3((mZoomBaseChartSpace.x - ViewCenter.x), (mZoomBaseChartSpace.y - ViewCenter.y));
|
||||
float growFactor = Mathf.Pow(2,totalZoom/ZoomSpeed);
|
||||
double hSize = InitalViewSize.x * growFactor;
|
||||
double vSize = InitalViewSize.y * growFactor;
|
||||
if (hSize * InitalViewDirection.x < MaxViewSize && hSize * InitalViewDirection.x > MinViewSize && vSize * InitalViewDirection.y < MaxViewSize && vSize * InitalViewDirection.y > MinViewSize )
|
||||
{
|
||||
graph.HorizontalScrolling = InitalScrolling.x + trans.x - (trans.x * growFactor);
|
||||
graph.VerticalScrolling = InitalScrolling.y + trans.y - (trans.y * growFactor);
|
||||
graph.DataSource.HorizontalViewSize = hSize;
|
||||
graph.DataSource.VerticalViewSize = vSize;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3dc21a745b760064c816e20fb5a7f709
|
||||
timeCreated: 1553945584
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37bc33121528f8846bcb70ae9011da67
|
||||
timeCreated: 1553945564
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user