Repository URL to install this package:
Version:
2022.9.5 ▾
|
/*
* Copyright 2016 Game Server Services, Inc. or its affiliates. All Rights
* Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedAutoPropertyAccessor.Local
// ReSharper disable CheckNamespace
using System;
using System.Collections;
using Gs2.Core.Exception;
using Gs2.Unity.Gs2Chat.ScriptableObject;
using Gs2.Unity.UiKit.Gs2Chat.Fetcher;
using Gs2.Unity.Util;
using UnityEngine;
using UnityEngine.Events;
namespace Gs2.Unity.UiKit.Gs2Chat
{
[AddComponentMenu("GS2 UIKit/Chat/Gs2ChatRoomUnsubscribeAction")]
public partial class Gs2ChatRoomUnsubscribeAction : MonoBehaviour
{
private IEnumerator Process()
{
var future = _clientHolder.Gs2.Chat.Namespace(
_roomFetcher.room.Namespace.namespaceName
).Me(
_gameSessionHolder.GameSession
).Subscribe(
_roomFetcher.room.roomName
).Unsubscribe();
yield return future;
if (future.Error != null)
{
if (future.Error is TransactionException e)
{
IEnumerator Retry()
{
var retryFuture = e.Retry();
yield return retryFuture;
if (retryFuture.Error != null)
{
onError.Invoke(future.Error, Retry);
yield break;
}
onUnsubscribeComplete.Invoke(_roomFetcher.room);
}
onError.Invoke(future.Error, Retry);
yield break;
}
onError.Invoke(future.Error, null);
yield break;
}
onUnsubscribeComplete.Invoke(_roomFetcher.room);
}
public void OnEnable()
{
StartCoroutine(nameof(Process));
}
public void OnDisable()
{
StopCoroutine(nameof(Process));
}
}
/// <summary>
/// Dependent components
/// </summary>
public partial class Gs2ChatRoomUnsubscribeAction
{
private Gs2ClientHolder _clientHolder;
private Gs2GameSessionHolder _gameSessionHolder;
private Gs2ChatRoomFetcher _roomFetcher;
public void Awake()
{
_clientHolder = Gs2ClientHolder.Instance;
_gameSessionHolder = Gs2GameSessionHolder.Instance;
_roomFetcher = GetComponentInParent<Gs2ChatRoomFetcher>() ?? GetComponent<Gs2ChatRoomFetcher>();
}
}
/// <summary>
/// Public properties
/// </summary>
public partial class Gs2ChatRoomUnsubscribeAction
{
}
/// <summary>
/// Parameters for Inspector
/// </summary>
public partial class Gs2ChatRoomUnsubscribeAction
{
}
/// <summary>
/// Event handlers
/// </summary>
public partial class Gs2ChatRoomUnsubscribeAction
{
[Serializable]
private class UnsubscribeCompleteEvent : UnityEvent<Room>
{
}
[SerializeField]
private UnsubscribeCompleteEvent onUnsubscribeComplete = new UnsubscribeCompleteEvent();
public event UnityAction<Room> OnUnsubscribeComplete
{
add => onUnsubscribeComplete.AddListener(value);
remove => onUnsubscribeComplete.RemoveListener(value);
}
[SerializeField]
internal ErrorEvent onError = new ErrorEvent();
public event UnityAction<Gs2Exception, Func<IEnumerator>> OnError
{
add => onError.AddListener(value);
remove => onError.RemoveListener(value);
}
}
}