ゲームのアイデアと機能

次に追加する機能

フレンド

選択したプロジェクトのフレンド、申請、ブロック。

SDK:developプレイヤーセッションが必要
Unity
フレンドのイラスト
確認できる結果

タイムアウトや競合後は再取得して意図を確認します。新しいリビジョンで自動再試行しません。

動画は後日公開

この手順の動画はまだありません。ガイドとMCPへの依頼は利用できます。

フレンド

同じプロジェクトを準備する

  1. ゲームの設定と同じプロジェクトをダッシュボードで選択してください。

    フレンド →
  2. 最初のリクエストに追加の定義は不要です。対応するゲームデータがなければ、空の結果も正常です。

    同じプロジェクトで別々のプレイヤーセッションを2つ使います。ユーザー管理から相手の正確なUUIDをコピーします。

    正確なUUIDまたは正規Hコードを使用します。名前やメールは使用できません。

    ここでは閲覧のみです。関係を変更できるのは本人のプレイヤーセッションだけです。

この機能を実装する

ガイドは閲覧できます。実行には有効なプロジェクトキーが必要です。 プロジェクトを準備する

SDK をインストールし、プロジェクト設定をインポート済みで、プレイヤーがログインしていること。

この SDK サンプルは develop を使用します。必要な API がインストール済みの SDK にあるか確認してください。

クイックスタートで対象プレイヤーを接続します。ボタンやシーンの明示的な操作からRunReviewedAction()を呼び出してください。ファイルを開くだけではリクエストは送信されません。

C#
Assets/Scripts/FriendsDemo.cs
horizOn 呼び出し
1using UnityEngine;
2using PM.horizOn.Cloud.Core;
3using PM.horizOn.Cloud.Manager;
4​
5// Existing SDK/project configuration and authenticated player session required.
6// Call RunReviewedAction explicitly after reviewing this example and its data.
7// タイムアウトや競合後は再取得して意図を確認します。新しいリビジョンで自動再試行しません。
8public sealed class FriendsDemo : MonoBehaviour
9{
10 public async void RunReviewedAction()
11 {
12 var sessionUser = UserManager.Instance.CurrentUser;
13 if (sessionUser == null || !sessionUser.IsValid()) return;
14 var userId = UserManager.Instance.CurrentUser.UserId;
15 var manager = FriendsManager.Instance;
16 var loaded = await manager.GetFriends(userId);
17 if (!loaded.IsSuccess) { Debug.LogWarning(loaded.ErrorCode); return; }
18 Debug.Log(loaded.Data.friendCode); // Public identifier, not a credential.
19 foreach (var friend in loaded.Data.friends)
20 Debug.Log(friend.display.name + ": " + (friend.lastActiveAt ?? "unknown"));
21​
22 // Invoke only after the player explicitly reviews this snapshot and chooses an action.
23 async System.Threading.Tasks.Task ApplyReviewed(string action, string targetUserId,
24 long expectedRevision, string requestId = null)
25 {
26 var result = action switch {
27 "request" => await manager.SendRequest(userId, targetUserId, expectedRevision),
28 "accept" => await manager.AcceptRequest(userId, targetUserId, expectedRevision, requestId),
29 "decline" => await manager.DeclineRequest(userId, targetUserId, expectedRevision, requestId),
30 "cancel" => await manager.CancelRequest(userId, targetUserId, expectedRevision, requestId),
31 "remove" => await manager.RemoveFriend(userId, targetUserId, expectedRevision),
32 "block" => await manager.BlockPlayer(userId, targetUserId, expectedRevision),
33 "unblock" => await manager.UnblockPlayer(userId, targetUserId, expectedRevision),
34 _ => throw new System.ArgumentException("Unknown action")
35 };
36 if (!result.IsSuccess) {
37 Debug.LogWarning(result.ErrorCode); // Timeout/409: reload and reconcile; do not repeat automatically.
38 return;
39 }
40 Debug.Log(result.Data.revision); // Replace the whole displayed snapshot.
41 }
42 // Accept/decline: original incoming requestId. Cancel: original outgoing requestId.
43 // Never replace expectedRevision on an uncertain retry. A new request is a new identity.
44 // FindPlayer(userId, exactUuidOrHCode) never searches names or emails.
45 // Last login is nullable, never an online flag. No hidden polling timer.
46 }
47}
完全なSDKサンプルを開く ↗

新しい機能をテストしましょう。

タイムアウトや競合後は再取得して意図を確認します。新しいリビジョンで自動再試行しません。

ゲームの設定と同じプロジェクトをダッシュボードで選択してください。

エンドポイント
  • GET/friends
  • GET/friends/find
  • POST/friends/request
  • POST/friends/accept
  • POST/friends/decline
  • POST/friends/cancel
  • POST/friends/remove
  • POST/friends/block
  • POST/friends/unblock
API リファレンスのすべてのエンドポイント
次のステップへのおすすめ

毎ラウンドにハイスコアを。

ラウンド終了後にスコアを保存し、上位のプレイヤーを表示します。現在の接続とプレイヤーセッションを引き続き使用します。