public void AddRunningWeightTo(ref HeatmapTile tile, float weight) { tile.RunningWeight += weight; tile.RunningWeightLog10 = Mathf.Log10(1.0f + tile.RunningWeight); if (tile.RunningWeight > MaxRunningWeight) { MaxRunningWeight = tile.RunningWeight; MaxRunningWeightLog10 = tile.RunningWeightLog10; } }
public void AddPositionWeightTo(ref HeatmapTile tile, float weight) { tile.PositionWeight += weight; tile.PositionWeightLog10 = Mathf.Log10(1.0f + tile.PositionWeight); if (tile.PositionWeight > MaxPositionWeight) { MaxPositionWeight = tile.PositionWeight; MaxPositionWeightLog10 = tile.PositionWeightLog10; } }
// Adds position, shooting or running weight to a tile // If the new weight is over the maximum, replaces the maximum for this new one #region AddPositionWeightTo public void AddPositionWeightTo(ref HeatmapTile tile, float weight) { tile.PositionWeight += weight; tile.PositionWeightLog10 = Mathf.Log10(1.0f + tile.PositionWeight); if (tile.PositionWeight > MaxPositionWeight) { MaxPositionWeight = tile.PositionWeight; MaxPositionWeightLog10 = tile.PositionWeightLog10; } }
private float _Timer; // Timer used for the update interval #endregion Fields #region Methods public void DrawTile(int x, int y, HeatmapTile tile) { // Checks if this tile is the tile the playe is standing on, so it makes the color brighter bool playerTile = (x == _PlayerGridX) && (y == _PlayerGridY); // Calculates the center world position of the tile Vector3 origin = new Vector3(_Min.x + (x + 0.5f) * Division.x, _Min.y, _Min.z + (y + 0.5f) * Division.y); // Calculates the minimum weight for position, shooting and running based on the cleanliness level float minPositionWeight = Cleanliness * Data.MaxPositionWeight; float minPositionWeightLog10 = Cleanliness * Data.MaxPositionWeightLog10; float minShootingWeight = Cleanliness * Data.MaxShootingWeight; float minShootingWeightLog10 = Cleanliness * Data.MaxShootingWeightLog10; float minRunningWeight = Cleanliness * Data.MaxRunningWeight; float minRunningWeightLog10 = Cleanliness * Data.MaxRunningWeightLog10; float positionWeight; float positionRatio; float positionCleanRatio; float shootingWeight; float shootingRatio; float shootingCleanRatio; float runningWeight; float runningRatio; float runningCleanRatio; // Calculates the average using the selected scale switch (Scale) { case HeatmapScale.Log10: positionWeight = tile.PositionWeightLog10; positionRatio = positionWeight / Data.MaxPositionWeightLog10; positionCleanRatio = (positionWeight - minPositionWeightLog10) / (Data.MaxPositionWeightLog10 - minPositionWeightLog10); shootingWeight = tile.ShootingWeightLog10; shootingRatio = shootingWeight / Data.MaxShootingWeightLog10; shootingCleanRatio = (shootingWeight - minShootingWeightLog10) / (Data.MaxShootingWeightLog10 - minShootingWeightLog10); runningWeight = tile.RunningWeightLog10; runningRatio = runningWeight / Data.MaxRunningWeightLog10; runningCleanRatio = (runningWeight - minRunningWeightLog10) / (Data.MaxRunningWeightLog10 - minRunningWeightLog10); break; default: positionWeight = tile.PositionWeight; positionRatio = positionWeight / Data.MaxPositionWeight; positionCleanRatio = (positionWeight - minPositionWeight) / (Data.MaxPositionWeight - minPositionWeight); shootingWeight = tile.ShootingWeight; shootingRatio = shootingWeight / Data.MaxShootingWeight; shootingCleanRatio = (shootingWeight - minShootingWeight) / (Data.MaxShootingWeight - minShootingWeight); runningWeight = tile.RunningWeight; runningRatio = runningWeight / Data.MaxRunningWeight; runningCleanRatio = (runningWeight - minRunningWeight) / (Data.MaxRunningWeight - minRunningWeight); break; } float size; // Checks if the user selected to visualize the position, shooting and running weights // If they did, then draws cubes for the position weights if ( ((Visualization & HeatmapVisualization.Position) == HeatmapVisualization.Position) && (positionRatio > 0.0f) && (positionRatio >= Cleanliness) ) { if ((Normalization & HeatmapNormalization.Size) == HeatmapNormalization.Size) size = positionCleanRatio * CubeHeightMultiplier; else size = positionWeight * CubeHeightMultiplier; if ((Normalization & HeatmapNormalization.Color) == HeatmapNormalization.Color) Gizmos.color = HeatmapUtils.GetColor(ColorPoints, positionCleanRatio); else Gizmos.color = HeatmapUtils.GetColor(ColorPoints, positionWeight); if (playerTile) Gizmos.color += new Color(ColorHighlight, ColorHighlight, ColorHighlight, 0.0f); Gizmos.DrawCube( origin + new Vector3(0.0f, 0.5f * size, 0.0f), new Vector3(Division.x, size, Division.y) ); Gizmos.color = new Color( Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 1.0f ); Gizmos.DrawWireCube( origin + new Vector3(0.0f, 0.5f * size, 0.0f), new Vector3(Division.x, size, Division.y) ); } // Spheres for the shooting weights if ( ((Visualization & HeatmapVisualization.Shooting) == HeatmapVisualization.Shooting) && (shootingRatio > 0.0f) && (shootingRatio >= Cleanliness) ) { float height = 0.5f * Mathf.Min(Division.x, Division.y); if ((Normalization & HeatmapNormalization.Size) == HeatmapNormalization.Size) size = shootingCleanRatio * height * SphereRadiusMultiplier; else size = shootingWeight * height * SphereRadiusMultiplier; if ((Normalization & HeatmapNormalization.Color) == HeatmapNormalization.Color) Gizmos.color = HeatmapUtils.GetColor(ColorPoints, shootingCleanRatio); else Gizmos.color = HeatmapUtils.GetColor(ColorPoints, shootingWeight); if (playerTile) Gizmos.color += new Color(ColorHighlight, ColorHighlight, ColorHighlight, 0.0f); Gizmos.DrawSphere( origin + new Vector3(0.0f, size, 0.0f), size ); Gizmos.color = new Color( Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 1.0f ); Gizmos.DrawWireSphere( origin + new Vector3(0.0f, size, 0.0f), size ); } // And circles for the running weights if ( ((Visualization & HeatmapVisualization.Running) == HeatmapVisualization.Running) && (runningRatio > 0.0f) && (runningRatio >= Cleanliness) ) { float height = 0.5f * Mathf.Min(Division.x, Division.y); if ((Normalization & HeatmapNormalization.Size) == HeatmapNormalization.Size) size = runningCleanRatio * height * CircleRadiusMultiplier; else size = runningWeight * height * CircleRadiusMultiplier; // The only way to draw circles on the scene view is by using the Handles class from the UnityEditor namespace // However, the UnityEditor namespace doesn't get compiled when the project is built, so we have to check for the UNITY_EDITOR symbol #if UNITY_EDITOR if ((Normalization & HeatmapNormalization.Color) == HeatmapNormalization.Color) Handles.color = HeatmapUtils.GetColor(ColorPoints, runningCleanRatio); else Handles.color = HeatmapUtils.GetColor(ColorPoints, runningWeight); if (playerTile) Handles.color += new Color(ColorHighlight, ColorHighlight, ColorHighlight, 0.0f); Handles.DrawSolidArc(origin, Vector3.up, Vector3.forward, 360.0f, size); Handles.color = new Color( Handles.color.r, Handles.color.g, Handles.color.b, 1.0f ); Handles.DrawWireArc(origin, Vector3.up, Vector3.forward, 360.0f, size); #endif } }
public void DrawTile(int x, int y, HeatmapTile tile) { // Checks if this tile is the tile the playe is standing on, so it makes the color brighter bool playerTile = (x == _PlayerGridX) && (y == _PlayerGridY); // Calculates the center world position of the tile Vector3 origin = new Vector3(_Min.x + (x + 0.5f) * Division.x, _Min.y, _Min.z + (y + 0.5f) * Division.y); // Calculates the minimum weight for position, shooting and running based on the cleanliness level float minPositionWeight = Cleanliness * Data.MaxPositionWeight; float minPositionWeightLog10 = Cleanliness * Data.MaxPositionWeightLog10; float minShootingWeight = Cleanliness * Data.MaxShootingWeight; float minShootingWeightLog10 = Cleanliness * Data.MaxShootingWeightLog10; float minRunningWeight = Cleanliness * Data.MaxRunningWeight; float minRunningWeightLog10 = Cleanliness * Data.MaxRunningWeightLog10; float positionWeight; float positionRatio; float positionCleanRatio; float shootingWeight; float shootingRatio; float shootingCleanRatio; float runningWeight; float runningRatio; float runningCleanRatio; // Calculates the average using the selected scale switch (Scale) { case HeatmapScale.Log10: positionWeight = tile.PositionWeightLog10; positionRatio = positionWeight / Data.MaxPositionWeightLog10; positionCleanRatio = (positionWeight - minPositionWeightLog10) / (Data.MaxPositionWeightLog10 - minPositionWeightLog10); shootingWeight = tile.ShootingWeightLog10; shootingRatio = shootingWeight / Data.MaxShootingWeightLog10; shootingCleanRatio = (shootingWeight - minShootingWeightLog10) / (Data.MaxShootingWeightLog10 - minShootingWeightLog10); runningWeight = tile.RunningWeightLog10; runningRatio = runningWeight / Data.MaxRunningWeightLog10; runningCleanRatio = (runningWeight - minRunningWeightLog10) / (Data.MaxRunningWeightLog10 - minRunningWeightLog10); break; default: positionWeight = tile.PositionWeight; positionRatio = positionWeight / Data.MaxPositionWeight; positionCleanRatio = (positionWeight - minPositionWeight) / (Data.MaxPositionWeight - minPositionWeight); shootingWeight = tile.ShootingWeight; shootingRatio = shootingWeight / Data.MaxShootingWeight; shootingCleanRatio = (shootingWeight - minShootingWeight) / (Data.MaxShootingWeight - minShootingWeight); runningWeight = tile.RunningWeight; runningRatio = runningWeight / Data.MaxRunningWeight; runningCleanRatio = (runningWeight - minRunningWeight) / (Data.MaxRunningWeight - minRunningWeight); break; } float size; // Checks if the user selected to visualize the position, shooting and running weights // If they did, then draws cubes for the position weights if ( ((Visualization & HeatmapVisualization.Position) == HeatmapVisualization.Position) && (positionRatio > 0.0f) && (positionRatio >= Cleanliness) ) { if ((Normalization & HeatmapNormalization.Size) == HeatmapNormalization.Size) { size = positionCleanRatio * CubeHeightMultiplier; } else { size = positionWeight * CubeHeightMultiplier; } if ((Normalization & HeatmapNormalization.Color) == HeatmapNormalization.Color) { Gizmos.color = HeatmapUtils.GetColor(ColorPoints, positionCleanRatio); } else { Gizmos.color = HeatmapUtils.GetColor(ColorPoints, positionWeight); } if (playerTile) { Gizmos.color += new Color(ColorHighlight, ColorHighlight, ColorHighlight, 0.0f); } Gizmos.DrawCube( origin + new Vector3(0.0f, 0.5f * size, 0.0f), new Vector3(Division.x, size, Division.y) ); Gizmos.color = new Color( Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 1.0f ); Gizmos.DrawWireCube( origin + new Vector3(0.0f, 0.5f * size, 0.0f), new Vector3(Division.x, size, Division.y) ); } // Spheres for the shooting weights if ( ((Visualization & HeatmapVisualization.Shooting) == HeatmapVisualization.Shooting) && (shootingRatio > 0.0f) && (shootingRatio >= Cleanliness) ) { float height = 0.5f * Mathf.Min(Division.x, Division.y); if ((Normalization & HeatmapNormalization.Size) == HeatmapNormalization.Size) { size = shootingCleanRatio * height * SphereRadiusMultiplier; } else { size = shootingWeight * height * SphereRadiusMultiplier; } if ((Normalization & HeatmapNormalization.Color) == HeatmapNormalization.Color) { Gizmos.color = HeatmapUtils.GetColor(ColorPoints, shootingCleanRatio); } else { Gizmos.color = HeatmapUtils.GetColor(ColorPoints, shootingWeight); } if (playerTile) { Gizmos.color += new Color(ColorHighlight, ColorHighlight, ColorHighlight, 0.0f); } Gizmos.DrawSphere( origin + new Vector3(0.0f, size, 0.0f), size ); Gizmos.color = new Color( Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 1.0f ); Gizmos.DrawWireSphere( origin + new Vector3(0.0f, size, 0.0f), size ); } // And circles for the running weights if ( ((Visualization & HeatmapVisualization.Running) == HeatmapVisualization.Running) && (runningRatio > 0.0f) && (runningRatio >= Cleanliness) ) { float height = 0.5f * Mathf.Min(Division.x, Division.y); if ((Normalization & HeatmapNormalization.Size) == HeatmapNormalization.Size) { size = runningCleanRatio * height * CircleRadiusMultiplier; } else { size = runningWeight * height * CircleRadiusMultiplier; } // The only way to draw circles on the scene view is by using the Handles class from the UnityEditor namespace // However, the UnityEditor namespace doesn't get compiled when the project is built, so we have to check for the UNITY_EDITOR symbol #if UNITY_EDITOR if ((Normalization & HeatmapNormalization.Color) == HeatmapNormalization.Color) { Handles.color = HeatmapUtils.GetColor(ColorPoints, runningCleanRatio); } else { Handles.color = HeatmapUtils.GetColor(ColorPoints, runningWeight); } if (playerTile) { Handles.color += new Color(ColorHighlight, ColorHighlight, ColorHighlight, 0.0f); } Handles.DrawSolidArc(origin, Vector3.up, Vector3.forward, 360.0f, size); Handles.color = new Color( Handles.color.r, Handles.color.g, Handles.color.b, 1.0f ); Handles.DrawWireArc(origin, Vector3.up, Vector3.forward, 360.0f, size); #endif } }