public void Start()
        {
            var selectableBehaviours = GameObject.FindObjectsOfType <SelectableBehaviour>();

            foreach (var el in selectableBehaviours)
            {
                var selectable = HexDatabase.GetSelectable(el.Cell);
                if (selectable == default)
                {
                    Debug.LogError("Selectable component was in scene but not in the database. Default selectable was assigned in MonoDatabase. Did you forget to rebuild the database?");
                    continue;
                }

                m_SelectableMap[selectable] = el;
            }
        }
Exemple #2
0
        public void Start()
        {
            ObjectMap = new Dictionary <Selectable, T>();

            var behaviours = GameObject.FindObjectsOfType <T>();

            foreach (var el in behaviours)
            {
                var cell       = HexUtility.WorldPointToHex(el.gameObject.transform.position, 1);
                var selectable = HexDatabase.GetSelectable(cell);
                if (selectable == default)
                {
                    Debug.LogError("Selectable component was in scene but not in the database. Default selectable was assigned in BehaviourCollector. Did you forget to rebuild the database?");
                    continue;
                }

                ObjectMap[selectable] = el;
            }
        }
        private void OnPerformSkillCallback(Unit unit, int2 target, SkillType skill)
        {
            if (skill == SkillType.Attack)
            {
                var targetUnit = HexDatabase.GetSelectable(target) as Unit;
                if (targetUnit == null)
                {
                    Debug.LogWarning("targetUnit was null thus cannot be attacked. It should not be possible to initiate attacks on empty cells: " + target);
                }
                else
                {
                    targetUnit.Health -= Math.Abs(unit.Attack - targetUnit.Defense);

                    SkillPerformed?.Invoke(SkillPerformedFinishedFromUI, unit, target, skill);
                    if (SkillPerformed == null)
                    {
                        SkillPerformedFinishedFromUI(unit);
                    }
                }
            }

            TurnManager.EndTurn(unit);
        }