-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfbscriptnew.cs
195 lines (151 loc) · 4.25 KB
/
fbscriptnew.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;
using Facebook.Unity;
public class fbscriptnew : MonoBehaviour
{
public GameObject DialogLoggedIn; // for loged in functions
public GameObject DialogLoggedOut; // for showing login
public GameObject DialogUsername; // username to display
public GameObject DialogProfilePic; // profile pic to display
void Awake()
{
FB.Init(SetInit, OnHideUnity); // initialising
}
void SetInit()
{
if (FB.IsLoggedIn) // checking login status
{
Debug.Log("FB is logged in");
}
else
{
Debug.Log("FB is not logged in");
}
DealWithFBMenus(FB.IsLoggedIn);
}
void OnHideUnity(bool isGameShown)
{
if (!isGameShown)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
}
public void FBlogin() // login functions
{
List<string> permissions = new List<string>();
permissions.Add("public_profile"); // requesting permision to acces data
FB.LogInWithReadPermissions(permissions, AuthCallBack);
}
void AuthCallBack(IResult result)
{
if (result.Error != null)
{
Debug.Log(result.Error);
}
else
{
if (FB.IsLoggedIn)
{
Debug.Log("FB is logged in");
}
else
{
Debug.Log("FB is not logged in");
}
DealWithFBMenus(FB.IsLoggedIn);
}
}
void DealWithFBMenus(bool isLoggedIn)
{
if (isLoggedIn) //showing the loged in window
{
DialogLoggedIn.SetActive(true);
DialogLoggedOut.SetActive(false);
FB.API("/me?fields=first_name", HttpMethod.GET, DisplayUsername); // loading facebook username
FB.API("/me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayProfilePic); // lodaing facebook profile pic
}
else
{
DialogLoggedIn.SetActive(false);
DialogLoggedOut.SetActive(true);
}
}
void DisplayUsername(IResult result)
{
Text UserName = DialogUsername.GetComponent<Text>();
if (result.Error == null)
{
UserName.text = "Let's Go, " + result.ResultDictionary["first_name"]; // showing facebook username
}
else
{
Debug.Log(result.Error);
}
}
void DisplayProfilePic(IGraphResult result)
{
if (result.Texture != null)
{
Image ProfilePic = DialogProfilePic.GetComponent<Image>();
ProfilePic.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 128, 128), new Vector2()); // lodaing facebook profile pic
}
}
public void Share() // share function
{
FB.FeedShare(
string.Empty,
new Uri("http://www.8stags.in"),
"Improve Your Brain Skills",
"Crotex The 1st Dual Charcter single Player Game",
"Check This Out",
new Uri("http://www.8stags.in/cortex.png"),
string.Empty,
ShareCallback
);
}
void ShareCallback(IResult result)
{
if (result.Cancelled)
{
Debug.Log("Share Cancelled");
}
else if (!string.IsNullOrEmpty(result.Error))
{
Debug.Log("Error on share!");
}
else if (!string.IsNullOrEmpty(result.RawResult))
{
Debug.Log("Success on share");
}
}
public void Invite() // invite function
{
FB.Mobile.AppInvite(
new Uri("https://fb.me/542620622603464"),
new Uri("http://8stags.in/logo.png"),
InviteCallback
);
}
void InviteCallback(IResult result)
{
if (result.Cancelled)
{
Debug.Log("Invite Cancelled");
}
else if (!string.IsNullOrEmpty(result.Error))
{
Debug.Log("Error on invite!");
}
else if (!string.IsNullOrEmpty(result.RawResult))
{
Debug.Log("Success on Invite");
}
}
}