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,26 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public abstract class ChartParser
|
||||
{
|
||||
public abstract bool SetPathRelativeTo(string pathObject);
|
||||
/// <summary>
|
||||
/// returns null if object not found
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public abstract object GetObject(string name);
|
||||
public abstract object GetChildObject(object obj, string name);
|
||||
public abstract IEnumerable<KeyValuePair<string , object>> GetAllChildObjects(object obj);
|
||||
public abstract string GetChildObjectValue(object obj, string name);
|
||||
public abstract string GetItem(object arr, int item);
|
||||
public abstract object GetItemObject(object arr, int item);
|
||||
public abstract int GetArraySize(object arr);
|
||||
public abstract string ObjectValue(object obj);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5948d4ad51f370c4f927d0d10573cc84
|
||||
timeCreated: 1536396364
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,134 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using SimpleJSON;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
class JsonParser : ChartParser
|
||||
{
|
||||
JSONNode mBaseJson;
|
||||
JSONNode mRelativePath;
|
||||
public JsonParser(string data)
|
||||
{
|
||||
|
||||
mBaseJson = JSON.Parse(data);
|
||||
mRelativePath = mBaseJson;
|
||||
}
|
||||
|
||||
object GetObjectFromRoot(JSONNode root, string name)
|
||||
{
|
||||
string[] parents = name.Split('>');
|
||||
object current = root;
|
||||
for (int i = 0; current != null && i < parents.Length; i++)
|
||||
{
|
||||
string nextNode = parents[i];
|
||||
current = GetChildObject(current, nextNode);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
public override int GetArraySize(object arr)
|
||||
{
|
||||
var node = (JSONNode)arr;
|
||||
if (node.IsArray == false)
|
||||
return 0;
|
||||
return node.Count;
|
||||
}
|
||||
|
||||
public override object GetChildObject(object obj, string name)
|
||||
{
|
||||
var node = (JSONNode)obj;
|
||||
if (name.Length <= 0)
|
||||
return obj;
|
||||
if (char.IsDigit(name[0])) // if it is a number then find by order , atag name cannot start with a digit
|
||||
{
|
||||
if (node.IsArray == false)
|
||||
return null;
|
||||
int index = 0;
|
||||
if (int.TryParse(name, out index) == false) // try parsing the number
|
||||
return null;
|
||||
if (index < 0 || index >= node.Count)
|
||||
return null;
|
||||
return node[index];
|
||||
}
|
||||
if(name.Length>=2 && name[0] == '"' && name[name.Length-1] == '"')
|
||||
{
|
||||
name = name.Substring(1, name.Length - 2); //strip quatation marks
|
||||
}
|
||||
return node[name];
|
||||
}
|
||||
|
||||
|
||||
public override bool SetPathRelativeTo(string pathObject)
|
||||
{
|
||||
mRelativePath = (JSONNode)GetObjectFromRoot(mBaseJson, pathObject);
|
||||
if (mRelativePath == null)
|
||||
{
|
||||
mRelativePath = mBaseJson;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override object GetObject(string name)
|
||||
{
|
||||
return GetObjectFromRoot(mRelativePath, name);
|
||||
}
|
||||
|
||||
public override string GetItem(object arr, int item)
|
||||
{
|
||||
var element = arr as JSONNode;
|
||||
if (element == null)
|
||||
return null;
|
||||
var child = element[item] as JSONNode;
|
||||
if (child == null)
|
||||
return null;
|
||||
return ObjectValue(child);
|
||||
}
|
||||
|
||||
public override object GetItemObject(object arr, int item)
|
||||
{
|
||||
var element = arr as JSONNode;
|
||||
if (element == null)
|
||||
return null;
|
||||
var child = element[item];
|
||||
return child;
|
||||
}
|
||||
|
||||
public override string ObjectValue(object obj)
|
||||
{
|
||||
var element = obj as JSONNode;
|
||||
return element.Value;
|
||||
}
|
||||
|
||||
public override string GetChildObjectValue(object obj, string name)
|
||||
{
|
||||
var element = obj as JSONNode;
|
||||
if (element == null)
|
||||
return null;
|
||||
try
|
||||
{
|
||||
var child = element[name] as JSONNode;
|
||||
return ObjectValue(child);
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override IEnumerable<KeyValuePair<string, object>> GetAllChildObjects(object obj)
|
||||
{
|
||||
var node = (JSONNode)obj;
|
||||
if (node.IsObject == false)
|
||||
yield break;
|
||||
foreach(var key in node.Keys)
|
||||
yield return new KeyValuePair<string, object>(key, node[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0693b788053aab64a88908e1e3d6b944
|
||||
timeCreated: 1536396364
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,146 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.Data.Xml.Dom;
|
||||
#else
|
||||
using System.Xml;
|
||||
#endif
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
class XMLParser : ChartParser
|
||||
{
|
||||
XmlDocument mXmlDoc;
|
||||
XmlElement mRelativeElement;
|
||||
|
||||
public XMLParser(string xml)
|
||||
{
|
||||
mXmlDoc = new XmlDocument();
|
||||
#if WINDOWS_UWP
|
||||
mXmlDoc.LoadXml(xml);
|
||||
#else
|
||||
using (var reader = new StringReader(xml))
|
||||
{
|
||||
mXmlDoc.Load(reader);
|
||||
}
|
||||
#endif
|
||||
mRelativeElement = mXmlDoc.DocumentElement;
|
||||
}
|
||||
|
||||
public override int GetArraySize(object arr)
|
||||
{
|
||||
var element = arr as XmlElement;
|
||||
if (element == null)
|
||||
return 0;
|
||||
return element.ChildNodes.Count;
|
||||
}
|
||||
|
||||
public override object GetChildObject(object obj, string name)
|
||||
{
|
||||
var node = (XmlElement)obj;
|
||||
if (name.Length <= 0)
|
||||
return obj;
|
||||
if (char.IsDigit(name[0])) // if it is a number then find by order , atag name cannot start with a digit
|
||||
{
|
||||
int index = 0;
|
||||
if (int.TryParse(name, out index) == false) // try parsing the number
|
||||
return null;
|
||||
if (index < 0 || index >= node.ChildNodes.Count)
|
||||
return null;
|
||||
return node.ChildNodes[index];
|
||||
}
|
||||
|
||||
return node.SelectSingleNode(name);
|
||||
}
|
||||
|
||||
public override object GetItemObject(object arr, int item)
|
||||
{
|
||||
var element = arr as XmlElement;
|
||||
if (element == null)
|
||||
return null;
|
||||
var child = element.ChildNodes[item] as XmlElement;
|
||||
return child;
|
||||
}
|
||||
|
||||
object GetObjectFromRoot(XmlElement root, string name)
|
||||
{
|
||||
string[] parents = name.Split('>');
|
||||
object current = root;
|
||||
for (int i = 0; current != null && i < parents.Length; i++)
|
||||
{
|
||||
string nextNode = parents[i];
|
||||
current = GetChildObject(current, nextNode);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
public override object GetObject(string name)
|
||||
{
|
||||
return GetObjectFromRoot(mRelativeElement, name);
|
||||
}
|
||||
|
||||
public override bool SetPathRelativeTo(string pathObject)
|
||||
{
|
||||
mRelativeElement = (XmlElement)GetObjectFromRoot(mXmlDoc.DocumentElement, pathObject);
|
||||
if (mRelativeElement == null)
|
||||
{
|
||||
mRelativeElement = mXmlDoc.DocumentElement;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetChildObjectValue(object obj, string name)
|
||||
{
|
||||
var element = obj as XmlElement;
|
||||
if (element == null)
|
||||
return null;
|
||||
var child = element.SelectSingleNode(name) as XmlElement;
|
||||
if (child == null)
|
||||
return null;
|
||||
return ObjectValue(child);
|
||||
}
|
||||
|
||||
public override string GetItem(object arr, int item)
|
||||
{
|
||||
var element = arr as XmlElement;
|
||||
if (element == null)
|
||||
return null;
|
||||
var child = element.ChildNodes[item] as XmlElement;
|
||||
if (child == null)
|
||||
return null;
|
||||
return ObjectValue(child);
|
||||
}
|
||||
|
||||
public override string ObjectValue(object obj)
|
||||
{
|
||||
var element = obj as XmlElement;
|
||||
if (element == null)
|
||||
return null;
|
||||
return element.InnerText;
|
||||
}
|
||||
|
||||
public override IEnumerable<KeyValuePair<string, object>> GetAllChildObjects(object obj)
|
||||
{
|
||||
var element = obj as XmlElement;
|
||||
if (element == null)
|
||||
yield break;
|
||||
foreach(var node in element.ChildNodes)
|
||||
{
|
||||
var xml = node as XmlElement;
|
||||
if(xml != null)
|
||||
{
|
||||
#if WINDOWS_UWP
|
||||
yield return new KeyValuePair<string, object>(xml.TagName, xml);
|
||||
#else
|
||||
yield return new KeyValuePair<string, object>(xml.Name, xml);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 878b8742852947849810df5d673d597c
|
||||
timeCreated: 1536396365
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user