Exemple #1
0
    /// <summary>
    /// Saves Yuni's stats
    /// </summary>
    void SavePlayerData()
    {
        yuniData.hasNeedle       = playerAttack.HasNeedle();
        yuniData.hasHammer       = playerAttack.HasHammer();
        yuniData.hasThread       = playerAttack.HasThread();
        yuniData.usingHammer     = playerAttack.UsingHammer();
        yuniData.usingNeedle     = playerAttack.UsingNeedle();
        yuniData.hp              = playerHealth.CurrentHealth();
        yuniData.maxHp           = playerHealth.GetMaxHp();
        yuniData.equippedDenom   = playerAttack.getEquippedDenominator();
        yuniData.needleDenom     = playerAttack.getEquippedDenominator();
        yuniData.hammerDenom     = playerAttack.getEquippedDenominator();
        yuniData.hammerCharge    = playerAttack.getHammerObject().chargeRate;
        yuniData.hammerPrevDenom = playerAttack.getHammerObject().prevDenominator;

        string newData = JsonUtility.ToJson(yuniData, true);

        File.WriteAllText(playerDataPath, newData);
        yuniData = new YuniData();

        Debug.Log("Saved player data" + "valu " + yuniData.needleDenom);
    }
Exemple #2
0
    /// <summary>
    /// Loads saved Yuni's stats, if it exists
    /// </summary>
    void LoadPlayerData()
    {
        Debug.Log("File exists" + File.Exists(playerDataPath));
        if (File.Exists(playerDataPath))
        {
            string data = File.ReadAllText(playerDataPath);
            yuniData = JsonUtility.FromJson <YuniData> (data);
            playerAttack.SetEquippedDenominator(yuniData.equippedDenom);
            playerAttack.SetHasHammer(yuniData.hasHammer);
            playerAttack.SetHasNeedle(yuniData.hasNeedle);
            playerAttack.SetHasThread(yuniData.hasThread);
//			playerAttack.SetUsingHammer (yuniData.usingHammer);
//			playerAttack.SetUsingNeedle (yuniData.usingNeedle);
            playerAttack.getHammerObject().chargeRate = yuniData.hammerCharge;
            playerAttack.getHammerObject().SyncWithEquippedDenominator(yuniData.hammerDenom);
            playerAttack.getNeedle().SyncWireSliceCountWithEquippedDenominator(yuniData.needleDenom);
            playerAttack.getHammerObject().prevDenominator = yuniData.hammerPrevDenom;
            playerHealth.SetCurrentHealth(yuniData.hp);
            playerHealth.SetMaxHp(yuniData.maxHp);

            if (yuniData.usingHammer)
            {
                Debug.Log("CHANGED WEAPONS");
                playerAttack.ChangeWeapons();
            }

            Debug.Log("<color=red>CHANGED WEAPONS </color> " + yuniData.hammerDenom);
//			Debug.Log ("LOAD"+"valu "+ yuniData.needleDenom);
            Debug.Log("Loaded player data");
        }
        else
        {
//			Debug.LogError ("Unable to read the saved data, file doesn't exist");
            yuniData = new YuniData();
        }
    }
Exemple #3
0
    /// <summary>
    /// Unity Function. Called once in the game object's lifetime to initiate the script once it has been enabled
    /// </summary>
    void Start()
    {
        doesSceneExist = false;
        currentBlockID = 1;
        currentPieceID = 1;
        sceneTag       = GameObject.FindGameObjectWithTag("SceneTag").GetComponent <SceneTag> ();
        if (PlayerPrefs.HasKey("Username"))
        {
            folderDataPath = Application.persistentDataPath + "/Game Data/user_" + PlayerPrefs.GetString("Username");
//			Debug.LogError("Username "+PlayerPrefs.GetString("Username"));
        }
        else
        {
            folderDataPath = Application.persistentDataPath + "/Game Data/user_default";
        }

//		folderDataPath = Application.persistentDataPath + "/Game Data/user_1";
        Debug.Log("Folder data path: " + folderDataPath);
//		if (isNewUser) {
//			if (!Directory.Exists (folderDataPath)) {
//				currentFolderID = "1";
//			} else {
//				string[] directories = Directory.GetDirectories (folderDataPath);
//				List<int> folderIDs = new List<int> ();
//				foreach (string dir in directories) {
//					folderIDs.Add (int.Parse (dir.Split ('_').Last ()));
//				}
//
//				folderIDs.OrderByDescending (x => x);
//				string directoryName = directories.OrderByDescending (x => x).First ();
//				currentFolderID = (1 + folderIDs.OrderByDescending (x => x).First ()).ToString ();
//			}
//
//			folderDataPath = Application.persistentDataPath + "/Game Data/user_" + currentFolderID;
//			Debug.Log ("Folder data path: " + folderDataPath);
//			if (!Directory.Exists (folderDataPath)) {
//				Directory.CreateDirectory (folderDataPath);
//			}
//		} else {
//			folderDataPath += "/user_1";
//		}

        sceneData = new SceneData();
        yuniData  = new YuniData();
        userData  = new UserData();
        Debug.Log("Folder data path: " + folderDataPath);
        sceneDataPath  = folderDataPath + "/" + SceneManager.GetActiveScene().name + ".json";
        playerDataPath = folderDataPath + "/YuniData.json";
        userDataPath   = folderDataPath + "/UserData.json";
        playerHealth   = GameObject.FindObjectOfType <PlayerHealth> ();
        playerAttack   = GameObject.FindObjectOfType <PlayerAttack> ();
        hollowBlocks   = FindObjectsOfType <HollowBlock>();
        skyBlocks      = FindObjectsOfType <SkyBlock> ();
        foreach (HollowBlock block in hollowBlocks)
        {
            block.SetSceneObjectId(currentBlockID);
            currentBlockID++;
//			skyFragmentPieces = block.gameObject.GetComponentsInChildren<SkyFragmentPiece> ();
        }

        currentBlockID = 1;
        foreach (SkyBlock block in skyBlocks)
        {
            block.SetSceneObjectId(currentBlockID);
            currentBlockID++;
        }
    }