diff --git a/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs b/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs index d5bb90e..b99dc87 100644 --- a/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs +++ b/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs @@ -89,7 +89,7 @@ public class ChannelsAPI : BaseAPI public event Action OnChannelStoragePropsFailedToSet; public event Action OnChannelStoragePropsUpdated; - private ChannelStorageManager _storageManager = new ChannelStorageManager(); + private readonly ChannelStorageManager _storageManager = new (); public ChannelsAPI() : base("v1/game-channels") { diff --git a/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerRelationshipsAPI.cs b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerRelationshipsAPI.cs new file mode 100644 index 0000000..aca679c --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerRelationshipsAPI.cs @@ -0,0 +1,283 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using UnityEngine; + +namespace TaloGameServices +{ + public enum ConfirmedFilter + { + Any, + Confirmed, + Unconfirmed + } + + public enum RelationshipTypeFilter + { + Any, + Unidirectional, + Bidirectional + } + + public class GetSubscribersOptions + { + public int page = 0; + public ConfirmedFilter confirmed = ConfirmedFilter.Any; + public int aliasId = -1; + public RelationshipTypeFilter relationshipType = RelationshipTypeFilter.Any; + + public string ToQueryString() + { + var query = new Dictionary { ["page"] = page.ToString() }; + + if (confirmed != ConfirmedFilter.Any) + { + // 'true' or 'false' + query["confirmed"] = (confirmed == ConfirmedFilter.Confirmed).ToString().ToLower(); + } + + if (aliasId != -1) + { + query["aliasId"] = aliasId.ToString(); + } + + if (relationshipType != RelationshipTypeFilter.Any) + { + var type = relationshipType == RelationshipTypeFilter.Bidirectional ? RelationshipType.Bidirectional : RelationshipType.Unidirectional; + query["relationshipType"] = PlayerAliasSubscription.RelationshipTypeToString(type); + } + + return string.Join("&", query.Select((param) => $"{param.Key}={Uri.EscapeDataString(param.Value)}")); + } + } + + public class GetSubscriptionsOptions + { + public int page = 0; + public ConfirmedFilter confirmed = ConfirmedFilter.Any; + public int aliasId = -1; + public RelationshipTypeFilter relationshipType = RelationshipTypeFilter.Any; + + public string ToQueryString() + { + var query = new Dictionary { ["page"] = page.ToString() }; + + if (confirmed != ConfirmedFilter.Any) + { + query["confirmed"] = (confirmed == ConfirmedFilter.Confirmed).ToString().ToLower(); + } + + if (aliasId != -1) + { + query["aliasId"] = aliasId.ToString(); + } + + if (relationshipType != RelationshipTypeFilter.Any) + { + var type = relationshipType == RelationshipTypeFilter.Bidirectional ? RelationshipType.Bidirectional : RelationshipType.Unidirectional; + query["relationshipType"] = PlayerAliasSubscription.RelationshipTypeToString(type); + } + + return string.Join("&", query.Select((param) => $"{param.Key}={Uri.EscapeDataString(param.Value)}")); + } + } + + public class PlayerRelationshipsAPI : BaseAPI + { + public event Action OnMessageReceived; + public event Action OnRelationshipRequestReceived; + public event Action OnRelationshipRequestCancelled; + public event Action OnRelationshipConfirmed; + public event Action OnRelationshipEnded; + + public PlayerRelationshipsAPI() : base("v1/players/relationships") + { + Talo.Socket.OnMessageReceived += HandleSocketMessage; + } + + private void HandleSocketMessage(SocketResponse response) + { + var responseType = response.GetResponseType(); + + switch (responseType) + { + case "v1.player-relationships.broadcast": + var broadcastData = response.GetData(); + if (broadcastData?.playerAlias != null) + { + OnMessageReceived?.Invoke(broadcastData.playerAlias, broadcastData.message); + } + break; + + case "v1.player-relationships.subscription-created": + var createdData = response.GetData(); + if (createdData?.subscription?.subscriber != null) + { + OnRelationshipRequestReceived?.Invoke(createdData.subscription.subscriber); + } + break; + + case "v1.player-relationships.subscription-confirmed": + var confirmedData = response.GetData(); + if (confirmedData?.subscription != null) + { + var subscription = confirmedData.subscription; + var otherAlias = GetOtherAlias(subscription); + if (otherAlias != null) + { + OnRelationshipConfirmed?.Invoke(otherAlias); + } + } + break; + + case "v1.player-relationships.subscription-deleted": + var deletedData = response.GetData(); + if (deletedData?.subscription != null) + { + var subscription = deletedData.subscription; + var otherAlias = GetOtherAlias(subscription); + if (otherAlias != null) + { + if (subscription.confirmed) + { + OnRelationshipEnded?.Invoke(otherAlias); + } + else + { + OnRelationshipRequestCancelled?.Invoke(otherAlias); + } + } + } + break; + } + } + + private PlayerAlias GetOtherAlias(PlayerAliasSubscription subscription) + { + if (subscription.subscriber?.player?.id == Talo.CurrentPlayer?.id) + { + return subscription.subscribedTo; + } + return subscription.subscriber; + } + + public void Broadcast(string message) + { + Talo.IdentityCheck(); + + var payload = new PlayerRelationshipsBroadcastRequest + { + message = message + }; + + Talo.Socket.Send(new SocketRequest("v1.player-relationships.broadcast", payload)); + } + + public async Task SubscribeTo(int playerAliasId, RelationshipType relationshipType) + { + Talo.IdentityCheck(); + + var request = new PlayerRelationshipsSubscribeToRequest + { + aliasId = playerAliasId, + relationshipType = PlayerAliasSubscription.RelationshipTypeToString(relationshipType) + }; + + var json = await Call(GetUri(), "POST", JsonUtility.ToJson(request)); + var response = JsonUtility.FromJson(json); + return response.subscription; + } + + public async Task RevokeSubscription(int subscriptionId) + { + Talo.IdentityCheck(); + + await Call(new Uri($"{baseUrl}/{subscriptionId}"), "DELETE"); + } + + public async Task UnsubscribeFrom(int playerAliasId) + { + Talo.IdentityCheck(); + + var options = new GetSubscriptionsOptions { aliasId = playerAliasId }; + var page = await GetSubscriptions(options); + + if (page.subscriptions.Length == 0) + { + return false; + } + + await RevokeSubscription(page.subscriptions[0].id); + return true; + } + + public async Task ConfirmSubscriptionById(int subscriptionId) + { + Talo.IdentityCheck(); + + var json = await Call(new Uri($"{baseUrl}/{subscriptionId}/confirm"), "PUT"); + var response = JsonUtility.FromJson(json); + return response.subscription; + } + + public async Task ConfirmSubscriptionFrom(int playerAliasId) + { + Talo.IdentityCheck(); + + var options = new GetSubscribersOptions + { + confirmed = ConfirmedFilter.Unconfirmed, + aliasId = playerAliasId + }; + var page = await GetSubscribers(options); + + if (page.subscriptions.Length == 0) + { + return false; + } + + var subscription = page.subscriptions[0]; + var confirmed = await ConfirmSubscriptionById(subscription.id); + return confirmed != null; + } + + public async Task IsSubscribedTo(int playerAliasId, bool confirmed) + { + Talo.IdentityCheck(); + + var options = new GetSubscriptionsOptions + { + confirmed = confirmed ? ConfirmedFilter.Confirmed : ConfirmedFilter.Any, + aliasId = playerAliasId + }; + var page = await GetSubscriptions(options); + + return page.subscriptions.Length > 0; + } + + public async Task GetSubscribers(GetSubscribersOptions options = null) + { + Talo.IdentityCheck(); + + options ??= new GetSubscribersOptions(); + + var queryString = options.ToQueryString(); + var uri = new Uri($"{baseUrl}/subscribers?{queryString}"); + var json = await Call(uri, "GET"); + return JsonUtility.FromJson(json); + } + + public async Task GetSubscriptions(GetSubscriptionsOptions options = null) + { + Talo.IdentityCheck(); + + options ??= new GetSubscriptionsOptions(); + + var queryString = options.ToQueryString(); + var uri = new Uri($"{baseUrl}/subscriptions?{queryString}"); + var json = await Call(uri, "GET"); + return JsonUtility.FromJson(json); + } + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerRelationshipsAPI.cs.meta b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerRelationshipsAPI.cs.meta new file mode 100644 index 0000000..542a817 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerRelationshipsAPI.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: aada1426a4fa2459090415b91be3085a \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/Entities/Player.cs b/Assets/Talo Game Services/Talo/Runtime/Entities/Player.cs index 30d8464..7d3e059 100644 --- a/Assets/Talo Game Services/Talo/Runtime/Entities/Player.cs +++ b/Assets/Talo Game Services/Talo/Runtime/Entities/Player.cs @@ -10,6 +10,7 @@ public class Player : EntityWithProps public string id; public PlayerAlias[] aliases; public GroupStub[] groups; + public PlayerPresence presence; public override string ToString() { diff --git a/Assets/Talo Game Services/Talo/Runtime/Entities/PlayerAliasSubscription.cs b/Assets/Talo Game Services/Talo/Runtime/Entities/PlayerAliasSubscription.cs new file mode 100644 index 0000000..eb5ad9a --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Entities/PlayerAliasSubscription.cs @@ -0,0 +1,37 @@ +using System; + +namespace TaloGameServices +{ + public enum RelationshipType + { + Unidirectional, + Bidirectional + } + + [Serializable] + public class PlayerAliasSubscription + { + public int id; + public PlayerAlias subscriber; + public PlayerAlias subscribedTo; + public bool confirmed; + public string relationshipType; + public string createdAt; + public string updatedAt; + + public RelationshipType GetRelationshipType() + { + return ParseRelationshipType(relationshipType); + } + + public static RelationshipType ParseRelationshipType(string type) + { + return type == "bidirectional" ? RelationshipType.Bidirectional : RelationshipType.Unidirectional; + } + + public static string RelationshipTypeToString(RelationshipType type) + { + return type == RelationshipType.Bidirectional ? "bidirectional" : "unidirectional"; + } + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/Entities/PlayerAliasSubscription.cs.meta b/Assets/Talo Game Services/Talo/Runtime/Entities/PlayerAliasSubscription.cs.meta new file mode 100644 index 0000000..fb548df --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Entities/PlayerAliasSubscription.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 3767fc32a8fbd46ba979a54af366df0f \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerRelationshipsSubscribeToRequest.cs b/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerRelationshipsSubscribeToRequest.cs new file mode 100644 index 0000000..c935873 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerRelationshipsSubscribeToRequest.cs @@ -0,0 +1,11 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class PlayerRelationshipsSubscribeToRequest + { + public int aliasId; + public string relationshipType; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerRelationshipsSubscribeToRequest.cs.meta b/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerRelationshipsSubscribeToRequest.cs.meta new file mode 100644 index 0000000..a0c5bf8 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerRelationshipsSubscribeToRequest.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 5c3956d63a59c4ccfad93741c33ac2b8 \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionResponse.cs b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionResponse.cs new file mode 100644 index 0000000..f2e3263 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionResponse.cs @@ -0,0 +1,10 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class PlayerRelationshipsSubscriptionResponse + { + public PlayerAliasSubscription subscription; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionResponse.cs.meta b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionResponse.cs.meta new file mode 100644 index 0000000..27fcaff --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionResponse.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0dc50abe8e00e4a188c188011520a29c \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionsListResponse.cs b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionsListResponse.cs new file mode 100644 index 0000000..6b4125c --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionsListResponse.cs @@ -0,0 +1,13 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class PlayerRelationshipsSubscriptionsListResponse + { + public PlayerAliasSubscription[] subscriptions; + public int count; + public int itemsPerPage; + public bool isLastPage; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionsListResponse.cs.meta b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionsListResponse.cs.meta new file mode 100644 index 0000000..afdf83e --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerRelationshipsSubscriptionsListResponse.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 990534281fb9f4a438f70a2d6d146cf4 \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketRequests/PlayerRelationshipsBroadcastRequest.cs b/Assets/Talo Game Services/Talo/Runtime/SocketRequests/PlayerRelationshipsBroadcastRequest.cs new file mode 100644 index 0000000..7373d0a --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketRequests/PlayerRelationshipsBroadcastRequest.cs @@ -0,0 +1,10 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class PlayerRelationshipsBroadcastRequest + { + public string message; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketRequests/PlayerRelationshipsBroadcastRequest.cs.meta b/Assets/Talo Game Services/Talo/Runtime/SocketRequests/PlayerRelationshipsBroadcastRequest.cs.meta new file mode 100644 index 0000000..7994d2d --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketRequests/PlayerRelationshipsBroadcastRequest.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cdd5217a603964f54b3ca295b13d1b4c \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsBroadcastResponse.cs b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsBroadcastResponse.cs new file mode 100644 index 0000000..996127c --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsBroadcastResponse.cs @@ -0,0 +1,11 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class PlayerRelationshipsBroadcastResponse + { + public PlayerAlias playerAlias; + public string message; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsBroadcastResponse.cs.meta b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsBroadcastResponse.cs.meta new file mode 100644 index 0000000..0a30436 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsBroadcastResponse.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 99985fbbbcfcb4bba84d4e6ca571c8d3 \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionConfirmedResponse.cs b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionConfirmedResponse.cs new file mode 100644 index 0000000..c81a7eb --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionConfirmedResponse.cs @@ -0,0 +1,10 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class PlayerRelationshipsSubscriptionConfirmedResponse + { + public PlayerAliasSubscription subscription; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionConfirmedResponse.cs.meta b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionConfirmedResponse.cs.meta new file mode 100644 index 0000000..24772de --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionConfirmedResponse.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: fc137b6d310744be28489f57e27a4c1b \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionCreatedResponse.cs b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionCreatedResponse.cs new file mode 100644 index 0000000..3e502fa --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionCreatedResponse.cs @@ -0,0 +1,10 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class PlayerRelationshipsSubscriptionCreatedResponse + { + public PlayerAliasSubscription subscription; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionCreatedResponse.cs.meta b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionCreatedResponse.cs.meta new file mode 100644 index 0000000..de8476a --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionCreatedResponse.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 1d1779e93040148cdb65de7a6f6daae3 \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionDeletedResponse.cs b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionDeletedResponse.cs new file mode 100644 index 0000000..509ee12 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionDeletedResponse.cs @@ -0,0 +1,10 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class PlayerRelationshipsSubscriptionDeletedResponse + { + public PlayerAliasSubscription subscription; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionDeletedResponse.cs.meta b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionDeletedResponse.cs.meta new file mode 100644 index 0000000..478a996 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/PlayerRelationshipsSubscriptionDeletedResponse.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f94ac5f1b5a7543b98d8aa851e3c296c \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/Talo.cs b/Assets/Talo Game Services/Talo/Runtime/Talo.cs index d902c88..e00efe3 100644 --- a/Assets/Talo Game Services/Talo/Runtime/Talo.cs +++ b/Assets/Talo Game Services/Talo/Runtime/Talo.cs @@ -37,6 +37,7 @@ internal static void InvokeConnectionRestored() internal static SocketTicketsAPI _socketTickets; internal static ChannelsAPI _channels; internal static PlayerPresenceAPI _playerPresence; + internal static PlayerRelationshipsAPI _playerRelationships; private static PlayerAlias _currentAlias; @@ -143,6 +144,11 @@ public static PlayerPresenceAPI PlayerPresence get => _playerPresence; } + public static PlayerRelationshipsAPI PlayerRelationships + { + get => _playerRelationships; + } + static Talo() { TaloManager tm; @@ -181,6 +187,7 @@ static Talo() _socketTickets = new SocketTicketsAPI(); _channels = new ChannelsAPI(); _playerPresence = new PlayerPresenceAPI(); + _playerRelationships = new PlayerRelationshipsAPI(); tm.OnReady(); diff --git a/Assets/Talo Game Services/Talo/Samples/FriendsDemo.meta b/Assets/Talo Game Services/Talo/Samples/FriendsDemo.meta new file mode 100644 index 0000000..112152f --- /dev/null +++ b/Assets/Talo Game Services/Talo/Samples/FriendsDemo.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6f23fcf3b48a84f15a50553578ffb61a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes.meta b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes.meta new file mode 100644 index 0000000..e3cf703 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 16656a23b2c92472086e73c1c608bc32 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes/FriendsDemo.unity b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes/FriendsDemo.unity new file mode 100644 index 0000000..46c4619 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes/FriendsDemo.unity @@ -0,0 +1,283 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 10 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 3 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 13 + m_BakeOnSceneLoad: 0 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 0 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 12 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_ReflectionCompression: 2 + m_MixedBakeMode: 2 + m_BakeBackend: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVREnvironmentMIS: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 1 + m_PVRFilteringGaussRadiusAO: 1 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 + m_LightingDataAsset: {fileID: 20201, guid: 0000000000000000f000000000000000, type: 0} + m_LightingSettings: {fileID: 0} +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 3 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + buildHeightMesh: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &459959530 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 459959533} + - component: {fileID: 459959532} + - component: {fileID: 459959531} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &459959531 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 459959530} + m_Enabled: 1 +--- !u!20 &459959532 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 459959530} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_FocusDistance: 10 + m_FocalLength: 50 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 1 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &459959533 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 459959530} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1888389462 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1888389464} + - component: {fileID: 1888389463} + - component: {fileID: 1888389465} + m_Layer: 0 + m_Name: UI + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1888389463 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1888389462} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0} + m_Name: + m_EditorClassIdentifier: + m_PanelSettings: {fileID: 11400000, guid: 227071aa7a6924fdf93576f323c32a39, type: 2} + m_ParentUI: {fileID: 0} + sourceAsset: {fileID: 9197481963319205126, guid: fd54348e2719f40edaef7bc2743a6526, type: 3} + m_SortingOrder: 0 + m_WorldSpaceSizeMode: 1 + m_WorldSpaceWidth: 1920 + m_WorldSpaceHeight: 1080 +--- !u!4 &1888389464 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1888389462} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1888389465 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1888389462} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 238f969cf577947939a3eddd70836800, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: + - {fileID: 459959533} + - {fileID: 1888389464} diff --git a/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes/FriendsDemo.unity.meta b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes/FriendsDemo.unity.meta new file mode 100644 index 0000000..94268ae --- /dev/null +++ b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scenes/FriendsDemo.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 55f71a0cb1edf4f208063eab3e6e47ef +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scripts.meta b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scripts.meta new file mode 100644 index 0000000..8bb6fe6 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a10fdd0f62e664a58970f226fee6181d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scripts/FriendsUIController.cs b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scripts/FriendsUIController.cs new file mode 100644 index 0000000..a05505e --- /dev/null +++ b/Assets/Talo Game Services/Talo/Samples/FriendsDemo/Scripts/FriendsUIController.cs @@ -0,0 +1,271 @@ +using UnityEngine; +using UnityEngine.UIElements; +using System.Threading.Tasks; + +namespace TaloGameServices.Sample.FriendsDemo +{ + [RequireComponent(typeof(UIDocument))] + public class FriendsUIController : MonoBehaviour + { + public const string LookingForFriendsStatus = "Looking for friends!"; + private static readonly string[] RandomNames = { "Alice", "Bob", "Carl", "Doric", "Eve", "Fred", "Gina", "Hank" }; + + private string playerName; + private PlayersManager playersManager; + private SubscriptionsManager subscriptionsManager; + private UIManager uiManager; + + private Label playerNameLabel; + private TextField broadcastInput; + + private async void Start() + { + InitializeManagers(); + ConnectEvents(); + await IdentifyPlayer(); + await FindOnlinePlayers(); + } + + private void InitializeManagers() + { + var root = GetComponent().rootVisualElement; + + // UI elements + playerNameLabel = root.Q