Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
io.gs2.unity.sdk.uikit / Gs2Quest / Action / Gs2QuestProgressStartAction.cs
Size: Mime:
/*
 * 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.
 *
 * deny overwrite
 */
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedAutoPropertyAccessor.Local
// ReSharper disable CheckNamespace
// ReSharper disable RedundantNameQualifier
// ReSharper disable RedundantAssignment
// ReSharper disable NotAccessedVariable
// ReSharper disable RedundantUsingDirective
// ReSharper disable Unity.NoNullPropagation
// ReSharper disable InconsistentNaming

#pragma warning disable CS0472

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Gs2.Core.Exception;
using Gs2.Unity.Gs2Quest.Model;
using Gs2.Unity.Util;
using Gs2.Unity.UiKit.Core;
using Gs2.Unity.UiKit.Gs2Quest.Context;
using UnityEngine;
using UnityEngine.Events;
using Progress = Gs2.Unity.Gs2Quest.ScriptableObject.QuestGroupModel;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Gs2.Unity.UiKit.Gs2Quest
{
    public partial class Gs2QuestProgressStartAction : MonoBehaviour
    {
        private IEnumerator Process()
        {
            yield return new WaitUntil(() => this._clientHolder.Initialized);
            yield return new WaitUntil(() => this._gameSessionHolder.Initialized);
            
            var domain = this._clientHolder.Gs2.Quest.Namespace(
                this._context.QuestModel.NamespaceName
            ).Me(
                this._gameSessionHolder.GameSession
            );
            var future = domain.Start(
                QuestGroupName,
                QuestName,
                Force,
                Config.ToArray()
            );
            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)
                        {
                            this.onError.Invoke(future.Error, Retry);
                            yield break;
                        }
                        this.onStartComplete.Invoke(future.Result.TransactionId);
                    }

                    this.onError.Invoke(future.Error, Retry);
                    yield break;
                }

                this.onError.Invoke(future.Error, null);
                yield break;
            }
            this.onStartComplete.Invoke(future.Result.TransactionId);
        }

        public void OnEnable()
        {
            StartCoroutine(nameof(Process));
        }

        public void OnDisable()
        {
            StopCoroutine(nameof(Process));
        }
    }

    /// <summary>
    /// Dependent components
    /// </summary>

    public partial class Gs2QuestProgressStartAction
    {
        private Gs2ClientHolder _clientHolder;
        private Gs2GameSessionHolder _gameSessionHolder;
        private Gs2QuestQuestModelContext _context;

        public void Awake()
        {
            this._clientHolder = Gs2ClientHolder.Instance;
            this._gameSessionHolder = Gs2GameSessionHolder.Instance;
            this._context = GetComponent<Gs2QuestQuestModelContext>() ?? GetComponentInParent<Gs2QuestQuestModelContext>();

            if (_context == null) {
                Debug.LogError($"{gameObject.GetFullPath()}: Couldn't find the Gs2QuestQuestModelContext.");
                enabled = false;
            }
        }

        public bool HasError()
        {
            this._context = GetComponent<Gs2QuestQuestModelContext>() ?? GetComponentInParent<Gs2QuestQuestModelContext>(true);
            if (_context == null) {
                return true;
            }
            return false;
        }
    }

    /// <summary>
    /// Public properties
    /// </summary>

    public partial class Gs2QuestProgressStartAction
    {

    }

    /// <summary>
    /// Parameters for Inspector
    /// </summary>
    public partial class Gs2QuestProgressStartAction
    {
        public string QuestGroupName;
        public string QuestName;
        public bool Force;
        public List<Gs2.Unity.Gs2Quest.Model.EzConfig> Config;

        public void SetQuestGroupName(string value) {
            QuestGroupName = value;
            this.onChangeQuestGroupName.Invoke(QuestGroupName);
        }

        public void SetQuestName(string value) {
            QuestName = value;
            this.onChangeQuestName.Invoke(QuestName);
        }

        public void SetForce(bool value) {
            Force = value;
            this.onChangeForce.Invoke(Force);
        }

        public void SetConfig(List<Gs2.Unity.Gs2Quest.Model.EzConfig> value) {
            Config = value;
            this.onChangeConfig.Invoke(Config);
        }
    }

    /// <summary>
    /// Event handlers
    /// </summary>
    public partial class Gs2QuestProgressStartAction
    {

        [Serializable]
        private class ChangeQuestGroupNameEvent : UnityEvent<string>
        {

        }

        [SerializeField]
        private ChangeQuestGroupNameEvent onChangeQuestGroupName = new ChangeQuestGroupNameEvent();
        public event UnityAction<string> OnChangeQuestGroupName
        {
            add => this.onChangeQuestGroupName.AddListener(value);
            remove => this.onChangeQuestGroupName.RemoveListener(value);
        }

        [Serializable]
        private class ChangeQuestNameEvent : UnityEvent<string>
        {

        }

        [SerializeField]
        private ChangeQuestNameEvent onChangeQuestName = new ChangeQuestNameEvent();
        public event UnityAction<string> OnChangeQuestName
        {
            add => this.onChangeQuestName.AddListener(value);
            remove => this.onChangeQuestName.RemoveListener(value);
        }

        [Serializable]
        private class ChangeForceEvent : UnityEvent<bool>
        {

        }

        [SerializeField]
        private ChangeForceEvent onChangeForce = new ChangeForceEvent();
        public event UnityAction<bool> OnChangeForce
        {
            add => this.onChangeForce.AddListener(value);
            remove => this.onChangeForce.RemoveListener(value);
        }

        [Serializable]
        private class ChangeConfigEvent : UnityEvent<List<Gs2.Unity.Gs2Quest.Model.EzConfig>>
        {

        }

        [SerializeField]
        private ChangeConfigEvent onChangeConfig = new ChangeConfigEvent();
        public event UnityAction<List<Gs2.Unity.Gs2Quest.Model.EzConfig>> OnChangeConfig
        {
            add => this.onChangeConfig.AddListener(value);
            remove => this.onChangeConfig.RemoveListener(value);
        }

        [Serializable]
        private class StartCompleteEvent : UnityEvent<string>
        {

        }

        [SerializeField]
        private StartCompleteEvent onStartComplete = new StartCompleteEvent();
        public event UnityAction<string> OnStartComplete
        {
            add => this.onStartComplete.AddListener(value);
            remove => this.onStartComplete.RemoveListener(value);
        }

        [SerializeField]
        internal ErrorEvent onError = new ErrorEvent();

        public event UnityAction<Gs2Exception, Func<IEnumerator>> OnError
        {
            add => this.onError.AddListener(value);
            remove => this.onError.RemoveListener(value);
        }
    }

#if UNITY_EDITOR

    /// <summary>
    /// Context Menu
    /// </summary>
    public partial class Gs2QuestProgressStartAction
    {
        [MenuItem("GameObject/Game Server Services/Quest/Progress/Action/Start", priority = 0)]
        private static void CreateButton()
        {
            var prefab = AssetDatabase.LoadAssetAtPath<Gs2QuestProgressStartAction>(
                "Packages/io.gs2.unity.sdk.uikit/Gs2Quest/Prefabs/Action/Gs2QuestProgressStartAction.prefab"
            );

            var instance = PrefabUtility.InstantiatePrefab(prefab, Selection.activeTransform);

            Undo.RegisterCreatedObjectUndo(instance, $"Create {instance.name}");
            Selection.activeObject = instance;
        }
    }
#endif
}