private void SelectBestTarget(Unit nextTarget)
            {
                switch (options.Distance)
                {
                case TargetingDistance.Any:
                    int unitPreviousIndex = previousTargets.IndexOf(nextTarget);
                    if (BestTarget == null || unitPreviousIndex < bestTargetPrevousIndex)
                    {
                        BestTarget             = nextTarget;
                        bestTargetPrevousIndex = unitPreviousIndex;
                    }
                    break;

                case TargetingDistance.Near:
                    float nextTargetNearDistance = referer.ExactDistanceTo(nextTarget);
                    if (BestTarget == null || nextTargetNearDistance < bestTargetDistance)
                    {
                        BestTarget         = nextTarget;
                        bestTargetDistance = nextTargetNearDistance;
                    }
                    break;

                case TargetingDistance.Far:
                    float nextTargetFarDistance = referer.ExactDistanceTo(nextTarget);
                    if (BestTarget == null || nextTargetFarDistance > bestTargetDistance)
                    {
                        BestTarget         = nextTarget;
                        bestTargetDistance = nextTargetFarDistance;
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(options.Distance));
                }
            }
Example #2
0
        private void OnFactionChanged()
        {
            Player referer = renderReference.Player;
            Unit   target  = UnitRenderer.Unit;

            if (referer == target)
            {
                HostilitySettings = nameplateSettings.Self;
            }
            else if (referer.IsHostileTo(target))
            {
                HostilitySettings = nameplateSettings.Enemy;
            }
            else if (referer.IsFriendlyTo(target))
            {
                HostilitySettings = nameplateSettings.Friendly;
            }
            else
            {
                HostilitySettings = nameplateSettings.Neutral;
            }

            unitName.gameObject.SetActive(HostilitySettings.ShowName);
            healthFrame.HealthBar.FillImage.color = HostilitySettings.HealthColor;
            unitName.color = HostilitySettings.NameWithoutPlateColor;

            InDetailRange = referer.ExactDistanceTo(target) < nameplateSettings.DetailedDistance;

            UpdateSelection(true);

            ApplyScaling();
        }