コード例 #1
0
        public bool Remove(RosemaryUnit item)
        {
            bool r = m_units.Remove(item);

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

            m_units.Add(item);
            item.OnSelected(this);
            return(true);
        }
コード例 #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));
            }
        }
コード例 #4
0
 private void InflictDamage(RosemaryUnit unit)
 {
     unit.InflictDamage(this);
 }
コード例 #5
0
 public override bool CanAttackUnit(RosemaryUnit other)
 {
     return(IsEnemyAndInViewRange(other) &&
            other.useResourceReward &&
            resourceNames.Contains(other.resourceReward.resourceName));
 }
コード例 #6
0
 protected virtual bool IsUnitMultiSelectable(RosemaryUnit unit)
 {
     return(unit.faction == selection.faction);
 }
コード例 #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;
            }
        }
コード例 #8
0
 private void Awake()
 {
     unit = GetComponentInParent <RosemaryUnit>();
     lr   = GetComponent <LineRenderer>();
 }
コード例 #9
0
 public bool Contains(RosemaryUnit item)
 {
     return(m_units.Contains(item));
 }