-
Notifications
You must be signed in to change notification settings - Fork 32
/
FacebookManager.cs
105 lines (92 loc) · 2.74 KB
/
FacebookManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using UnityEngine;
/// <summary>
/// Handles Facebook integration
/// </summary>
public class FacebookManager : MonoBehaviour
{
private bool _loggedIn = false;
private const string FacebookAuthTokenKey = "FacebookAuthToken";
GUIContent[] comboBoxList;
private ComboBox comboBoxControl;// = new ComboBox();
private GUIStyle listStyle = new GUIStyle();
void Start()
{
comboBoxList = new GUIContent[5];
comboBoxList[0] = new GUIContent("Friend 1");
comboBoxList[1] = new GUIContent("Friend 2");
comboBoxList[2] = new GUIContent("Friend 3");
comboBoxList[3] = new GUIContent("Friend 4");
comboBoxList[4] = new GUIContent("Friend 5");
listStyle.normal.textColor = Color.white;
listStyle.onHover.background =
listStyle.hover.background = new Texture2D(2, 2);
listStyle.padding.left =
listStyle.padding.right =
listStyle.padding.top =
listStyle.padding.bottom = 4;
comboBoxControl = new ComboBox(new Rect(160, 20, 100, 20), comboBoxList[0], comboBoxList, "button", "box", listStyle);
}
void OnGUI()
{
comboBoxControl.Show();
GUI.Label(new Rect(20, 20, 150, 20), "Select friend to invite : " + comboBoxControl.ButtonContent);
if (GUI.Button(new Rect(280, 20, 100, 20), "Send invite"))
{
ShowFriends();
}
if (_loggedIn)
{
if (GUI.Button(new Rect(Screen.width - 150, 50, 130, 20), "Facebook logout"))
{
Logout();
}
}
else
{
if (GUI.Button(new Rect(Screen.width - 150, 50, 130, 20), "Facebook login"))
{
Login();
}
}
}
private void ShowFriends()
{
#if UNITY_WINRT
// TODO display a list of friends, and then when one is pressed call InviteFriend("friendid");
InviteFriend("TestUser");
#endif
}
private void Login()
{
#if UNITY_WINRT
MyPlugin.Facebook.FacebookPlugin.Login(result =>
{
if (!string.IsNullOrEmpty(result))
{
PlayerPrefs.SetString(FacebookAuthTokenKey, result);
PlayerPrefs.Save();
}
});
#endif
}
private void Logout()
{
#if UNITY_WINRT
MyPlugin.Facebook.FacebookPlugin.Logout(() =>
{
if (PlayerPrefs.HasKey(FacebookAuthTokenKey))
{
PlayerPrefs.DeleteKey(FacebookAuthTokenKey);
PlayerPrefs.Save();
}
_loggedIn = false;
});
#endif
}
private void InviteFriend(string friend)
{
#if UNITY_WINRT
MyPlugin.Facebook.FacebookPlugin.InviteFriend(friend);
#endif
}
}