Beispiel #1
0
        public bool Remove(RosemaryUnit item)
        {
            bool r = m_units.Remove(item);

            if (r && item)
            {
                item.OnDeselected();
            }
            return(r);
        }
Beispiel #2
0
        public bool Add(RosemaryUnit item)
        {
            if (m_units.Contains(item))
            {
                return(false);
            }

            m_units.Add(item);
            item.OnSelected(this);
            return(true);
        }
Beispiel #3
0
        public void CommandAttack(RosemaryUnit other)
        {
            var units = controllableUnits;

            foreach (var unit in units)
            {
                unit.CommandAttack(other);
            }

            if (units.Any())
            {
                attackCommandEffectSpawner.Spawn(
                    other.centre, Quaternion.identity,
                    TargetPoint.Transform(other.centreTransform));
            }
        }
Beispiel #4
0
 private void InflictDamage(RosemaryUnit unit)
 {
     unit.InflictDamage(this);
 }
Beispiel #5
0
 public override bool CanAttackUnit(RosemaryUnit other)
 {
     return(IsEnemyAndInViewRange(other) &&
            other.useResourceReward &&
            resourceNames.Contains(other.resourceReward.resourceName));
 }
Beispiel #6
0
 protected virtual bool IsUnitMultiSelectable(RosemaryUnit unit)
 {
     return(unit.faction == selection.faction);
 }
Beispiel #7
0
        public void OnPointerUp(PointerEventData eventData)
        {
            var camera = this.cam;

            switch (eventData.button)
            {
            case PointerEventData.InputButton.Left:
            {
                try
                {
                    if (isBoxSelecting)
                    {
                        // Complete Box Selection.
                        var units = GetUnitsInScreenRect(camera, boxSelectRect)
                                    .Where(IsUnitMultiSelectable);
                        if (isMultiSelecting)
                        {
                            if (units.All(unit => selection.Contains(unit)))
                            {
                                foreach (var unit in units)
                                {
                                    selection.Remove(unit);
                                }
                            }
                            else
                            {
                                foreach (var unit in units)
                                {
                                    selection.Add(unit);
                                }
                            }
                        }
                        else
                        {
                            selection.Clear();
                            foreach (var unit in units)
                            {
                                selection.Add(unit);
                            }
                        }
                    }
                    else
                    {
                        // Just a click.
                        // Complete Single Selection.
                        RosemaryUnit unit = null;
                        if (Physics.Raycast(
                                camera.ScreenPointToRay(eventData.position),
                                out RaycastHit hit,
                                Mathf.Infinity,
                                unitLayerMask,
                                QueryTriggerInteraction.Collide))
                        {
                            unit = hit.collider.GetComponentInParent <RosemaryUnit>();
                        }
                        if (unit)
                        {
                            if (isMultiSelecting)
                            {
                                selection.RemoveAll(u => !IsUnitMultiSelectable(u));
                                if (IsUnitMultiSelectable(unit))
                                {
                                    // if contains then remove else add.
                                    if (!selection.Remove(unit))
                                    {
                                        selection.Add(unit);
                                    }
                                }
                                // else do not modify selection.
                            }
                            else
                            {
                                selection.Clear();
                                selection.Add(unit);
                            }
                        }
                        else
                        {
                            if (!isMultiSelecting)
                            {
                                selection.Clear();
                            }
                        }
                    }
                }
                finally
                {
                    isPointerDown  = false;
                    isBoxSelecting = false;
                }
            }
            break;

            case PointerEventData.InputButton.Right:
            {
                if (Physics.Raycast(
                        camera.ScreenPointToRay(eventData.position),
                        out RaycastHit hit,
                        Mathf.Infinity,
                        terrainLayerMask | unitLayerMask,
                        QueryTriggerInteraction.Ignore))
                {
                    var unit = hit.collider.GetComponentInParent <RosemaryUnit>();
                    if (unit)
                    {
                        if (unit.faction.IsAlly(selection.faction))
                        {
                            selection.CommandFollow(unit);
                        }
                        else
                        {
                            selection.CommandAttack(unit);
                        }
                    }
                    else
                    {
                        selection.CommandMove(hit.point, effectPoint: hit.point + hit.normal * 0.5f);
                    }
                }
            }
            break;
            }
        }
Beispiel #8
0
 private void Awake()
 {
     unit = GetComponentInParent <RosemaryUnit>();
     lr   = GetComponent <LineRenderer>();
 }
Beispiel #9
0
 public bool Contains(RosemaryUnit item)
 {
     return(m_units.Contains(item));
 }