Example #1
0
        void PutBottleToBeercase(GameObject bottle, GameObject beercase)
        {
            if (bottle == null || beercase == null)
            {
                BottleRecycling.DebugPrint("BeercaseManager: Error when trying to put empty bottle to empty beercase.");
                return;
            }

            // Add BeercaseFilled -component
            if (beercase.GetComponent <BeercaseFilled>() == null)
            {
                beercase.AddComponent <BeercaseFilled>();
            }
            try
            {
                Destroy(beercase.GetComponent <PlayMakerFSM>()); // Remove PlayMakerFSM from Beercase
            }
            catch { }

            BeercaseFilled beercaseFilled = beercase.GetComponent <BeercaseFilled>();

            // Only 24 bottles fits to beercase (duh)
            if (beercaseFilled.totalBottles >= 24)
            {
                return;
            }

            beercaseFilled.AddBottleToBeerCase(bottle);             // Add Empty Bottle to Beercase
            PlaySound(bottle_empty_2, beercase.transform.position); // Play Sound
        }
Example #2
0
        IEnumerator SpawnSavedFilledBeercases(SaveData saveData)
        {
            yield return(new WaitForEndOfFrame()); // wait one frame for apparently no reason

            // Create Empty Beercase prefab
            filledBeercasePrefab = GetEmptyBeercase();
            filledBeercasePrefab.SetActive(true);
            if (filledBeercasePrefab.GetComponent <PlayMakerFSM>())
            {
                GameObject.Destroy(filledBeercasePrefab.GetComponent <PlayMakerFSM>()); // Destroy FSM Component from clone.
            }
            yield return(new WaitForEndOfFrame());                                      // wait one frame after destroying fsm

            // Destroy all existing child bottles from Beercase prefab.
            foreach (Transform child in filledBeercasePrefab.GetComponentsInChildren <Transform>())
            {
                if (child != filledBeercasePrefab.transform)
                {
                    GameObject.Destroy(child.gameObject);
                }
            }

            yield return(new WaitForEndOfFrame()); // wait one frame before creating empty bottles to case.

            if (saveData.filledBeercases.Count > 0)
            {
                foreach (SaveDataFilledBeercase filledBeercase in saveData.filledBeercases)
                {
                    // Create new Beercase
                    GameObject newCase = GameObject.Instantiate(filledBeercasePrefab) as GameObject;
                    newCase.transform.position    = filledBeercase.Position;
                    newCase.transform.eulerAngles = new Vector3(filledBeercase.RotX, filledBeercase.RotY, filledBeercase.RotZ);
                    newCase.name = "empty(itemx)";

                    // Make Beercase Fillable
                    BeercaseFilled filled = newCase.AddComponent <BeercaseFilled>();
                    // Add Empty Bottles GameObjects to New Beercase
                    for (int i = 0; i < filledBeercase.bottleAmount; i++)
                    {
                        filled.AddBottleToBeerCase(GameObject.Instantiate(emptyBottlePrefab) as GameObject);
                    }
                }
            }

            // Empty Beercase prefab is not needed anymore; destroy it.
            GameObject.Destroy(filledBeercasePrefab);

            yield return(null);
        }