示例#1
0
        public void AddBottleToBeerCase(GameObject emptyBeerBottle)
        {
            Vector3 bottleLocalPosition = BeercaseManager.GetEmptyBottlePositionForBeercase(totalBottles);

            if (bottleLocalPosition == Vector3.zero)
            {
                return;
            }

            emptyBeerBottle.SetActive(true);

            if (emptyBeerBottle.GetComponent <Rigidbody>() != null)
            {
                emptyBeerBottle.GetComponent <Rigidbody>().isKinematic      = true;
                emptyBeerBottle.GetComponent <Rigidbody>().detectCollisions = false;
                emptyBeerBottle.GetComponent <Rigidbody>().useGravity       = false;
                GameObject.Destroy(emptyBeerBottle.GetComponent <Rigidbody>());
            }
            if (emptyBeerBottle.GetComponent <Collider>() != null)
            {
                emptyBeerBottle.GetComponent <Collider>().enabled = false;
                GameObject.Destroy(emptyBeerBottle.GetComponent <Collider>());
            }


            emptyBeerBottle.tag   = "Untagged";
            emptyBeerBottle.layer = LayerMask.NameToLayer("Default");
            emptyBeerBottle.name  = "empty_bottle";

            emptyBeerBottle.transform.parent           = transform;
            emptyBeerBottle.transform.localPosition    = bottleLocalPosition;
            emptyBeerBottle.transform.localEulerAngles = Vector3.zero;

            totalBottles++;
            StartCoroutine(ForceBottlesToStayInBeercase(emptyBeerBottle, gameObject)); // fix for bottle parentness
        }
示例#2
0
        public override void OnLoad() // Called once, when mod is loading after game is fully loaded
        {
            // Create BottleRecyclingManager / Desk Trigger
            GameObject bottleRecyclingTrigger = GameObject.CreatePrimitive(PrimitiveType.Cube);

            bottleRecyclingTrigger.name = "Bottle Recycling Manager";
            bottleRecyclingTrigger.transform.position                  = new Vector3(-1551.096f, 4.712f, 1182.784f);
            bottleRecyclingTrigger.transform.localEulerAngles          = new Vector3(-90, 0, 61.256f);
            bottleRecyclingTrigger.transform.localScale                = new Vector3(0.4274191f, 0.5956179f, 0.1249701f);
            bottleRecyclingTrigger.GetComponent <Collider>().isTrigger = true;
            bottleRecyclingManager = bottleRecyclingTrigger.AddComponent <BottleRecyclingManager>();
            GameObject.Destroy(bottleRecyclingTrigger.GetComponent <MeshRenderer>());
            GameObject.Destroy(bottleRecyclingTrigger.GetComponent <MeshFilter>());

            // Create Receive Money Trigger
            GameObject receiveMoneyTrigger = GameObject.CreatePrimitive(PrimitiveType.Cube);

            receiveMoneyTrigger.name  = "Bottle Receive Money Trigger";
            receiveMoneyTrigger.layer = LayerMask.NameToLayer("DontCollide");
            receiveMoneyTrigger.transform.position                  = new Vector3(-1551.336f, 5.0255f, 1183.061f);
            receiveMoneyTrigger.transform.localEulerAngles          = new Vector3(-90, 0, 57.398f);
            receiveMoneyTrigger.transform.localScale                = new Vector3(0.2007769f, 0.5619151f, 0.8257601f);
            receiveMoneyTrigger.GetComponent <Collider>().isTrigger = true;
            GameObject.Destroy(receiveMoneyTrigger.GetComponent <MeshRenderer>());
            GameObject.Destroy(receiveMoneyTrigger.GetComponent <MeshFilter>());
            bottleRecyclingManager.receiveMoneyTrigger = receiveMoneyTrigger.transform;

            // Create Recycling Prices Note
            if ((bool)useAdditionalStoreGfx.GetValue())
            {
                GameObject bottleDepositsNoteVisual = GameObject.CreatePrimitive(PrimitiveType.Plane);
                GameObject.Destroy(bottleDepositsNoteVisual.GetComponent <Collider>());
                bottleDepositsNoteVisual.transform.position         = new Vector3(-1551.484f, 4.36f, 1182.2f);
                bottleDepositsNoteVisual.transform.localEulerAngles = new Vector3(270, 327.354f, 0);
                bottleDepositsNoteVisual.transform.localScale       = new Vector3(0.023f, 0.02f, 0.032f);
                bottleDepositsNoteVisual.name           = "Bottle Deposits Note Visual";
                bottleRecyclingManager.pricesNoteVisual = bottleDepositsNoteVisual.transform;

                GameObject bottleDepositsNote = GameObject.CreatePrimitive(PrimitiveType.Cube);
                bottleDepositsNote.name  = "Bottle Deposits Note";
                bottleDepositsNote.layer = LayerMask.NameToLayer("DontCollide");
                bottleDepositsNote.transform.position                    = new Vector3(-1551.484f, 4.36f, 1182.2f);
                bottleDepositsNote.transform.localEulerAngles            = new Vector3(0, -32.646f, 0);
                bottleDepositsNote.transform.localScale                  = new Vector3(0.1900704f, 0.2755774f, 0.001717138f);
                bottleDepositsNote.GetComponent <Collider>().isTrigger   = true;
                bottleDepositsNote.GetComponent <MeshRenderer>().enabled = false;
                bottleRecyclingManager.pricesNote = bottleDepositsNote.transform;
            }

            // Create BeercaseManager
            if ((bool)useFilledBeercases.GetValue())
            {
                GameObject _beerCaseManager = GameObject.CreatePrimitive(PrimitiveType.Cube);
                beerCaseManager      = _beerCaseManager.AddComponent <BeercaseManager>();
                beerCaseManager.name = "Beercase Manager";
                beerCaseManager.GetComponent <Collider>().isTrigger = true;
                beerCaseManager.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);
                GameObject.Destroy(beerCaseManager.GetComponent <MeshRenderer>());
                GameObject.Destroy(beerCaseManager.GetComponent <MeshFilter>());
            }

            // Custom Bottles
            if ((bool)useCustomBottles.GetValue())
            {
                string[] customBottles = null;
                try
                {
                    customBottles = System.IO.File.ReadAllLines(System.IO.Path.Combine(ModLoader.GetModConfigFolder(this), "custom_bottles.txt"));
                }
                catch { }

                if (customBottles != null)
                {
                    foreach (string s in customBottles)
                    {
                        if (s.StartsWith("//") || string.IsNullOrEmpty(s)) // ignore comments
                        {
                            continue;
                        }

                        string[] chars = s.Split('=');
                        if (chars.Length > 1)
                        {
                            if (int.TryParse(chars[1], out int _price))
                            {
                                bottleRecyclingManager.customBottles.Add(chars[0]);
                                bottleRecyclingManager.customBottlePrices.Add(_price);
                            }
                        }
                    }
                }
            }

            ab = LoadAssets.LoadBundle(this, "bottlerecyclingbundle"); // load assetbundle
            LoadSaveFile();                                            // load savefile

            // apply bottle deposits note material
            if (bottleRecyclingManager.pricesNote != null)
            {
                Material noteMaterial = ab.LoadAsset("bottleDepositNoteMat") as Material;
                try
                {
                    bottleRecyclingManager.pricesNoteVisual.GetComponent <MeshRenderer>().material = GameObject.Instantiate(noteMaterial) as Material;
                }
                catch { }
            }

            ab.Unload(false); // unload assetbundle
        }