Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.41 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Google.Apis.Calendar.v3;
  5. using Google.Apis.Calendar.v3.Data;
  6. using Google.Apis.Services;
  7. using System;
  8. using System.Globalization;
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. using Event = Google.Apis.Calendar.v3.Data.Event;
  13.  
  14. public class Scrollbar : MonoBehaviour
  15. {
  16.     private Dictionary<DateTime, List<EventInfo>> eventsOnDay = new Dictionary<DateTime, List<EventInfo>>();
  17.  
  18.     public Transform infoPrefab;
  19.  
  20.     public Transform infoContentPanel;
  21.  
  22.     DateTime date = DateTime.Today;
  23.  
  24.     public EventPanel eventPanel;
  25.  
  26.     int h = 0;
  27.     // Start is called before the first frame update
  28.     void Start()
  29.     {
  30.         foreach (EventInfo e in eventsOnDay[date])
  31.         {
  32.             // Create a new information item
  33.             Transform item = Instantiate(infoPrefab, infoContentPanel);
  34.             // Set its title to the title of the event
  35.             item.GetComponentInChildren<Text>().text = e.e.Summary.ToString();
  36.             // Add an event listener when the information item is clicked, passing in its current index
  37.             item.GetComponent<Button>().onClick.AddListener(() => DisplayEventDetails(date, item.transform.GetSiblingIndex()));
  38.  
  39.         }
  40.     }
  41.  
  42.     internal void DisplayEventDetails(DateTime date, int index)
  43.     {
  44.         // Play a cool animation
  45.         eventPanel.GetComponent<Animator>().Play("slide in");
  46.  
  47.         Event e = eventsOnDay[date][index].e;
  48.  
  49.         eventPanel.eventTitle.text = e.Summary.ToString();
  50.  
  51.         eventPanel.eventCalendar.text = eventsOnDay[date][index].calendarName;
  52.  
  53.         // Get the start time
  54.         string when = e.Start.DateTime.ToString();
  55.         if (String.IsNullOrEmpty(when))
  56.         {
  57.             when = e.Start.Date;
  58.         }
  59.  
  60.         // Set the location to the event's location, default none
  61.         try
  62.         {
  63.             eventPanel.eventLoc.text = e.Location.ToString();
  64.         }
  65.         catch (NullReferenceException exception)
  66.         {
  67.             eventPanel.eventLoc.text = "No location specified";
  68.         }
  69.  
  70.         // Set the description to the event's description, default is the time of the event
  71.         try
  72.         {
  73.             // If the date of the event does not equal 12 AM, then add the time afterwards
  74.             if (!DateTime.Parse(when).ToShortTimeString().Equals(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).ToShortTimeString()))
  75.             {
  76.                 eventPanel.eventDesc.text = e.Description.ToString() + " " + DateTime.Parse(when).ToShortTimeString();
  77.             }
  78.             else
  79.             {
  80.                 eventPanel.eventDesc.text = e.Description.ToString();
  81.             }
  82.  
  83.         }
  84.         catch (Exception exception)
  85.         {
  86.             eventPanel.eventDesc.text = DateTime.Parse(when).ToShortTimeString();
  87.         }
  88.  
  89.  
  90.         DateTime day = DateTime.Parse(when);
  91.  
  92.         // Set the top date to the event date
  93.         eventPanel.eventDay.text = day.Day.ToString();
  94.         eventPanel.eventMonth.text = DateTimeFormatInfo.CurrentInfo.GetMonthName(day.Month).ToUpper();
  95.         eventPanel.eventYear.text = day.Year.ToString();
  96.  
  97.         eventPanel.eventDateBG.color = Color.HSVToRGB((day.Month - 1) * 30f / 360f, 0.6f, 0.78f);
  98.     }
  99.  
  100.     // Update is called once per frame
  101.     void Update()
  102.     {
  103.        
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement