コード例 #1
0
ファイル: AccessTest.cs プロジェクト: aiczk/MoApi
        private void Awake()
        {
            access   = GetComponent <Access>();
            matching = GetComponent <Matching>();

            join
            .OnClickAsObservable()
            .Subscribe(async _ =>
            {
                roomName = await matching.Require();
                await matching.Join(roomName);
                await access.Join(roomName, PlayerInfo.Instance.PlayerIdentifier);
                Debug.Log("Join");
            });

            leave
            .OnClickAsObservable()
            .Subscribe(async _ =>
            {
                await access.Leave();
                await matching.Leave(roomName);
                Debug.Log("Leave");
            });

            access
            .JoinAsObservable
            .Subscribe(async player =>
            {
                Debug.Log($"{player.Name}が{roomName}に入室しました。");
                var currentCount = await matching.Count(roomName);
                Debug.Log($"現在部屋にいる人数は{currentCount.ToString()}人です。");
            });

            access
            .LeaveAsObservable
            .Subscribe(async player =>
            {
                Debug.Log($"{player.Name}が{roomName}を退室しました。");
                var currentCount = await matching.Count(roomName);
                Debug.Log($"現在部屋にいる人数は{currentCount.ToString()}人です。");
            });
        }