// Set up and create the gameobject for a telemetry event public void CreateTelemetryObject(int index, TelemetryEvent data, Color color, PrimitiveType shape) { TelemetryEventGameObject tempTelemetryObject = new TelemetryEventGameObject(); tempTelemetryObject.SetEvent(data, color, shape, index); gameObjectCollection.Add(tempTelemetryObject); tempTelemetryObject.GameObject.transform.SetParent(host.transform); UnityEngine.Object.DestroyImmediate(tempTelemetryObject.GameObject.GetComponent <Collider>()); }
// Set up and create the gameobject for a heatmap component public void CreateHeatmapObject(TelemetryEventGameObject inEvent) { gameObjectCollection.Add(inEvent); inEvent.GameObject.transform.SetParent(host.transform); UnityEngine.Object.DestroyImmediate(inEvent.GameObject.GetComponent <Collider>()); }
public void GenerateHeatmap(EventEditorContainer collection, float heatmapSize, HeatmapColors heatmapColor, int heatmapType, int heatmapShape, bool useOrientation, int first, int last, string subEvent) { DestroyTelemetryObjects(); if (collection.events.Count != 0 && !(subEvent == "" && (heatmapType == (int)Globals.HeatmapType.Value || heatmapType == (int)Globals.HeatmapType.Value_Bar))) { if ((first == 0 && first == last) || (first == collection.events.Count - 1 && first == last)) { first = 0; last = collection.events.Count - 1; } //Segment the world in to blocks of the specified size encompassing all points Vector3 origin = collection.GetPointRange(first, last).center; //For each segment, collect all of the points inside and decide what data to watch based on the heatmap type float scaledHeatmapSize = heatmapSize / 100; Vector3 tempPoint; Dictionary <Vector3, HeatmapNode> heatmapNodes = new Dictionary <Vector3, HeatmapNode>(); //For each segment, collect all of the points inside and decide what data to watch based on the heatmap type TelemetryEventGameObject tempTelemetryObject; if ((HeatmapValueMin == -1 && HeatmapValueMax == -1) || HeatmapValueMin == HeatmapValueMax) { double largestValue = 0; double smallestValue = 0; int largestNumValue = 0; if (useOrientation) { for (int j = first; j <= last; j++) { tempPoint = (collection.events[j].Point - origin) / heatmapSize; tempPoint.x = (float)Math.Floor(tempPoint.x); tempPoint.y = (float)Math.Floor(tempPoint.y); tempPoint.z = (float)Math.Floor(tempPoint.z); HeatmapNode tempNode; if (heatmapNodes.ContainsKey(tempPoint)) { heatmapNodes[tempPoint].numValues++; heatmapNodes[tempPoint].values += collection.events[j].GetValue(subEvent); heatmapNodes[tempPoint].orientation += collection.events[j].Orientation; tempNode = heatmapNodes[tempPoint]; } else { tempNode = new HeatmapNode(1, collection.events[j].GetValue(subEvent), collection.events[j].Orientation); heatmapNodes.Add(tempPoint, tempNode); } smallestValue = Math.Min(smallestValue, tempNode.values / tempNode.numValues); largestValue = Math.Max(largestValue, tempNode.values / tempNode.numValues); largestNumValue = Math.Max(largestNumValue, tempNode.numValues); } foreach (var node in heatmapNodes) { node.Value.orientation = node.Value.orientation / node.Value.numValues; } } else { for (int j = first; j <= last; j++) { tempPoint = (collection.events[j].Point - origin) / heatmapSize; tempPoint.x = (float)Math.Floor(tempPoint.x); tempPoint.y = (float)Math.Floor(tempPoint.y); tempPoint.z = (float)Math.Floor(tempPoint.z); HeatmapNode tempNode; if (heatmapNodes.ContainsKey(tempPoint)) { heatmapNodes[tempPoint].numValues++; heatmapNodes[tempPoint].values += collection.events[j].GetValue(subEvent); tempNode = heatmapNodes[tempPoint]; } else { tempNode = new HeatmapNode(1, collection.events[j].GetValue(subEvent)); heatmapNodes.Add(tempPoint, tempNode); } smallestValue = Math.Min(smallestValue, tempNode.values / tempNode.numValues); largestValue = Math.Max(largestValue, tempNode.values / tempNode.numValues); largestNumValue = Math.Max(largestNumValue, tempNode.numValues); } } HeatmapValueMin = 0; if (heatmapType == (int)Globals.HeatmapType.Value || heatmapType == (int)Globals.HeatmapType.Value_Bar) { if (subEvent.StartsWith("pct_")) { HeatmapValueMin = 0; HeatmapValueMax = 100; } else { HeatmapValueMin = smallestValue; HeatmapValueMax = largestValue; } } else { HeatmapValueMax = largestNumValue; } } else { if (useOrientation) { for (int j = first; j <= last; j++) { tempPoint = (collection.events[j].Point - origin) / heatmapSize; tempPoint.x = (float)Math.Floor(tempPoint.x); tempPoint.y = (float)Math.Floor(tempPoint.y); tempPoint.z = (float)Math.Floor(tempPoint.z); HeatmapNode tempNode; if (heatmapNodes.ContainsKey(tempPoint)) { heatmapNodes[tempPoint].numValues++; heatmapNodes[tempPoint].values += collection.events[j].GetValue(subEvent); heatmapNodes[tempPoint].orientation += collection.events[j].Orientation; tempNode = heatmapNodes[tempPoint]; } else { tempNode = new HeatmapNode(1, collection.events[j].GetValue(subEvent), collection.events[j].Orientation); heatmapNodes.Add(tempPoint, tempNode); } } foreach (var node in heatmapNodes) { node.Value.orientation = node.Value.orientation / node.Value.numValues; } } else { for (int j = first; j <= last; j++) { tempPoint = (collection.events[j].Point - origin) / heatmapSize; tempPoint.x = (float)Math.Floor(tempPoint.x); tempPoint.y = (float)Math.Floor(tempPoint.y); tempPoint.z = (float)Math.Floor(tempPoint.z); HeatmapNode tempNode; if (heatmapNodes.ContainsKey(tempPoint)) { heatmapNodes[tempPoint].numValues++; heatmapNodes[tempPoint].values += collection.events[j].GetValue(subEvent); tempNode = heatmapNodes[tempPoint]; } else { tempNode = new HeatmapNode(1, collection.events[j].GetValue(subEvent)); heatmapNodes.Add(tempPoint, tempNode); } } } } if (heatmapNodes.Count > 0) { double tempValue; float tempColorValue; int i = 0; if (heatmapType == (int)Globals.HeatmapType.Value) { foreach (var node in heatmapNodes) { tempValue = node.Value.values / node.Value.numValues; tempColorValue = (float)((tempValue - HeatmapValueMin) / (HeatmapValueMax - HeatmapValueMin)); tempColorValue = Mathf.Clamp(tempColorValue, 0, 1); tempTelemetryObject = new TelemetryEventGameObject(); tempTelemetryObject.SetHeatmapEvent(i, (node.Key * heatmapSize) + origin, node.Value.orientation, heatmapColor.GetColorFromRange(tempColorValue), (PrimitiveType)heatmapShape, heatmapSize, tempValue); CreateHeatmapObject(tempTelemetryObject); i++; } } else if (heatmapType == (int)Globals.HeatmapType.Population) { foreach (var node in heatmapNodes) { tempValue = node.Value.numValues / HeatmapValueMax; tempColorValue = (float)((node.Value.numValues - HeatmapValueMin) / (HeatmapValueMax - HeatmapValueMin)); tempColorValue = Mathf.Clamp(tempColorValue, 0, 1); tempTelemetryObject = new TelemetryEventGameObject(); tempTelemetryObject.SetHeatmapEvent(i, (node.Key * heatmapSize) + origin, node.Value.orientation, heatmapColor.GetColorFromRange(tempColorValue), (PrimitiveType)heatmapShape, heatmapSize, tempValue); CreateHeatmapObject(tempTelemetryObject); i++; } } else if (heatmapType == (int)Globals.HeatmapType.Value_Bar) { float tempHeight; foreach (var node in heatmapNodes) { tempValue = node.Value.values / node.Value.numValues; tempColorValue = (float)((tempValue - HeatmapValueMin) / (HeatmapValueMax - HeatmapValueMin)); tempColorValue = Mathf.Clamp(tempColorValue, 0, 1); tempHeight = (float)(tempValue / HeatmapValueMax) * heatmapSize; tempTelemetryObject = new TelemetryEventGameObject(); tempTelemetryObject.SetHeatmapEvent(i, (node.Key * heatmapSize) + origin, Vector3.zero, heatmapColor.GetColorFromRange(tempColorValue), (PrimitiveType)heatmapShape, new Vector3(heatmapSize, heatmapSize, tempHeight), tempValue); CreateHeatmapObject(tempTelemetryObject); i++; } } else if (heatmapType == (int)Globals.HeatmapType.Population_Bar) { float tempHeight; foreach (var node in heatmapNodes) { tempValue = node.Value.numValues / HeatmapValueMax; tempColorValue = (float)((node.Value.numValues - HeatmapValueMin) / (HeatmapValueMax - HeatmapValueMin)); tempColorValue = Mathf.Clamp(tempColorValue, 0, 1); tempHeight = (float)tempValue * heatmapSize; tempTelemetryObject = new TelemetryEventGameObject(); tempTelemetryObject.SetHeatmapEvent(i, (node.Key * heatmapSize) + origin, Vector3.zero, heatmapColor.GetColorFromRange(tempColorValue), (PrimitiveType)heatmapShape, new Vector3(heatmapSize, heatmapSize, tempHeight), tempValue); CreateHeatmapObject(tempTelemetryObject); i++; } } } } }