Example #1
0
        //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);
        }
Example #2
0
        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();
        }