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,91 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using ChartAndGraph;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
public class BarRunChart : MonoBehaviour
|
||||
{
|
||||
|
||||
class RunChartEntry
|
||||
{
|
||||
public RunChartEntry(string name,double amount)
|
||||
{
|
||||
Name = name;
|
||||
Amount = amount;
|
||||
}
|
||||
public string Name;
|
||||
public double Amount;
|
||||
}
|
||||
|
||||
public float switchTime = 0.1f;
|
||||
float switchTimeCounter =0f;
|
||||
|
||||
List<RunChartEntry> mEntries = new List<RunChartEntry>();
|
||||
public Material SourceMaterial;
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
switchTimeCounter = switchTime;
|
||||
|
||||
|
||||
var bar = GetComponent<BarChart>();
|
||||
bar.TransitionTimeBetaFeature = switchTime;
|
||||
bar.DataSource.ClearCategories();
|
||||
bar.DataSource.ClearGroups();
|
||||
bar.DataSource.AddGroup("Default");
|
||||
|
||||
// generate a random run chart
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
string categoryName = "Item " + i;
|
||||
mEntries.Add(new RunChartEntry(categoryName, UnityEngine.Random.value * 10));
|
||||
Material mat = new Material(SourceMaterial);
|
||||
mat.color = new Color(
|
||||
UnityEngine.Random.Range(0f, 1f),
|
||||
UnityEngine.Random.Range(0f, 1f),
|
||||
UnityEngine.Random.Range(0f, 1f)
|
||||
);
|
||||
bar.DataSource.AddCategory(categoryName, mat);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void AddValuesToCategories()
|
||||
{
|
||||
|
||||
for (int i = 0; i < mEntries.Count; i++)
|
||||
{
|
||||
mEntries[i].Amount += UnityEngine.Random.Range(-0.3f, 0.3f);
|
||||
}
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// changes are timed
|
||||
switchTimeCounter -= Time.deltaTime;
|
||||
if (switchTimeCounter < 0f)
|
||||
{
|
||||
switchTimeCounter = switchTime;
|
||||
var bar = GetComponent<BarChart>();
|
||||
//position the categories according to the currently displayed values
|
||||
for (int i = 0; i < mEntries.Count; i++)
|
||||
{
|
||||
bar.DataSource.MoveCategory(mEntries[i].Name, i);
|
||||
}
|
||||
// add the changes
|
||||
AddValuesToCategories();
|
||||
// sort the changes
|
||||
mEntries.Sort((x, y) => (int)Math.Sign(x.Amount - y.Amount));
|
||||
// animate the transition to the next values
|
||||
for (int i = 0; i < mEntries.Count; i++)
|
||||
{
|
||||
|
||||
bar.DataSource.SlideValue(mEntries[i].Name, "Default", mEntries[i].Amount, switchTime);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user