Advertisement
AppingCS

DateTimeTimer

Jan 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Events;
  6. using UnityEngine.UI;
  7. public class DateTimeTimer : MonoBehaviour {
  8.     public HardWorking HardWorking;
  9.     public float seconds;
  10.     public bool Cur;
  11.     public bool Prib;
  12.     public int CutInt;
  13.     public int PribInt;
  14.     void Start () {
  15.         if (PlayerPrefs.GetInt ("CurInt1") == 1) {
  16.             CutInt = 1;
  17.            
  18.             Cur = true;
  19.         }
  20.         if (PlayerPrefs.GetInt ("BribInt1") == 1) {
  21.             Prib = true;
  22.             PribInt = 1;
  23.            
  24.         }
  25.         string dateTimeStringValue = PlayerPrefs.GetString ("TimeExit", DateTime.Now.ToString ());
  26.         seconds = PlayerPrefs.GetFloat ("Now");
  27.         DateTime timeExit = new DateTime ();
  28.         DateTime.TryParse (dateTimeStringValue, out timeExit);
  29.         TimeSpan deltaTime = DateTime.Now.Subtract (timeExit);
  30.         if (deltaTime.Seconds >= seconds) {
  31.             if (Cur) {
  32.                 HardWorking.TimerCur[0] = 0;
  33.                 Debug.Log ("Set timerCur is 0");
  34.             }
  35.             if (Prib) {
  36.                 HardWorking.TimerPrib[0] = 0;
  37.                 Debug.Log ("Set timerPrib is 0");
  38.             }
  39.         } else {
  40.             if (deltaTime.Seconds < seconds) {
  41.                 if (Cur) {
  42.                     float TimeC = PlayerPrefs.GetFloat ("SaveTimerCur1");
  43.                     TimeC -= deltaTime.Seconds;
  44.                     HardWorking.TimerCur[0] = TimeC;
  45.                     HardWorking.ButtonZak[0].interactable = false;
  46.                 }
  47.                 if (Prib) {
  48.                     float TimeP = PlayerPrefs.GetFloat ("SaveTimerPrib1");
  49.                     TimeP -= deltaTime.Seconds;
  50.                     HardWorking.TimerPrib[0] = TimeP;
  51.                     HardWorking.ButtonZak[0].interactable = false;
  52.                 }
  53.             }
  54.         }
  55.     }
  56.     void OnApplicationQuit () {
  57.         PlayerPrefs.SetString ("TimeExit", DateTime.Now.ToString ());
  58.         PlayerPrefs.SetFloat ("SaveTimerCur1", HardWorking.TimerCur[0]);
  59.         PlayerPrefs.SetFloat ("SaveTimerPrib1", HardWorking.TimerPrib[0]);
  60.         PlayerPrefs.SetFloat ("Now", seconds);
  61.         PlayerPrefs.SetInt ("CurInt1", CutInt);
  62.         PlayerPrefs.SetInt ("BribInt1", PribInt);
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement