Search Unity

CalendarUnit question

Discussion in 'Scripting' started by Tripwire, Sep 22, 2014.

  1. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi,

    I have a question about the CalendarUnit enum, i'm using it for LocalNotifications in my app. Thing is my client wants to choose between the following repeatintervals:

    - hourly (default so no problem)
    - every 3 hours
    - every 5 hours
    - every 10 hours

    Since the CalendarUnit is an enum I can't add new items to it. I tried debugging to see what the CalendarUnit variable actually returns but it simply prints Hour. I also tried:
    Code (CSharp):
    1. Debug.Log (CalendarUnit.Hour + 3 + " and Unit converted to int: " + System.Convert.ToInt32(CalendarUnit.Hour));
    This prints the following:
    35 and Unit converted to int: 32

    Don't really know where those values stand for.

    Any ideas?
     
  2. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    pretty pls :)
     
  3. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    anyone?
     
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    http://docs.unity3d.com/ScriptReference/CalendarUnit.html
    The integer value of each unit is just a power 2, in the order shown (starting from 2), presumably so you can combine different ones and get a unique value.

    You should just make your own enum

    enum myTimes { OneHour, ThreeHours, FiveHours, TenHours }

    Code (CSharp):
    1.     enum myTimes { OneHour, ThreeHours, FiveHours, TenHours }
    2.  
    3.     myTimes time;
    4.  
    5.     void OnGUI () {
    6.         time = (myTimes) EditorGUILayout.EnumPopup( time );
    7.     }
    8.  
     
  5. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi hpjohn,

    Thanks for your reply! Thing is, LocalNotification.repeatInterval only accepts a CalendarUnit. So I think creating my own Enum isn't going to work.