123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- /**************************************************
- 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> heatMapDate = new List<HeatMapDate>(); //数据集合
- 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<MeshFilter>().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<heatControl>().enabled = false;
- //this.GetComponent<HeatMapRead>().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);
- }
-
- }
|