Example #1
0
        public override void OnSave()
        {
            CDSaveData sd = new CDSaveData();

            if (rack10.activeSelf)
            {
                sd.rackpos       = rack10.transform.position;
                sd.rackrotX      = rack10.transform.rotation.eulerAngles.x;
                sd.rackrotY      = rack10.transform.rotation.eulerAngles.y;
                sd.rackrotZ      = rack10.transform.rotation.eulerAngles.z;
                sd.rackpurchased = true;
            }

            foreach (GameObject go in listOfCDs)
            {
                // if (go.activeSelf) //maybe not
                // {
                CDSaveDataList sdl = new CDSaveDataList
                {
                    pos    = go.transform.position,
                    rotX   = go.transform.rotation.eulerAngles.x,
                    rotY   = go.transform.rotation.eulerAngles.y,
                    rotZ   = go.transform.rotation.eulerAngles.z,
                    CDName = go.GetComponent <CD>().CDName,
                    inCase = go.GetComponent <CD>().inCase
                };
                if (go.GetComponent <CD>().inPlayer)
                {
                    sdl.inCase = true;
                }
                sd.cds.Add(sdl);
                //  }
            }
            foreach (GameObject go in listOfCases)
            {
                if (go.activeSelf)
                {
                    CaseSaveDataList sdl = new CaseSaveDataList
                    {
                        pos        = go.transform.position,
                        rotX       = go.transform.rotation.eulerAngles.x,
                        rotY       = go.transform.rotation.eulerAngles.y,
                        rotZ       = go.transform.rotation.eulerAngles.z,
                        CDName     = go.GetComponent <CDCase>().CDName,
                        inRack     = go.GetComponent <CDCase>().inRack,
                        inRackSlot = go.GetComponent <CDCase>().inRackSlot,
                        purchased  = true
                    };

                    sd.cases.Add(sdl);
                }
            }
            SaveLoad.SerializeSaveFile(this, sd, "cdplayer.save");
        }
Example #2
0
        public void Load()
        {
            string old_path  = Path.Combine(ModLoader.GetModConfigFolder(this), "case.save");
            string old_path2 = Path.Combine(ModLoader.GetModConfigFolder(this), "cd.save");

            if (File.Exists(old_path))
            {
                File.Delete(old_path);
            }
            if (File.Exists(old_path2))
            {
                File.Delete(old_path2);
            }

            CDSaveData data = SaveLoad.DeserializeSaveFile <CDSaveData>(this, "cdplayer.save");

            if (data != null)
            {
                if (data.rackpurchased)
                {
                    rack10.transform.position    = data.rackpos;
                    rack10.transform.eulerAngles = new Vector3(data.rackrotX, data.rackrotY, data.rackrotZ);
                    rack10.SetActive(true);
                    rack10.GetComponent <CDRack>().purchased = true;
                }
                for (int i = 0; i < listOfCases.Count; i++)
                {
                    CaseSaveDataList cas = data.cases.Where(x => x.CDName == listOfCases[i].GetComponent <CDCase>().CDName&& x.purchased).FirstOrDefault();
                    if (cas != null)
                    {
                        if (!cas.inRack)
                        {
                            listOfCases[i].transform.position    = cas.pos;
                            listOfCases[i].transform.eulerAngles = new Vector3(cas.rotX, cas.rotY, cas.rotZ);
                        }
                        else
                        {
                            listOfCases[i].GetComponent <Rigidbody>().isKinematic      = true;
                            listOfCases[i].GetComponent <Rigidbody>().detectCollisions = false;
                            listOfCases[i].transform.SetParent(rack10.transform.GetChild(cas.inRackSlot), false);
                            listOfCases[i].transform.localPosition            = Vector3.zero;
                            listOfCases[i].transform.localEulerAngles         = Vector3.zero;
                            listOfCases[i].GetComponent <CDCase>().inRack     = true;
                            listOfCases[i].GetComponent <CDCase>().inRackSlot = cas.inRackSlot;
                            listOfCases[i].name = "cd case (" + (cas.inRackSlot + 1).ToString() + ")(itemy)";
                        }
                        listOfCases[i].GetComponent <CDCase>().purchased = true;
                        listOfCases[i].SetActive(true);
                    }
                }

                for (int i = 0; i < listOfCDs.Count; i++)
                {
                    CDSaveDataList cds = data.cds.Where(x => x.CDName == listOfCDs[i].GetComponent <CD>().CDName).FirstOrDefault();
                    if (cds != null)
                    {
                        if (cds.CDName == listOfCDs[i].GetComponent <CD>().CDName)
                        {
                            if (!cds.inCase)
                            {
                                listOfCDs[i].GetComponent <CD>().inCase = false;
                                LoadAssets.MakeGameObjectPickable(listOfCDs[i]);
                                listOfCDs[i].transform.SetParent(null);
                                listOfCDs[i].transform.position    = cds.pos;
                                listOfCDs[i].transform.eulerAngles = new Vector3(cds.rotX, cds.rotY, cds.rotZ);
                            }
                        }
                    }
                }
            }
        }