private void ShowDotAt(Vector3 location, Color color, HexFactorData factorData)
        {
            GameObject dot;

            if (_unusedDotPool.Count > 0)
            {
                dot = _unusedDotPool[0];
                _unusedDotPool.RemoveAt(0);
            }
            else
            {
                dot = GenerateDot($"dot_{_unusedDotPool.Count + _usedDotPool.Count}");
            }

            _usedDotPool.Add(dot);
            dot.transform.position = location + _groundOffset;
            dot.transform.rotation = Quaternion.Euler(90f, 0f, 0f);

            var tooltip = dot.GetComponent <DotTooltip>();

            tooltip.FactorData = factorData;

            var renderer = dot.GetComponent <MeshRenderer>();

            renderer.material.color = color;

            dot.SetActive(true);
        }
 public void OnMouseDown()
 {
     if (CompareAgainst == FactorData)
     {
         CompareAgainst = null;
     }
     else
     {
         CompareAgainst = FactorData;
     }
 }
        public void OnInfluenceMapSort(AbstractActor unit)
        {
            Hide();

            var map = unit.BehaviorTree.influenceMapEvaluator;

            var lowest           = float.MaxValue;
            var highest          = float.MinValue;
            var total            = 0f;
            var hexToHighestData = new Dictionary <MapTerrainDataCell, HexFactorData>();

            for (var i = 0; i < map.firstFreeWorkspaceEvaluationEntryIndex; i++)
            {
                var entry = map.WorkspaceEvaluationEntries[i];
                var hex   = unit.Combat.MapMetaData.GetCellAt(entry.Position);
                var value = entry.GetHighestAccumulator();

                highest = Mathf.Max(highest, value);
                lowest  = Mathf.Min(lowest, value);
                total  += value;

                if (hexToHighestData.ContainsKey(hex) && hexToHighestData[hex].Value > value)
                {
                    continue;
                }

                var data = new HexFactorData
                {
                    FactorRecords = entry.ValuesByFactorName,
                    MoveType      = entry.GetBestMoveType(),
                    Position      = entry.Position,
                    Value         = value
                };

                hexToHighestData[hex] = data;
            }

            var average = total / map.firstFreeWorkspaceEvaluationEntryIndex;

            foreach (var hexData in hexToHighestData.Values)
            {
                var darkGrey = new Color(.15f, .15f, .15f);
                var color    = hexData.Value <= average
                    ? Color.Lerp(Color.red, darkGrey, (hexData.Value - lowest) / (average - lowest))
                    : Color.Lerp(darkGrey, Color.cyan, (hexData.Value - average) / (highest - average));

                ShowDotAt(hexData.Position, color, hexData);
            }
        }