Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by narotuali · Nov 29, 2019 at 10:49 PM · playerprefssavesavingsave datasave file

Unity problem when i convert playerprefs save to the standard file io save

i am using tow kind of save the main save which is encrypting save that is using in this video (https://www.youtube.com/watch?v=XOjd_qU2Ido&t=351s) and playerprefs save when i use them together with the playerprefs only works when i disable the playerprefs the encrypting save work how to make them work together
the playerprefs comes as cs script when i bought daily reward from the asset store this the cs script that contain the playerprefs so i got a problem when i convert playerprefs save to the standard file io save any help

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Globalization;
 
 namespace NiobiumStudios
 {
     /**
     * Timed Rewards Canvas is the User interface to show Timed rewards
     **/
     public class TimedRewards : DailyRewardsCore<TimedRewards>
     {
         public DateTime lastRewardTime;     // The last time the user clicked in a reward
         public TimeSpan timer;
         public float maxTime = 3600f; // How many seconds until the player can claim the reward
         public bool isRewardRandom = false;     // Is the reward random or the player chooses from available rewards?
 
         public List<Reward> rewards;
 
         public delegate void OnCanClaim();              // When the player can claim the reward
         public OnCanClaim onCanClaim;
 
         public delegate void OnClaimPrize(int index);   // When the player claims the prize
         public OnClaimPrize onClaimPrize;
 
         private bool canClaim;              // Checks if the user can claim the reward
 
         // Needed Constants
         private const string TIMED_REWARDS_TIME = "TimedRewardsTime";
         private const string FMT = "O";
         
         void Start()
         {
             StartCoroutine(InitializeTimer());
         }
 
         // Initializes the timer in case the user already have a player preference
         private IEnumerator InitializeTimer()
         {
             yield return StartCoroutine(base.InitializeDate());
 
             if (base.isErrorConnect)
             {
                 if(onInitialize!=null)
                     onInitialize(true, base.errorMessage);
             }
             else
             {
                 LoadTimerData();
 
                 if(onInitialize!=null)
                     onInitialize();
 
                 CheckCanClaim();
             }
         }
 
         void LoadTimerData ()
         {
             string lastRewardTimeStr = PlayerPrefs.GetString(GetTimedRewardsTimeKey());
 
             if (!string.IsNullOrEmpty(lastRewardTimeStr))
             {
                 lastRewardTime = DateTime.ParseExact(lastRewardTimeStr, FMT, CultureInfo.InvariantCulture);
                 timer = (lastRewardTime - now).Add(TimeSpan.FromSeconds(maxTime));
             }
             else
             {
                 timer = TimeSpan.FromSeconds(maxTime);
             }
         }
 
         protected override void OnApplicationPause(bool pauseStatus)
         {
             base.OnApplicationPause(pauseStatus);
             LoadTimerData();
             CheckCanClaim();
         }
 
         public override void TickTime()
         {
             base.TickTime();
             if(isInitialized)
             {
                 // Keeps ticking until the player claims
                 if (!canClaim)
                 {
                     timer = timer.Subtract(TimeSpan.FromSeconds(Time.unscaledDeltaTime));
                     CheckCanClaim();
                 }
             }
         }
 
         public void CheckCanClaim ()
         {
             if (timer.TotalSeconds <= 0)
             {
                 canClaim = true;
                 if (onCanClaim != null)
                     onCanClaim();
             }
             else
             {
                 // We need to save the player time every tick. If the player exits the game the information keeps logged
                 // For perfomance issues you can save this information when the player switches scenes or quits the application
                 PlayerPrefs.SetString(GetTimedRewardsTimeKey(), now.Add(timer - TimeSpan.FromSeconds(maxTime)).ToString(FMT));
             }
         }
 
         //Returns the TimeRewardsTime playerPrefs key depending on instanceId
         private string GetTimedRewardsTimeKey()
         {
             if (instanceId == 0)
                 return TIMED_REWARDS_TIME;
 
             return string.Format("{0}_{1}", TIMED_REWARDS_TIME, instanceId);
         }
 
         // The player claimed the prize. We need to reset to restart the timer
         public void ClaimReward(int rewardIdx)
         {
             PlayerPrefs.SetString(GetTimedRewardsTimeKey(), now.Add(timer - TimeSpan.FromSeconds(maxTime)).ToString(FMT));
             timer = TimeSpan.FromSeconds(maxTime);
 
             canClaim = false;
 
             if (onClaimPrize != null)
                 onClaimPrize(rewardIdx);
         }
 
         public string GetFormattedTime()
         {
             if(timer.Days > 0) 
                 return string.Format("{0:D2} days {1:D2}:{2:D2}:{0:D3}", timer.Days, timer.Hours, timer.Minutes, timer.Seconds);
             else
                 return string.Format("{0:D2}:{1:D2}:{2:D2}", timer.Hours, timer.Minutes, timer.Seconds);
         }
 
         // Resets the Timed Rewards. For debug purposes
         public void Reset()
         {
             PlayerPrefs.DeleteKey(GetTimedRewardsTimeKey());
             canClaim = true;
             timer = TimeSpan.FromSeconds(0);
 
             if (onCanClaim != null)
                 onCanClaim();
         }
 
         // Returns a reward from an index
         public Reward GetReward(int index)
         {
             return rewards[index];
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

126 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Save scene 1 Answer

Why does PlayerPrefs save to the Windows Registry? 0 Answers

Saving Player Data 3 Answers

saving highscores 1 Answer

PlayerPrefs.DeleteAll() not deleting unless app restarts 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges