//Instantiation logic and reference assignment private void SpawnStackSlice(IngredientSo data) { var stackPosition = new Vector3( transform.position.x, transform.position.y + _stackedIngredients.Count * sliceHeightOffset, transform.position.z); IngredientSlice spawnedSlice = Instantiate(stackSlicePrefab, stackPosition, Quaternion.Euler(0, 270, 0)) .GetComponent <IngredientSlice>(); spawnedSlice.Initialize(data); Instantiate(particlePrefab, spawnedSlice.transform.position, Quaternion.identity); _stackedIngredients.Push(spawnedSlice); }
private void Initialize() { var temp = Resources.LoadAll <IngredientSo>(INGREDIENT_PATH + specificFolderName); //Offsets the elements to form a grid pattern. int height = 0; for (int i = 0; i < temp.Length; i++) { IngredientSlice slice = Instantiate(ingredientPrefab, parentTransform).GetComponent <IngredientSlice>(); slice.Initialize(temp[i]); int tempWidth = (i % width); slice.transform.localPosition = new Vector3(tempWidth * horizontalPadding, 0, height * verticalPadding); if (tempWidth == width - 1) { height++; } } //Invocation for ingredient response to update. OnInitialized?.Invoke(); }
// makes sure that the bottom bread does not get removed (User Experience) and only the top slice can be removed public bool TryRemoveSlice(IngredientSlice checkAgainst) { return(_stackedIngredients.Count > 1 && _stackedIngredients.Peek() == checkAgainst); }