/************************************************** FileName:ObjectPool ****************************************************/ //using DG.Tweening; using LitJson; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HeatMapDate : MonoBehaviour { private int people;//最大人口 private int range;//范围 private int xpos;//x位置 private int zpos;//z位置 private int min;//最小人口 public int People { get { return people; } set { people = value; } } public int Range { get { return range; } set { range = value; } } public int Xpos { get { return xpos; } set { xpos = value; } } public int Zpos { get { return zpos; } set { zpos = value; } } public int Min { get { return min; } set { min = value; } } } public class HeatMapRead : MonoBehaviour { public TextAsset HeatMapJson; JsonData heatMapJson; public string Layer = ""; List heatMapDate = new List(); //数据集合 public heatControl heatControl; //生成热力图算法代码 public static HeatMapRead instance; private void Awake() { instance = this; Generate(); } void Start() { StartR(); } public int xSize, ySize; private Vector3[] vertices; private Mesh mesh; //生成Mesh private void Generate() { GetComponent().mesh = mesh = new Mesh(); mesh.name = "Procedural Grid"; vertices = new Vector3[(xSize + 1) * (ySize + 1)]; for (int i = 0, y = 0; y <= ySize; y++) { for (int x = 0; x <= xSize; x++, i++) { vertices[i] = new Vector3(x,0,y); } } mesh.vertices = vertices; int[] triangles = new int[xSize * ySize * 6]; for (int ti = 0, vi = 0, y = 0; y < ySize; y++, vi++) { for (int x = 0; x < xSize; x++, ti += 6, vi++) { triangles[ti] = vi; triangles[ti + 3] = triangles[ti + 2] = vi + 1; triangles[ti + 4] = triangles[ti + 1] = vi + xSize + 1; triangles[ti + 5] = vi + xSize + 2; } } mesh.triangles = triangles; // 网格自动计算法线向量 mesh.RecalculateNormals(); //Vector2[] uv = new Vector2[vertices.Length]; //Vector4[] tangents = new Vector4[vertices.Length];//切线 //Vector4 tangent = new Vector4(1f, 0f, 0f, -1f); //for (int i = 0, y = 0; y <= ySize; y++) //{ // for (int x = 0; x <= xSize; x++, i++) // { // uv[i] = new Vector2((float)x / xSize, (float)y / ySize); // tangents[i] = tangent; // } //} //mesh.uv = uv; //mesh.tangents = tangents; } void StartR() { raedHeatMap(0); //this.GetComponent().enabled = false; //this.GetComponent().enabled = false; } public void raedHeatMap(float High) { heatMapDate.Clear();//清空数据 string subwayText = HeatMapJson.text; heatMapJson = JsonMapper.ToObject(subwayText); for (int i = 0; i < heatMapJson[Layer].Count; i++) { HeatMapDate Date = new HeatMapDate(); Date.People = int.Parse(heatMapJson[Layer][i]["people"].ToString()); Date.Range = int.Parse(heatMapJson[Layer][i]["range"].ToString()); Date.Xpos = int.Parse(heatMapJson[Layer][i]["Xpos"].ToString()); Date.Zpos = int.Parse(heatMapJson[Layer][i]["Zpos"].ToString()); Date.Min = int.Parse(heatMapJson[Layer][i]["min"].ToString()); heatMapDate.Add(Date); } heatControl.mapBigen(heatMapDate, High, gameObject); } }