/// <summary> /// Generate new item /// </summary> /// <returns>The item.</returns> /// <param name="falling">If set to <c>true</c> prepare for falling animation.</param> public Item GenItem(bool falling = true, ItemsTypes itemType = ItemsTypes.NONE, int color = -1) { if (IsNone() && !CanGoInto()) { return(null); } GameObject item = null; if (itemType == ItemsTypes.NONE) { if (LevelManager.THIS.collectIngredients && !IsObstacle()) { item = GetIngredientItem(); } if (!item) { item = ObjectPooler.Instance.GetPooledObject("Item"); } } else { item = ObjectPooler.Instance.GetPooledObject(itemType.ToString()); item?.GetComponent <Item>().anim?.SetTrigger("bonus_appear"); } if (item == null) { Debug.LogError("there is no " + itemType + " in pool "); } item.transform.localScale = Vector2.one * 0.42f; Item itemComponent = item.GetComponent <Item>(); itemComponent.square = this; // item.GetComponent<IColorableComponent>().RandomizeColor(); IColorableComponent colorableComponent = item.GetComponent <IColorableComponent>(); if (color == -1) { itemComponent.GenColor(); } else if (colorableComponent != null) { colorableComponent.SetColor(color); } itemComponent.field = field; itemComponent.needFall = falling; if (!falling) { item.transform.position = (Vector3)((Vector2)transform.position) + Vector3.back * 0.2f; } if (LevelManager.THIS.gameStatus != GameState.Playing && LevelManager.THIS.gameStatus != GameState.Tutorial) { Item = itemComponent; } else if (!IsHaveFallingItemsAbove()) { Item = itemComponent; } // this.item.falling = falling; if (falling) { Vector3 startPos = GetReverseDirection(); item.transform.position = transform.position + startPos * field.squareHeight + Vector3.back * 0.2f; itemComponent.JustCreatedItem = true; } if (LevelManager.THIS.DebugSettings.DestroyLog) { DebugLogKeeper.Log(name + " gen item " + item.name + " pos " + item.transform.position, DebugLogKeeper.LogType.Destroying); } itemComponent.needFall = falling; // if ((!nextSquare?.IsFree() ?? false) || Item == itemComponent) itemComponent.StartFallingTo(itemComponent.GenerateWaypoints(this)); // itemComponent.StartFalling(); return(itemComponent); }