/// <summary>
    /// Updates combat unit manager.
    /// </summary>
    void UpdateCombatUnitManager()
    {
        CombatUnitManagerMetaData data = CombatUnitManagerMetaData.Load(true);

        maxCombatUnit      = data.maxCombatUnit;
        currentCombatUnit  = data.CurrentCombatUnit;
        _unitTypeAndNumber = data.GetAllUnit();

        if ((data.producingUnit) && (_task == null))
        {
            _task = ProduceUnitTask.CreateTask(data.producingUnitType, data.producingAmount, OnProducingUnitComplete, OnTimeLeftToComplete, data.producingDuration);

            TaskManager.Instance.AddTask(_task);
        }
        else
        {
            _task = null;
        }
    }
    /// <summary>
    /// Produces combat unit.
    /// </summary>
    /// <returns><c>true</c>, if combat unit was produced, <c>false</c> otherwise.</returns>
    /// <param name="unitType">Unit type.</param>
    /// <param name="produceAmount">Produce amount.</param>
    public bool ProduceCombatUnit(CombatUnitType unitType, int produceAmount)
    {
        if ((combatUnitInfo != null) && (_task == null))
        {
            CombatUnitManagerMetaData data = CombatUnitManagerMetaData.Load();

            CombatUnit unitInfo = null;

            for (int i = 0; i < combatUnitInfo.Count; i++)
            {
                if (unitType == combatUnitInfo[i].unitType)
                {
                    unitInfo = combatUnitInfo[i];

                    break;
                }
            }

            if (unitInfo != null)
            {
                //todo:check if resource is enough
                bool canProduceUnit = true;

                for (int i = 0; i < unitInfo.costResourceTypes.Count; i++)
                {
                    if (!Player.Instance.IsResourceEnough(unitInfo.costResourceTypes[i], unitInfo.costResources[i] * produceAmount))
                    {
                        EventManager.GetInstance().ExecuteEvent <EventAlert>(new EventAlert("Warning", "Not enough resources"));

                        canProduceUnit = false;

                        break;
                    }
                }

                if (canProduceUnit)
                {
                    Dictionary <ResourceType, float> resourceCost = new Dictionary <ResourceType, float>();

                    for (int i = 0; i < unitInfo.costResourceTypes.Count; i++)
                    {
                        resourceCost.Add(unitInfo.costResourceTypes[i], unitInfo.costResources[i]);
                    }

                    if (data.ProduceCombatUnit(unitInfo.unitType, produceAmount, unitInfo.generateDuration * produceAmount, resourceCost))
                    {
                        _task = ProduceUnitTask.CreateTask(unitInfo.unitType, produceAmount, OnProducingUnitComplete, OnTimeLeftToComplete, unitInfo.generateDuration * produceAmount);

                        TaskManager.Instance.AddTask(_task);

                        //todo:post produce unit event
                        List <ResourceType> costType = new List <ResourceType>();
                        foreach (ResourceType type in resourceCost.Keys)
                        {
                            costType.Add(type);
                        }

                        Architecture archi = GetComponent <Architecture> ();

                        if (archi.isSelected)
                        {
                            UIArchitectureMenuController.Instance.GetMenu(transform, ArchitectureMenuType.OnTask);
                        }

                        EventManager.GetInstance().ExecuteEvent <EventProduceCombatUnit>(new EventProduceCombatUnit(costType));

                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                Debug.LogError(gameObject.name + " unable to produce combat unit, no unit definition");
            }
        }

        return(false);
    }