summaryrefslogtreecommitdiff
path: root/Runtime/Export/NetworkServices.cs
blob: 0e1f1cdb791b4fe3ad5e91ea913c42a1b2d3dd49 (plain)
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;

namespace UnityEngine
{
	using UnityEngine.SocialPlatforms;
	
	// A facade for the social API namespace, no state, only helper functions which delegate into others
	public static class Social
	{
		public static ISocialPlatform Active
		{
			get	{ return ActivePlatform.Instance; }
			set { ActivePlatform.Instance = value; }
		}
		
		public static ILocalUser localUser { get { return Active.localUser; } }
		
		public static void LoadUsers(string[] userIDs, Action<IUserProfile[]> callback)
		{
			Active.LoadUsers(userIDs, callback);
		}
		
		public static void ReportProgress(string achievementID, double progress, Action<bool> callback)
        {
			Active.ReportProgress(achievementID, progress, callback);
        }
		
		public static void LoadAchievementDescriptions(Action<IAchievementDescription[]> callback)
		{
			Active.LoadAchievementDescriptions(callback);
		}
		
		public static void LoadAchievements(Action<IAchievement[]> callback)
		{
			Active.LoadAchievements(callback);
		}
		
		public static void ReportScore(Int64 score, string board, Action<bool> callback)
		{
			Active.ReportScore(score, board, callback);
		}
		
		public static void LoadScores(string leaderboardID, Action<IScore[]> callback)
		{
			Active.LoadScores(leaderboardID, callback);
		}
		
		public static ILeaderboard CreateLeaderboard()
		{
			return Active.CreateLeaderboard();
		}
		
		public static IAchievement CreateAchievement()
		{
			return Active.CreateAchievement();
		}
		
		public static void ShowAchievementsUI()
		{
			Active.ShowAchievementsUI();
		}
		
		public static void ShowLeaderboardUI()
		{
			Active.ShowLeaderboardUI();
		}
	}
}

namespace UnityEngine.SocialPlatforms
{	
	// The state of the current active social implementation
	internal static class ActivePlatform
	{
		private static ISocialPlatform _active;
		
		internal static ISocialPlatform Instance
		{
			get
			{
				if (_active == null)
					_active = SelectSocialPlatform();
				return _active;
			}
			set
			{
				_active = value;
			}
		}
		
		private static ISocialPlatform SelectSocialPlatform() {
			// statically selecting community
			#if ENABLE_GAMECENTER
			return new UnityEngine.SocialPlatforms.GameCenter.GameCenterPlatform();
			#elif UNITY_XENON_API && ENABLE_XENON_SOCIALAPI
			return new XboxLive();
			#else
			return new UnityEngine.SocialPlatforms.Local();
			#endif
		}		
	}

	public interface ISocialPlatform
	{
		ILocalUser localUser { get; }

		void LoadUsers(string[] userIDs, Action<IUserProfile[]> callback);

		void ReportProgress(string achievementID, double progress, Action<bool> callback);
		void LoadAchievementDescriptions(Action<IAchievementDescription[]> callback);
		void LoadAchievements(Action<IAchievement[]> callback);
		IAchievement CreateAchievement();
		
		void ReportScore(Int64 score, string board, Action<bool> callback);
		void LoadScores(string leaderboardID, Action<IScore[]> callback);
		ILeaderboard CreateLeaderboard();

		void ShowAchievementsUI();
		void ShowLeaderboardUI();
		
		// ===> These should be explicitly implemented <===
		void Authenticate(ILocalUser user, Action<bool> callback);		
		void LoadFriends(ILocalUser user, Action<bool> callback);
		void LoadScores(ILeaderboard board, Action<bool> callback);
		bool GetLoading(ILeaderboard board);
	}
		
	public interface ILocalUser : IUserProfile
	{
		void Authenticate (Action<bool> callback);
		void LoadFriends (Action<bool> callback);
		
		IUserProfile[] friends { get; }
		bool authenticated { get; }
		bool underage { get; }
	}

	public enum UserState
	{
		Online,
		OnlineAndAway,
		OnlineAndBusy,
		Offline,
		Playing
	}
		
	public interface IUserProfile
	{			
		string userName { get; }
		string id { get; }
		bool isFriend { get; }
		UserState state { get; }
		Texture2D image { get; }
	}
	
	public interface IAchievement
	{
		void ReportProgress(Action<bool> callback);

		string id { get; set; }		
		double percentCompleted { get; set; }
		bool completed { get; }
		bool hidden { get; }
		DateTime lastReportedDate { get; }
	}
	
	public interface IAchievementDescription
	{
		string id { get; set; }
		string title { get; }
		Texture2D image { get; }
		string achievedDescription { get; }
		string unachievedDescription { get; }
		bool hidden { get; }
		int points { get; }
	}
	
	public interface IScore
	{
		void ReportScore(Action<bool> callback);

		string leaderboardID { get; set; }
		// TODO: This is just an int64 here, but should be able to represent all supported formats, except for float type scores ...
		Int64 value { get; set; }
		DateTime date { get; }
		string formattedValue { get; }
		string userID { get; }
		int rank { get; }
	}
	
	public enum UserScope
	{
		Global = 0,
		FriendsOnly
	}
	
	public enum TimeScope
	{
		Today = 0,
		Week,
		AllTime
	}
	
	public struct Range
	{
		public int from;
		public int count;
		
		public Range(int fromValue, int valueCount)
		{
			from = fromValue;
			count = valueCount;
		}
	}
	
	public interface ILeaderboard
	{
		void SetUserFilter(string[] userIDs);
		void LoadScores(Action<bool> callback);
		bool loading { get; }

		string id { get; set; }
		UserScope userScope { get; set; }
		Range range { get; set; }
		TimeScope timeScope { get; set; }		
		IScore localUserScore { get; }
		uint maxRange { get; }
		IScore[] scores { get; }
		string title { get; }
	}
}