Esempio n. 1
0
        void Start()
        {
            Application.targetFrameRate = 60;

            if (ClearProgress)
            {
                ProgressManager.DeleteProgress();
            }

            BaseObjectFactory.SetVariants();
            PlayerModel = new Player();
            PlayerModel.Init(this);
            ProgressManager.LoadProgress(this);

            Player.Init(this);
            IapManager.Init(this);

            SpawnZonesAgragator.Init(this);
            Fauna.Init(this);

            StartCoroutine(AutoSave());

            Pathfinder.Scan();

#if FACEBOOK
            FbManager.Init();
#endif
#if UNITY_IOS
            GameCenterManager.Authenticate();
#endif
#if UNITY_ANDROID
            GooglePlayServicesController.Init();
#endif
        }
Esempio n. 2
0
        public static void SaveProgress(GameManager gameManager, bool toCloud = false)
        {
            ObscuredPrefs.SetInt(WorldConsts.Currency, CurrencyManager.CurrentCurrency);
            MainSaveModel.Instanse.CurrentCurrency = CurrencyManager.CurrentCurrency;
            MainSaveModel.Instanse.LogoutTs        = DateTime.Now;

            MainSaveModel.Instanse.Stats = new Dictionary <string, float>();
            MainSaveModel.Instanse.Stats[WorldConsts.Health] = gameManager.PlayerModel.Health;
            MainSaveModel.Instanse.Stats[WorldConsts.Hunger] = gameManager.PlayerModel.Hunger;
            MainSaveModel.Instanse.Stats[WorldConsts.Thirst] = gameManager.PlayerModel.Thirst;
            MainSaveModel.Instanse.Stats[WorldConsts.Energy] = gameManager.PlayerModel.Energy;

            MainSaveModel.Instanse.CurrentTime = TOD_Sky.Instance.Cycle.Hour;

            MainSaveModel.Instanse.IsBuyStarterPack = gameManager.IapManager.IsBuyStarterPack;
            MainSaveModel.Instanse.IsBuyFirst30000  = gameManager.IapManager.IsBuyFirst30000;
            MainSaveModel.Instanse.IsBuyNoAds       = gameManager.IapManager.IsBuyNoAds;

            MainSaveModel.Instanse.InCar = gameManager.Player.InCar;

            MainSaveModel.Instanse.CurrentBackpack = (int)gameManager.PlayerModel.CurrentBackpack;
            var playerPosition = gameManager.Player.transform.localPosition;

            MainSaveModel.Instanse.PlayerPosition = new List <float>
            {
                playerPosition.x,
                playerPosition.y,
                playerPosition.z
            };
            var playerRotation = gameManager.Player.transform.localEulerAngles;

            MainSaveModel.Instanse.PlayerRotation = playerRotation.y;

            #region Inventory
            MainSaveModel.Instanse.PlayerInventory = new InventorySaveModel();

            for (int i = 0; i < gameManager.PlayerModel.Inventory.MaxSlots; i++)
            {
                var slot = gameManager.PlayerModel.Inventory.Slots[i];
                if (slot != null)
                {
                    MainSaveModel.Instanse.PlayerInventory.ItemInSlots[i.ToString()]           = slot.Item.GetType().Name;
                    MainSaveModel.Instanse.PlayerInventory.ItemAmountInSlots[i.ToString()]     = slot.Amount;
                    MainSaveModel.Instanse.PlayerInventory.ItemDurabilityInSlots[i.ToString()] = slot.CurrentDurability;
                }
            }
            for (int i = 0; i < WorldConsts.QuickSlotsAmount; i++)
            {
                var slot = gameManager.PlayerModel.Inventory.QuickSlots[i];
                if (slot != null)
                {
                    MainSaveModel.Instanse.PlayerInventory.ItemInQuickSlots[i.ToString()]           = slot.Item.GetType().Name;
                    MainSaveModel.Instanse.PlayerInventory.ItemAmountInQuickSlots[i.ToString()]     = slot.Amount;
                    MainSaveModel.Instanse.PlayerInventory.ItemDurabilityInQuickSlots[i.ToString()] = slot.CurrentDurability;
                }
            }
            for (int i = 0; i < WorldConsts.EquipSlotsAmount; i++)
            {
                var slot = gameManager.PlayerModel.Inventory.EquipSlots[i];
                if (slot != null)
                {
                    MainSaveModel.Instanse.PlayerInventory.ItemInEquipSlots[i.ToString()]           = slot.Item.GetType().Name;
                    MainSaveModel.Instanse.PlayerInventory.ItemAmountInEquipSlots[i.ToString()]     = slot.Amount;
                    MainSaveModel.Instanse.PlayerInventory.ItemDurabilityInEquipSlots[i.ToString()] = slot.CurrentDurability;
                }
            }
            #endregion

            MainSaveModel.Instanse.GroundItems = gameManager.PlacementItemsController.GetItemsToSerialize();

            if (gameManager.CarInteractive != null)
            {
                var carModel     = new CarSaveModel();
                var carTransfrom = gameManager.CarInteractive.transform;
                carModel.PosX = carTransfrom.position.x;
                carModel.PosY = carTransfrom.position.y;
                carModel.PosZ = carTransfrom.position.z;

                var carRotation = carTransfrom.eulerAngles;
                carModel.RotX = carRotation.x;
                carModel.RotY = carRotation.y;
                carModel.RotZ = carRotation.z;

                carModel.Petrol = gameManager.CarInteractive.Petrol;
                MainSaveModel.Instanse.CarModel = carModel;
            }

            MainSaveModel.Instanse.CurrentTerratinId = gameManager.CurrentTerain == gameManager.Terrain2 ? 1 : 0;

            var jsString = JsonWriter.Serialize(MainSaveModel.Instanse);
            var saveData = AES.Encrypt(jsString, WorldConsts.CryptKey);
            ObscuredPrefs.SetString(WorldConsts.Save0, saveData);

            if (toCloud)
            {
                GooglePlayServicesController.SaveGame(GetBytes(saveData));
            }

            //Debug.Log("Save Progress " + jsString);
        }