G a_ heatmap data. Due to Unity watching serializeable properties we need to save the data on a component that isn't active. If we have a lot of data points Unity's watch will totally crash the game.
Наследование: MonoBehaviour
Пример #1
0
    public void OnSuccessDownload(GA_Request.RequestType requestType, Hashtable jsonList, GA_Request.SubmitErrorHandler errorEvent)
    {
        DownloadingData = false;
        BuildingHeatmap = true;

        if (DataContainer == null)
        {
            var dataContainerObject = new GameObject("GA_Data");
            dataContainerObject.transform.parent = transform;
            DataContainer = dataContainerObject.AddComponent <GA_HeatmapData>();

            DataContainer.Data = new List <GA_DataPoint>();
            GA.Log(DataContainer);
        }
        else if (_combineType == CombineHeatmapType.None)
        {
            DataContainer.Data.Clear();
        }

        List <GA_DataPoint> DPsToDelete = new List <GA_DataPoint>();

        ArrayList jsonArrayX     = (ArrayList)jsonList["x"];
        ArrayList jsonArrayY     = (ArrayList)jsonList["y"];
        ArrayList jsonArrayZ     = (ArrayList)jsonList["z"];
        ArrayList jsonArrayValue = (ArrayList)jsonList["value"];

        for (int i = 0; i < jsonArrayX.Count; i++)
        {
            try
            {
                bool done = false;
                if (_combineType == CombineHeatmapType.Add)
                {
                    Vector3 position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
                    int     count    = int.Parse(jsonArrayValue[i].ToString());

                    for (int u = 0; u < DataContainer.Data.Count; u++)
                    {
                        if (DataContainer.Data[u].position == position)
                        {
                            DataContainer.Data[u].count += count;
                            done = true;
                            u    = DataContainer.Data.Count;
                        }
                    }
                }
                else if (_combineType == CombineHeatmapType.Subtract)
                {
                    Vector3 position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
                    int     count    = int.Parse(jsonArrayValue[i].ToString());

                    for (int u = 0; u < DataContainer.Data.Count; u++)
                    {
                        if (DataContainer.Data[u].position == position)
                        {
                            DataContainer.Data[u].count = DataContainer.Data[u].count - count;

                            u    = DataContainer.Data.Count;
                            done = true;
                        }
                    }
                }
                else if (_combineType == CombineHeatmapType.SubtractZero)
                {
                    done = true;

                    Vector3 position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
                    int     count    = int.Parse(jsonArrayValue[i].ToString());

                    for (int u = 0; u < DataContainer.Data.Count; u++)
                    {
                        if (DataContainer.Data[u].position == position)
                        {
                            DataContainer.Data[u].count = Mathf.Max(DataContainer.Data[u].count - count, 0);

                            if (DataContainer.Data[u].count == 0)
                            {
                                DPsToDelete.Add(DataContainer.Data[u]);
                            }

                            u = DataContainer.Data.Count;
                        }
                    }
                }

                if (_combineType == CombineHeatmapType.Subtract && !done)
                {
                    GA_DataPoint p = new GA_DataPoint();
                    p.position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
                    p.count    = -(int.Parse(jsonArrayValue[i].ToString()));
                    DataContainer.Data.Add(p);
                }
                else if (_combineType != CombineHeatmapType.Subtract && (_combineType == CombineHeatmapType.None || !done))
                {
                    GA_DataPoint p = new GA_DataPoint();
                    p.position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
                    p.count    = int.Parse(jsonArrayValue[i].ToString());
                    DataContainer.Data.Add(p);
                }
            }
            catch (Exception e)
            {
                // JSON format error
                GA.LogError("GameAnalytics: Error in parsing JSON data from server - " + e.Message);
            }
            BuildHeatmapPercentage = (i * 100) / jsonArrayX.Count;
        }
        foreach (GA_DataPoint dp in DPsToDelete)
        {
            DataContainer.Data.Remove(dp);
        }

        BuildingHeatmap        = false;
        BuildHeatmapPercentage = 0;

        NormalizeDataPoints(DataContainer.Data);

        GetComponent <GA_HeatMapRenderer>().OnDataUpdate();
        Loading = false;
    }
	public void OnSuccessDownload(GA_Request.RequestType requestType, Hashtable jsonList, GA_Request.SubmitErrorHandler errorEvent)
	{
		DownloadingData = false;
		BuildingHeatmap = true;
		
		if(DataContainer == null)
		{
			var dataContainerObject = new GameObject("GA_Data");
			dataContainerObject.transform.parent = transform;
			DataContainer = dataContainerObject.AddComponent<GA_HeatmapData>();

			DataContainer.Data = new List<GA_DataPoint>();
			GA.Log(DataContainer);
		}
		else if (_combineType == CombineHeatmapType.None)
			DataContainer.Data.Clear();
		
		List<GA_DataPoint> DPsToDelete = new List<GA_DataPoint>();
		
		ArrayList jsonArrayX = (ArrayList)jsonList["x"];
		ArrayList jsonArrayY = (ArrayList)jsonList["y"];
		ArrayList jsonArrayZ = (ArrayList)jsonList["z"];
		ArrayList jsonArrayValue = (ArrayList)jsonList["value"];
		for (int i = 0; i < jsonArrayX.Count; i++)
		{
			try
			{
				bool done = false;
				if (_combineType == CombineHeatmapType.Add)
				{
					Vector3 position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
					int count = int.Parse(jsonArrayValue[i].ToString());
					
					for (int u = 0; u < DataContainer.Data.Count; u++)
					{
						if (DataContainer.Data[u].position == position)
						{
							DataContainer.Data[u].count += count;
							done = true;
							u = DataContainer.Data.Count;
						}
					}
				}
				else if (_combineType == CombineHeatmapType.Subtract)
				{
					Vector3 position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
					int count = int.Parse(jsonArrayValue[i].ToString());
					
					for (int u = 0; u < DataContainer.Data.Count; u++)
					{
						if (DataContainer.Data[u].position == position)
						{
							DataContainer.Data[u].count = DataContainer.Data[u].count - count;
							
							u = DataContainer.Data.Count;
							done = true;
						}
					}
				}
				else if (_combineType == CombineHeatmapType.SubtractZero)
				{
					done = true;
					
					Vector3 position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
					int count = int.Parse(jsonArrayValue[i].ToString());
					
					for (int u = 0; u < DataContainer.Data.Count; u++)
					{
						if (DataContainer.Data[u].position == position)
						{
							DataContainer.Data[u].count = Mathf.Max(DataContainer.Data[u].count - count, 0);
							
							if (DataContainer.Data[u].count == 0)
								DPsToDelete.Add(DataContainer.Data[u]);
							
							u = DataContainer.Data.Count;
						}
					}
				}
				
				if (_combineType == CombineHeatmapType.Subtract && !done)
				{
					GA_DataPoint p = new GA_DataPoint();
					p.position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
					p.count = -(int.Parse(jsonArrayValue[i].ToString()));
					DataContainer.Data.Add(p);
				}
				else if (_combineType != CombineHeatmapType.Subtract && (_combineType == CombineHeatmapType.None || !done))
				{
					GA_DataPoint p = new GA_DataPoint();
					p.position = new Vector3(float.Parse(jsonArrayX[i].ToString()) / GA.SettingsGA.HeatmapGridSize.x, float.Parse(jsonArrayY[i].ToString()) / GA.SettingsGA.HeatmapGridSize.y, float.Parse(jsonArrayZ[i].ToString()) / GA.SettingsGA.HeatmapGridSize.z);
					p.count = int.Parse(jsonArrayValue[i].ToString());
					DataContainer.Data.Add(p);
				}
			} 
			catch (Exception e)
			{
				// JSON format error
				GA.LogError("GameAnalytics: Error in parsing JSON data from server - " + e.Message);
			}
			BuildHeatmapPercentage = (i * 100) / jsonArrayX.Count;
		}
		foreach (GA_DataPoint dp in DPsToDelete)
		{
			DataContainer.Data.Remove(dp);
		}
		
		BuildingHeatmap = false;
		BuildHeatmapPercentage = 0;
		
		NormalizeDataPoints (DataContainer.Data);
		
		GetComponent<GA_HeatMapRenderer>().OnDataUpdate();
		Loading = false;
	}
	public void OnSuccessDownload(GA_Request.RequestType requestType, JsonData jsonList, GA_Request.SubmitErrorHandler errorEvent)
	{
		if(DataContainer == null) 
		{
			var dataContainerObject = new GameObject("GA_Data");
			dataContainerObject.transform.parent = transform;
			DataContainer = dataContainerObject.AddComponent<GA_HeatmapData>();

			DataContainer.Data = new List<GA_DataPoint>();
			GA.Log(DataContainer);
		}
		else
			DataContainer.Data.Clear();
		
		for (int i = 0; i < jsonList["x"].Count; i++)
		{
			try
			{
				GA_DataPoint p = new GA_DataPoint();
				p.position = new Vector3(float.Parse(jsonList["x"][i].ToString()), float.Parse(jsonList["y"][i].ToString()), float.Parse(jsonList["z"][i].ToString()));
				p.count = int.Parse(jsonList["value"][i].ToString());
				DataContainer.Data.Add(p);
			} 
			catch
			{
				// JSON format error
				GA.LogError("GameAnalytics: Error in parsing JSON data from server");
			}
		}
		
		NormalizeDataPoints (DataContainer.Data);
		
		GetComponent<GA_HeatMapRenderer>().OnDataUpdate();
		Loading = false;
	}