コード例 #1
0
ファイル: StirDish.cs プロジェクト: Jelled1st/Project_ShowOff
    private bool TryAddIngredientCheck(IIngredient ingredient)
    {
        if (_mustStir && !_currentRequiredStir.HasIngredientType(ingredient.GetIngredientType()))
        {
            return(false);
        }
        if (_debugLog)
        {
            Debug.Log("Trying to add");
        }
        var type = ingredient.GetIngredientType();

        if (_finishIngredient != IngredientType.Undefined && type == _finishIngredient)
        {
            if (IsFinished(false))
            {
                if (_debugLog)
                {
                    Debug.Log("Finish ingredient");
                }
                //required ingredient
                AddFinalIngredientMesh(type, ingredient.GetDishMesh(), ingredient.GetHeight());
                InformObserversAddIngredient(ingredient);
                _finishIngredientPlaced = true;
                InformObserversFinish();
                return(true);
            }
        }

        if (_finishIngredientPlaced)
        {
            return(false);
        }
        for (var i = 0; i < _requiredIngredients.Count; ++i)
        {
            if (type == _requiredIngredients[i])
            {
                if (_debugLog)
                {
                    Debug.Log("Required ingredient");
                }
                //required ingredient
                AddIngredientMesh(type, ingredient.GetDishMesh(), ingredient.GetHeight(), true, i);
                _requiredIngredients.RemoveAt(i); //remove ingredient from the list
                InformObserversAddIngredient(ingredient);
                return(true);
            }
        }

        for (var i = 0; i < _optionalIngredients.Count; ++i)
        {
            if (type == _optionalIngredients[i])
            {
                if (_debugLog)
                {
                    Debug.Log("Optional ingredient");
                }
                //required ingredient
                AddIngredientMesh(type, ingredient.GetDishMesh(), ingredient.GetHeight(), false, i);
                _optionalIngredients.RemoveAt(i); //remove ingredient from the list
                InformObserversAddIngredient(ingredient);
                return(true);
            }
        }

        if (_debugLog)
        {
            Debug.Log("Could not be added");
        }
        return(false);
    }