-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOdnoklassnikiWebplayerAPI.cs
More file actions
86 lines (69 loc) · 2.93 KB
/
OdnoklassnikiWebplayerAPI.cs
File metadata and controls
86 lines (69 loc) · 2.93 KB
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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class OdnoklassnikiWebplayerAPI : MonoBehaviour {
#if UNITY_WEBPLAYER
protected void CallApiMethod(Dictionary<string,string> parameters){
Application.ExternalCall( "OKAPIWrapper.unity_api_call", this.StringDictionaryToJSON(parameters));
}
protected virtual void APIMethodCallback(string param){
this.LogToConsole ("API METHOD CALLBACK FROM UNITY: " + param);
}
protected void JSgetPageInfo(){
Application.ExternalCall ("FAPI.UI.getPageInfo");
}
protected void JSscrollToTop(){
Application.ExternalCall ("FAPI.UI.scrollToTop");
}
protected void JSsetWindowSize(int width, int height){
Application.ExternalCall ("FAPI.UI.setWindowSize", width, height);
}
protected void JSshowInvite(string text,string parameters, string selected_uids){
Application.ExternalCall ("FAPI.UI.showInvite", text, parameters, selected_uids);
}
protected void JSshowNotification(string text,string parameters, string selected_uids){
Application.ExternalCall ("FAPI.UI.showNotification", text, parameters, selected_uids);
}
// TODO uiConf (now not supported)
protected void JSshowPayment(string name, string description, string code, int price, string options, string attributes, string currency, string callback){
Application.ExternalCall ("FAPI.UI.showPayment", name, description, code, price,options,attributes, currency, callback);
}
protected void JSshowPermissions(List<string> permissions){
StringBuilder builder = new StringBuilder ();
builder.Append("[");
foreach (string permission in permissions) {
builder.Append("\"").Append(permission).Append("\",");
}
builder.Replace (",", "]", builder.Length - 1, 1);
Application.ExternalCall ("FAPI.UI.showPermissions", builder.ToString());
}
protected virtual void JSMethodCallback(string param){
this.LogToConsole ("JS METHOD CALLBACK FROM UNITY: " + param);
}
protected void GetUrlVars(){
Application.ExternalCall ("getUrlVars");
}
protected virtual void GetUrlVarsCallback(string param){
this.LogToConsole ("GETVARS CALLBACK FROM UNITY: " + param);
}
protected void Publish(string description, string message, string JSONAttachment, string JSONActionLinks){
Application.ExternalCall ("publish", description, message, JSONAttachment, JSONActionLinks);
}
protected virtual void PublishCallback(string param){
this.LogToConsole ("PUBLISH CALLBACK FROM UNITY: " + param);
}
protected void LogToConsole(string param){
Application.ExternalCall("console.log", param);
}
#endif
private string StringDictionaryToJSON(Dictionary<string,string> parameters){
StringBuilder builder = new StringBuilder ();
builder.Append ("{");
foreach (KeyValuePair<string,string> pair in parameters) {
builder.Append("\"").Append(pair.Key).Append("\":\"").Append(pair.Value).Append("\",");
}
builder.Replace (",", "}", builder.Length - 1, 1);
return builder.ToString ();
}
}