Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.04 KB | None | 0 0
  1. using PlayFab;
  2. using PlayFab.ClientModels;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8.  
  9. public class DaileyManagment : MonoBehaviour
  10. {
  11.     [SerializeField] public int year, month, day, hours, minutes, seconds;
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.     private bool daylieRun;
  20.  
  21.  
  22.     public GameObject DaileyEncounter;
  23.  
  24.     public GameObject Dayprice1;
  25.     public GameObject Dayprice2;
  26.     public GameObject Dayprice3;
  27.     public GameObject Dayprice4;
  28.     public GameObject Dayprice5;
  29.     public GameObject Dayprice6;
  30.     public GameObject Dayprice7;
  31.  
  32.     //public float Timer;
  33.  
  34.  
  35.     public Text Daytime;
  36.     public Text Clock;
  37.     public Text Dailey;
  38.     public Text Day1;
  39.     public Text Day2;
  40.     public Text Day3;
  41.     public Text Day4;
  42.     public Text Day5;
  43.     public Text Day6;
  44.     public Text Day7;
  45.    
  46.  
  47.     void Awake()
  48.     {
  49.         GetStats();  
  50.     }
  51.  
  52.    
  53.  
  54.     // Start is called before the first frame update
  55.     void Start()
  56.     {
  57.         //daylieRun = false;
  58.         Dailey.text = "Tägliche Belohnung fürs einloggen";
  59.         Day1.text = "Tag 1";
  60.         Day2.text = "Tag 2";
  61.         Day3.text = "Tag 3";
  62.         Day4.text = "Tag 4";
  63.         Day5.text = "Tag 5";
  64.         Day6.text = "Tag 6";
  65.         Day7.text = "Tag 7";
  66.         //GetStats();
  67.     }
  68.  
  69.     // Update is called once per frame
  70.     public void Update()
  71.     {
  72.  
  73.  
  74.  
  75.  
  76.         DateTime time = DateTime.Now;
  77.  
  78.         Clock.text = time.ToString("HH:mm:ss");
  79.  
  80.         if (DateTime.Now.Hour == hours && DateTime.Now.Minute == minutes && DateTime.Now.Second == seconds)
  81.         {
  82.             if (!daylieRun)
  83.             {
  84.                 daylieRun = true;
  85.                 if (day == 7)
  86.                 {
  87.                     print("Es ist eine 7 !!!!!");
  88.                     day = 1;
  89.                 }
  90.                 else
  91.                 {
  92.                     day++;
  93.                 }
  94.  
  95.                 Daytime.text = "Day  " + day.ToString();
  96.                 print(day.ToString());
  97.                 SaveDay();
  98.  
  99.             }
  100.         }
  101.     }
  102.  
  103.     private void SaveDay()
  104.     {
  105.         var request = new UpdatePlayerStatisticsRequest();
  106.         request.Statistics = new List<StatisticUpdate>();
  107.  
  108.         var stat = new StatisticUpdate { StatisticName = "Day", Value = day };
  109.         request.Statistics.Add(stat);
  110.         PlayFabClientAPI.UpdatePlayerStatistics(request, OnSendStatsSuccess, OnError);
  111.  
  112.     }
  113.  
  114.     private void OnError(PlayFabError obj)
  115.     {
  116.         print("Der Tag konnte nicht gespeichert werden");
  117.     }
  118.  
  119.     private void OnSendStatsSuccess(UpdatePlayerStatisticsResult obj)
  120.     {
  121.         print("Tag wurde gespeichert");
  122.     }
  123.  
  124.     public void DaileyClosed()
  125.     {
  126.         DaileyEncounter.SetActive(false);
  127.     }
  128.  
  129.  
  130.  
  131.     public void DayPrice1()
  132.     {
  133.  
  134.     }
  135.  
  136.     public void DayPrice2()
  137.     {
  138.  
  139.     }
  140.  
  141.     public void DayPrice3()
  142.     {
  143.  
  144.     }
  145.  
  146.     public void DayPrice4()
  147.     {
  148.  
  149.     }
  150.  
  151.     public void DayPrice5()
  152.     {
  153.  
  154.     }
  155.  
  156.     public void DayPrice6()
  157.     {
  158.  
  159.     }
  160.  
  161.     public void DayPrice7()
  162.     {
  163.  
  164.     }
  165.  
  166.     public void GetStats()
  167.     {
  168.         //Neue Anfrage erstallen
  169.         var request = new GetPlayerStatisticsRequest();
  170.         request.StatisticNames = new List<string>() { "Year", "Month", "Day", "Hour", "Minuts", "Seconds" };
  171.  
  172.  
  173.         // request an PlayFabAPI
  174.         PlayFabClientAPI.GetPlayerStatistics(request, GetPlayerStaticsSuccess, OnPlayFabError);
  175.  
  176.     }
  177.  
  178.     private void OnPlayFabError(PlayFabError obj)
  179.     {
  180.         print("Es konnte nichts geholt werden");
  181.     }
  182.  
  183.     public void GetPlayerStaticsSuccess(GetPlayerStatisticsResult result)
  184.     {
  185.         for (int i = 0; i < result.Statistics.Count; i++)
  186.         {
  187.             if (result.Statistics[i].StatisticName == "Day")
  188.             {
  189.                 day = result.Statistics[i].Value;
  190.                 print("Day wurde geholt");
  191.             }
  192.         }
  193.         Daytime.text ="Day" + day.ToString();
  194.  
  195.         print(day.ToString());
  196.  
  197.     }
  198.  
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement