Ejemplo n.º 1
0
        /// <summary>
        /// GS2-Realtime のギャザリング情報から GS2-Realtime のルーム情報を取得
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public IEnumerator GetRoom(
            UnityAction <AsyncResult <EzGetRoomResult> > callback
            )
        {
            Validate();

            var request = Gs2Util.LoadGlobalGameObject <RealtimeRequest>("RealtimeRequest");

            AsyncResult <EzGetRoomResult> result = null;

            yield return(gs2Client.client.Realtime.GetRoom(
                             r => { result = r; },
                             gs2RealtimeSetting.realtimeNamespaceName,
                             request.gatheringId
                             ));

            if (result.Error != null)
            {
                gs2RealtimeSetting.onError.Invoke(
                    result.Error
                    );
                callback.Invoke(result);
                yield break;
            }

            gs2RealtimeSetting.onGetRoom.Invoke(result.Result.Item);

            callback.Invoke(result);
        }
Ejemplo n.º 2
0
    public void OnLogin(EzAccount account, GameSession session)
    {
        var request = Gs2Util.LoadGlobalResource <AccountTakeOverRequest>("AccountTakeOverRequest");

        request.gameSession = session;
        SceneManager.LoadScene("AccountTakeOver");
    }
        /// <summary>
        /// 設定済みの引継ぎ設定一覧を取得
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public IEnumerator ListAccountTakeOverSettings(
            UnityAction <AsyncResult <EzListTakeOverSettingsResult> > callback
            )
        {
            Validate();

            var request = Gs2Util.LoadGlobalGameObject <AccountTakeOverRequest>("AccountTakeOverRequest");

            AsyncResult <EzListTakeOverSettingsResult> result = null;

            yield return(gs2Client.client.Account.ListTakeOverSettings(
                             r => { result = r; },
                             request.gameSession,
                             gs2AccountSetting.accountNamespaceName
                             ));

            if (result.Error != null)
            {
                gs2AccountTakeOverSetting.onError.Invoke(
                    result.Error
                    );
                callback.Invoke(result);
                yield break;
            }

            callback.Invoke(result);
        }
        /// <summary>
        /// マッチメイキングをキャンセルしたとき
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public IEnumerator CancelMatchmaking(
            UnityAction <AsyncResult <EzCancelMatchmakingResult> > callback
            )
        {
            Validate();

            var request = Gs2Util.LoadGlobalGameObject <MatchmakingRequest>("MatchmakingRequest");

            AsyncResult <EzCancelMatchmakingResult> result = null;

            yield return(gs2Client.client.Matchmaking.CancelMatchmaking(
                             r => { result = r; },
                             request.gameSession,
                             gs2MatchmakingSetting.matchmakingNamespaceName,
                             _gathering.Name
                             ));

            if (result.Error != null)
            {
                gs2MatchmakingSetting.onError.Invoke(
                    result.Error
                    );
                callback.Invoke(result);
                yield break;
            }

            gs2MatchmakingSetting.onMatchmakingCancel.Invoke(
                _gathering
                );

            _gathering = null;

            callback.Invoke(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// ステートに対応したメニューパネルを取得
        /// </summary>
        /// <param name="state">ステート</param>
        /// <returns>メニューパネル</returns>
        private GameObject GetMenuGameObject(MatchmakingStateMachine.State state)
        {
            switch (state)
            {
            case MatchmakingStateMachine.State.MainMenu:
                var request = Gs2Util.LoadGlobalGameObject <MatchmakingRequest>("MatchmakingRequest");
                userId.text = "UserId: " + request.gameSession.AccessToken.UserId;
                return(transform.Find("MainMenu").gameObject);

            case MatchmakingStateMachine.State.CreateGatheringMenu:
                return(transform.Find("CreateGatheringMenu").gameObject);

            case MatchmakingStateMachine.State.Matchmaking:
                return(transform.Find("Matchmaking").gameObject);

            case MatchmakingStateMachine.State.GatheringNotFound:
                return(transform.Find("GatheringNotFound").gameObject);

            case MatchmakingStateMachine.State.MatchmakingComplete:
                return(transform.Find("Complete").gameObject);

            case MatchmakingStateMachine.State.Error:
                return(transform.Find("Error").gameObject);

            default:
                return(transform.Find("Processing").gameObject);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// スタミナ値を消費(非推奨 サービス間の連携(スタンプシート)を経由してスタミナ値を操作するほうが望ましい)
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="consumeValue"></param>
        /// <returns></returns>
        public IEnumerator ConsumeStamina(
            UnityAction <AsyncResult <EzConsumeResult> > callback,
            int consumeValue
            )
        {
            var request = Gs2Util.LoadGlobalGameObject <StaminaRequest>("StaminaRequest");

            AsyncResult <EzConsumeResult> result = null;

            yield return(gs2Client.client.Stamina.Consume(
                             r => { result = r; },
                             request.gameSession,
                             gs2StaminaSetting.staminaNamespaceName,
                             gs2StaminaSetting.staminaName,
                             consumeValue
                             ));

            if (result.Error != null)
            {
                gs2StaminaSetting.onError.Invoke(
                    result.Error
                    );
                callback.Invoke(result);
                yield break;
            }

            gs2StaminaSetting.onGetStamina.Invoke(result.Result.Item);

            callback.Invoke(result);
        }
        private void OnListGroupQuestModelFunc(List <EzQuestGroupModel> questGroups)
        {
            if (questGroupsViewPort != null)
            {
                for (int i = 0; i < questGroupsViewPort.transform.childCount; i++)
                {
                    Destroy(questGroupsViewPort.transform.GetChild(i).gameObject);
                }

                foreach (var questGroup in questGroups)
                {
                    var questType = Gs2Util.LoadGlobalResource <QuestGroupView>();
                    questType.transform.SetParent(questGroupsViewPort.transform);
                    questType.Initialize(new QuestGroupInformation(questGroup));
                    questType.transform.localScale = new Vector3(1, 1, 1);
                    questType.transform.GetComponentInChildren <Button>().onClick.AddListener(
                        () =>
                    {
                        _currentCompletedQuestList = _completedQuestLists.Find(completedQuestList =>
                                                                               completedQuestList.QuestGroupName == questGroup.Name);

                        ClickToSelect(questGroup);
                    }
                        );
                    questType.gameObject.SetActive(true);
                }
            }
        }
        private void OnGetProducts(List <Product> products)
        {
            if (productViewPort != null)
            {
                for (int i = 0; i < productViewPort.transform.childCount; i++)
                {
                    Destroy(productViewPort.transform.GetChild(i).gameObject);
                }

                foreach (var product in products)
                {
                    var productView = Gs2Util.LoadGlobalResource <ProductView>();
                    productView.transform.SetParent(productViewPort.transform);
                    productView.Initialize(product);
                    productView.transform.localScale = new Vector3(1, 1, 1);
                    if (!productView.Sold)
                    {
                        productView.transform.GetComponentInChildren <Button>().onClick.AddListener(
                            () =>
                        {
                            ClickToBuy(product);
                        }
                            );
                    }
                }
            }
        }
Ejemplo n.º 9
0
    public void OnLogin(EzAccount account, GameSession session)
    {
        var request = Gs2Util.LoadGlobalResource <MatchmakingRequest>("MatchmakingRequest");

        request.gameSession = session;
        SceneManager.LoadScene("Matchmaking");
    }
Ejemplo n.º 10
0
    public void OnLogin(EzAccount account, GameSession session)
    {
        var request = Gs2Util.LoadGlobalResource <MoneyRequest>("MoneyRequest");

        request.gameSession = session;
        StartCoroutine(LoadScene());
    }
Ejemplo n.º 11
0
    public void OnCompleteMatchmaking(EzGathering gathering, List <string> joinPlayerIds)
    {
        var request = Gs2Util.LoadGlobalResource <RealtimeRequest>("RealtimeRequest");

        request.gameSession = _gameSession;
        request.gatheringId = gathering.Name;
        SceneManager.LoadScene("Realtime");
    }
Ejemplo n.º 12
0
 public void OnLogin(EzAccount account, GameSession session)
 {
     {
         var request = Gs2Util.LoadGlobalResource <MoneyRequest>("MoneyRequest");
         request.gameSession = session;
     }
     {
         var request = Gs2Util.LoadGlobalResource <StaminaRequest>("StaminaRequest");
         request.gameSession = session;
     }
     SceneManager.LoadScene("Stamina");
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 初期化処理
        /// </summary>
        /// <returns></returns>
        public void Initialize()
        {
            if (!gs2QuestSetting)
            {
                gs2QuestSetting = Gs2Util.LoadGlobalGameObject <Gs2QuestSetting>("Gs2Settings");
            }

            if (!gs2Client)
            {
                gs2Client = Gs2Util.LoadGlobalGameObject <Gs2Client>("Gs2Settings");
            }
        }
        private void Validate()
        {
            if (!gs2MatchmakingSetting)
            {
                gs2MatchmakingSetting = Gs2Util.LoadGlobalGameObject <Gs2MatchmakingSetting>("Gs2Settings");
            }

            if (!gs2Client)
            {
                gs2Client = Gs2Util.LoadGlobalGameObject <Gs2Client>("Gs2Settings");
            }
        }
Ejemplo n.º 15
0
 public void OnPlayGameHandler()
 {
     if (_stateMachine.PlayGame())
     {
         var widget        = Gs2Util.LoadGlobalResource <PlayGameWidget>();
         var parent        = GameObject.Find("PlayGameHolder");
         var rectTransform = (RectTransform)widget.transform;
         rectTransform.SetParent(parent.transform);
         rectTransform.position   = parent.transform.position;
         rectTransform.sizeDelta  = new Vector2();
         rectTransform.localScale = new Vector3(1, 1, 1);
         widget.gameObject.SetActive(true);
     }
 }
        /// <summary>
        /// 既存のギャザリングに参加する
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public IEnumerator SimpleMatchmakingJoinGathering(
            UnityAction <AsyncResult <EzDoMatchmakingResult> > callback
            )
        {
            Validate();

            var request = Gs2Util.LoadGlobalGameObject <MatchmakingRequest>("MatchmakingRequest");

            AsyncResult <EzDoMatchmakingResult> result = null;
            string contextToken = null;

            while (true)
            {
                yield return(gs2Client.client.Matchmaking.DoMatchmaking(
                                 r => { result = r; },
                                 request.gameSession,
                                 gs2MatchmakingSetting.matchmakingNamespaceName,
                                 new EzPlayer
                {
                    RoleName = "default"
                },
                                 contextToken
                                 ));

                if (result.Error != null)
                {
                    gs2MatchmakingSetting.onError.Invoke(
                        result.Error
                        );

                    callback.Invoke(result);
                    yield break;
                }

                if (result.Result.Item != null)
                {
                    _gathering = result.Result.Item;
                    callback.Invoke(result);

                    if (_complete)
                    {
                        gs2MatchmakingSetting.onMatchmakingComplete.Invoke(_gathering, _joinedPlayerIds);
                    }

                    yield break;
                }

                contextToken = result.Result.MatchmakingContextToken;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 誰でもいいので参加者を募集するギャザリングを新規作成
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="capacity"></param>
        /// <returns></returns>
        public IEnumerator SimpleMatchmakingCreateGathering(
            UnityAction <AsyncResult <EzCreateGatheringResult> > callback,
            int capacity
            )
        {
            Validate();

            var request = Gs2Util.LoadGlobalGameObject <MatchmakingRequest>("MatchmakingRequest");

            AsyncResult <EzCreateGatheringResult> result = null;

            yield return(gs2Client.client.Matchmaking.CreateGathering(
                             r => { result = r; },
                             request.gameSession,
                             gs2MatchmakingSetting.matchmakingNamespaceName,
                             new EzPlayer
            {
                RoleName = "default"
            },
                             new List <EzCapacityOfRole>
            {
                new EzCapacityOfRole
                {
                    RoleName = "default",
                    Capacity = capacity
                },
            },
                             new List <EzAttributeRange>(),
                             new List <string>(),
                             null
                             ));

            if (result.Error != null)
            {
                gs2MatchmakingSetting.onError.Invoke(
                    result.Error
                    );
                callback.Invoke(result);
                yield break;
            }

            _joinedPlayerIds.Clear();
            _gathering = result.Result.Item;
            _joinedPlayerIds.Add(request.gameSession.AccessToken.UserId);

            gs2MatchmakingSetting.onUpdateJoinedPlayerIds.Invoke(_gathering, _joinedPlayerIds);

            callback.Invoke(result);
        }
        private void Validate()
        {
            if (!gs2AccountSetting)
            {
                gs2AccountSetting = Gs2Util.LoadGlobalGameObject <Gs2AccountSetting>("Gs2Settings");
            }

            if (!gs2AccountTakeOverSetting)
            {
                gs2AccountTakeOverSetting = Gs2Util.LoadGlobalGameObject <Gs2AccountTakeOverSetting>("Gs2Settings");
            }

            if (!gs2Client)
            {
                gs2Client = Gs2Util.LoadGlobalGameObject <Gs2Client>("Gs2Settings");
            }
        }
        /// <summary>
        /// GS2-Realtime のルーム情報を取得
        /// </summary>
        /// <param name="animator"></param>
        /// <returns></returns>
        private IEnumerator GetRoom(
            Animator animator
            )
        {
            var request = Gs2Util.LoadGlobalGameObject <RealtimeRequest>("RealtimeRequest");

            if (!string.IsNullOrEmpty(request.ipAddress))
            {
                room = new EzRoom
                {
                    Name          = request.gatheringId,
                    IpAddress     = request.ipAddress,
                    Port          = request.port,
                    EncryptionKey = request.encryptionKey,
                };
                animator.SetTrigger(Trigger.GetRoomSucceed.ToString());
                yield break;
            }
            while (true)
            {
                yield return(new WaitForSeconds(0.5f));

                AsyncResult <EzGetRoomResult> result = null;
                yield return(controller.GetRoom(
                                 r => { result = r; }
                                 ));

                if (result.Error != null)
                {
                    animator.SetTrigger(Trigger.GetRoomFailed.ToString());
                    yield break;
                }

                if (!string.IsNullOrEmpty(result.Result.Item.IpAddress))
                {
                    room = result.Result.Item;
                    break;
                }
            }

            animator.SetTrigger(Trigger.GetRoomSucceed.ToString());
        }
        private void OnListQuestModel(List <EzQuestModel> quests)
        {
            if (questsViewPort != null)
            {
                for (int i = 0; i < questsViewPort.transform.childCount; i++)
                {
                    Destroy(questsViewPort.transform.GetChild(i).gameObject);
                }

                foreach (var quest in quests)
                {
                    var questType = Gs2Util.LoadGlobalResource <QuestView>();
                    questType.transform.SetParent(questsViewPort.transform);
                    questType.Initialize(new QuestInformation(quest, _currentCompletedQuestList));
                    questType.transform.localScale = new Vector3(1, 1, 1);
                    questType.transform.GetComponentInChildren <Button>().onClick.AddListener(
                        () =>
                    {
                        ClickToSelect(quest);
                    }
                        );
                }
            }
        }
        /// <summary>
        /// 既存のギャザリングに参加する
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="type"></param>
        /// <param name="userIdentifier"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public IEnumerator AddAccountTakeOverSetting(
            UnityAction <AsyncResult <EzAddTakeOverSettingResult> > callback,
            int type,
            string userIdentifier,
            string password
            )
        {
            Validate();

            var request = Gs2Util.LoadGlobalGameObject <AccountTakeOverRequest>("AccountTakeOverRequest");

            AsyncResult <EzAddTakeOverSettingResult> result = null;

            yield return(gs2Client.client.Account.AddTakeOverSetting(
                             r => { result = r; },
                             request.gameSession,
                             gs2AccountSetting.accountNamespaceName,
                             type,
                             userIdentifier,
                             password
                             ));

            if (result.Error != null)
            {
                gs2AccountTakeOverSetting.onError.Invoke(
                    result.Error
                    );
                callback.Invoke(result);
                yield break;
            }

            gs2AccountTakeOverSetting.onSetTakeOver.Invoke(
                result.Result.Item
                );
            callback.Invoke(result);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// GS2-Realtime のルームを作成
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="ipAddress"></param>
        /// <param name="port"></param>
        /// <param name="encryptionKey"></param>
        /// <returns></returns>
        public IEnumerator ConnectRoom(
            UnityAction <AsyncResult <RelayRealtimeSession> > callback,
            string ipAddress,
            int port,
            string encryptionKey
            )
        {
            var request = Gs2Util.LoadGlobalGameObject <RealtimeRequest>("RealtimeRequest");

            var session = new RelayRealtimeSession(
                request.gameSession.AccessToken.Token,
                ipAddress,
                port,
                encryptionKey,
                ByteString.CopyFrom()
                );

            session.OnRelayMessage += message =>
            {
                gs2RealtimeSetting.onRelayMessage.Invoke(message);
            };
            session.OnJoinPlayer += player =>
            {
                gs2RealtimeSetting.onJoinPlayer.Invoke(player);
            };
            session.OnLeavePlayer += player =>
            {
                gs2RealtimeSetting.onLeavePlayer.Invoke(player);
            };
            session.OnGeneralError += args =>
            {
                gs2RealtimeSetting.onGeneralError.Invoke(args);
            };
            session.OnError += error =>
            {
                gs2RealtimeSetting.onRelayError.Invoke(error);
            };
            session.OnUpdateProfile += player =>
            {
                gs2RealtimeSetting.onUpdateProfile.Invoke(player);
            };
            session.OnClose += args =>
            {
                gs2RealtimeSetting.onClose.Invoke(args);
            };

            AsyncResult <bool> result = null;

            yield return(session.Connect(
                             this,
                             r =>
            {
                result = r;
            }
                             ));

            if (session.Connected)
            {
                callback.Invoke(
                    new AsyncResult <RelayRealtimeSession>(session, null)
                    );
            }
            else
            {
                gs2RealtimeSetting.onError.Invoke(
                    result.Error
                    );
                callback.Invoke(
                    new AsyncResult <RelayRealtimeSession>(null, result.Error)
                    );
            }
        }
Ejemplo n.º 23
0
        private void Start()
        {
            var animator = GetComponent <Animator>();

            if (animator == null)
            {
                throw new InvalidProgramException(
                          "'QuestSceneStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'QuestSceneStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }

            _stateMachine = animator.GetBehaviour <QuestSceneStateMachine>();
            if (_stateMachine == null)
            {
                throw new InvalidProgramException(
                          "'QuestSceneStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'QuestSceneStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }

            _stateMachine.moneyController.Initialize();
            _stateMachine.moneyController.gs2MoneySetting.onBuy.AddListener(
                product =>
            {
                GameObject.Find("Gs2StaminaInternalSetting").GetComponent <Gs2StaminaInternalSetting>().onRefreshStatus.Invoke();
            }
                );
            _stateMachine.moneyController.gs2MoneySetting.onError.AddListener(
                e =>
            {
                if (errorMessage != null)
                {
                    errorMessage.text = e.Message;

                    var stateMachine = GetComponent <Animator>();
                    stateMachine.SetTrigger(QuestSceneStateMachine.Trigger.Error.ToString());
                }
            }
                );

            _stateMachine.staminaController.Initialize();
            _stateMachine.staminaController.gs2StaminaSetting.onBuy.AddListener(
                () =>
            {
                GameObject.Find("Gs2MoneyInternalSetting").GetComponent <Gs2MoneyInternalSetting>().onRefreshStatus.Invoke();
            }
                );
            _stateMachine.staminaController.gs2StaminaSetting.onError.AddListener(
                e =>
            {
                if (errorMessage != null)
                {
                    errorMessage.text = e.Message;

                    var stateMachine = GetComponent <Animator>();
                    stateMachine.SetTrigger(QuestSceneStateMachine.Trigger.Error.ToString());
                }
            }
                );

            _stateMachine.questController.Initialize();
            _stateMachine.questController.gs2QuestSetting.onStart.AddListener(
                progress =>
            {
                GameObject.Find("Gs2MoneyInternalSetting").GetComponent <Gs2MoneyInternalSetting>().onRefreshStatus.Invoke();
                GameObject.Find("Gs2StaminaInternalSetting").GetComponent <Gs2StaminaInternalSetting>().onRefreshStatus.Invoke();
            }
                );
            _stateMachine.questController.gs2QuestSetting.onEnd.AddListener(
                (progress, rewards, isComplete) =>
            {
                GameObject.Find("Gs2MoneyInternalSetting").GetComponent <Gs2MoneyInternalSetting>().onRefreshStatus.Invoke();
                GameObject.Find("Gs2StaminaInternalSetting").GetComponent <Gs2StaminaInternalSetting>().onRefreshStatus.Invoke();
            }
                );
            _stateMachine.questController.gs2QuestSetting.onError.AddListener(
                e =>
            {
                if (errorMessage != null)
                {
                    errorMessage.text = e.Message;

                    var stateMachine = GetComponent <Animator>();
                    stateMachine.SetTrigger(QuestSceneStateMachine.Trigger.Error.ToString());
                }
            }
                );

            GameObject.Find("Gs2QuestInternalSetting").GetComponent <Gs2QuestInternalSetting>().onFewStamina.AddListener(
                () =>
            {
                GameObject.Find("Gs2StaminaInternalSetting").GetComponent <Gs2StaminaInternalSetting>().onOpenStore.Invoke();
            }
                );

            _stateMachine.onChangeState.AddListener(
                (_, state) =>
            {
                InActiveAll();
                GetMenuGameObject(state).SetActive(true);
            }
                );

            var gs2Client = Gs2Util.LoadGlobalGameObject <Gs2Client>("Gs2Settings");
            var request   = Gs2Util.LoadGlobalGameObject <QuestRequest>("QuestRequest");

            if (request != null)
            {
                var executor = GameObject.Find("Gs2QuestInternalSetting").GetComponent <JobQueueExecutor>();
                if (string.IsNullOrEmpty(executor.jobQueueNamespaceName))
                {
                    executor.jobQueueNamespaceName = _stateMachine.questController.gs2QuestSetting.jobQueueNamespaceName;
                }
                executor.onResult.AddListener(
                    (job, statusCode, result) =>
                {
                    GameObject.Find("Gs2MoneyInternalSetting").GetComponent <Gs2MoneyInternalSetting>().onRefreshStatus.Invoke();
                    GameObject.Find("Gs2StaminaInternalSetting").GetComponent <Gs2StaminaInternalSetting>().onRefreshStatus.Invoke();
                }
                    );
                executor.onError.AddListener(
                    e =>
                {
                    if (errorMessage != null)
                    {
                        errorMessage.text = e.Message;

                        var stateMachine = GetComponent <Animator>();
                        stateMachine.SetTrigger(QuestSceneStateMachine.Trigger.Error.ToString());
                    }
                }
                    );
                StartCoroutine(
                    executor.Exec(
                        gs2Client.profile,
                        request.gameSession
                        )
                    );
            }

            InActiveAll();
        }
        private void Start()
        {
            controller.Initialize();

            if (controller.gs2AccountTakeOverSetting == null)
            {
                throw new InvalidProgramException("'Gs2AccountTakeOverSetting' is not null.");
            }
            if (controller.gs2Client == null)
            {
                controller.gs2Client = Gs2Util.LoadGlobalGameObject <Gs2Client>("Gs2Client");
                if (controller.gs2Client == null)
                {
                    throw new InvalidProgramException(
                              "Unable to find GS2 Client" +
                              "You need to set GS2 Client on 'AccountTakeOverController' or place a GameObject named 'Gs2Client' in the scene." +
                              "Please check README.md for details." +
                              " / " +
                              "GS2 Client を見つけられません。" +
                              "'AccountTakeOverController' に GS2 Client を設定するか、'Gs2Client' という名前の GameObject をシーン内に配置する必要があります。" +
                              "詳しくは README.md をご確認ください。"
                              );
                }
            }

            var animator = GetComponent <Animator>();

            if (animator == null)
            {
                throw new InvalidProgramException(
                          "'AccountTakeOverStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'AccountTakeOverStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }
            _stateMachine = animator.GetBehaviour <AccountTakeOverStateMachine>();
            if (_stateMachine == null)
            {
                throw new InvalidProgramException(
                          "'AccountTakeOverStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'AccountTakeOverStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }

            _stateMachine.controller = controller;
            _stateMachine.onChangeState.AddListener(
                (_, state) =>
            {
                if (state == AccountTakeOverStateMachine.State.SelectSetTakeOverType)
                {
                    if (_stateMachine.GetEmailTakeOverSetting() != null)
                    {
                        emailTakeOverButtonLabel.text = "Email - Registered";
                    }
                    else
                    {
                        emailTakeOverButtonLabel.text = "Email";
                    }
                    if (_stateMachine.GetPlatformTakeOverSetting() != null)
                    {
                        platformTakeOverButtonLabel.text = "Game Center - Registered";
#if UNITY_ANDROID
                        platformTakeOverButtonLabel.text = "Google Play - Registered";
#endif
                    }
                    else
                    {
                        platformTakeOverButtonLabel.text = "Game Center";
#if UNITY_ANDROID
                        platformTakeOverButtonLabel.text = "Google Play";
#endif
                    }
                }
                if (state == AccountTakeOverStateMachine.State.SetPlatformTakeOver)
                {
                    if (Social.localUser.authenticated)
                    {
                        _stateMachine.userIdentifier = Social.localUser.id;
                        _stateMachine.password       = Social.localUser.id;
                        animator.SetTrigger(AccountTakeOverStateMachine.Trigger.ReadySetTakeOver.ToString());
                    }
                    else
                    {
                        errorMessage.text = "Not logged in to Game Center";
#if UNITY_ANDROID
                        errorMessage.text = "Not logged in to Google Play Game Services";
#endif
                        animator.SetTrigger(AccountTakeOverStateMachine.Trigger.NotPlatformLogin.ToString());
                    }
                }

                if (state == AccountTakeOverStateMachine.State.DoPlatformTakeOver)
                {
                    if (Social.localUser.authenticated)
                    {
                        _stateMachine.userIdentifier = Social.localUser.id;
                        _stateMachine.password       = Social.localUser.id;
                        animator.SetTrigger(AccountTakeOverStateMachine.Trigger.ReadyDoTakeOver.ToString());
                    }
                    else
                    {
                        errorMessage.text = "Not logged in to Game Center";
#if UNITY_ANDROID
                        errorMessage.text = "Not logged in to Google Play Game Services";
#endif
                        animator.SetTrigger(AccountTakeOverStateMachine.Trigger.NotPlatformLogin.ToString());
                    }
                }
                InActiveAll();
                GetMenuGameObject(state).SetActive(true);
            }
                );

            controller.gs2AccountTakeOverSetting.onError.AddListener(
                e =>
            {
                if (errorMessage != null)
                {
                    errorMessage.text = e.Message;
                }
            }
                );

            // 画面の初期状態を設定
            InActiveAll();
        }
Ejemplo n.º 25
0
        /// <summary>
        /// スタミナを購入する
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public IEnumerator Buy(
            UnityAction <AsyncResult <object> > callback
            )
        {
            var request = Gs2Util.LoadGlobalGameObject <StaminaRequest>("StaminaRequest");

            string stampSheet = null;

            {
                AsyncResult <EzExchangeResult> result = null;
                yield return(gs2Client.client.Exchange.Exchange(
                                 r => { result = r; },
                                 request.gameSession,
                                 gs2StaminaSetting.exchangeNamespaceName,
                                 gs2StaminaSetting.exchangeRateName,
                                 1,
                                 new List <Gs2.Unity.Gs2Exchange.Model.EzConfig>
                {
                    new Gs2.Unity.Gs2Exchange.Model.EzConfig
                    {
                        Key = "slot",
                        Value = MoneyController.Slot.ToString(),
                    }
                }
                                 ));

                if (result.Error != null)
                {
                    gs2StaminaSetting.onError.Invoke(
                        result.Error
                        );
                    callback.Invoke(new AsyncResult <object>(null, result.Error));
                    yield break;
                }

                stampSheet = result.Result.StampSheet;
            }
            {
                var machine = new StampSheetStateMachine(
                    stampSheet,
                    gs2Client.client,
                    gs2StaminaSetting.distributorNamespaceName,
                    gs2StaminaSetting.exchangeKeyId
                    );

                Gs2Exception exception = null;
                void OnError(Gs2Exception e)
                {
                    exception = e;
                }

                gs2StaminaSetting.onError.AddListener(OnError);
                yield return(machine.Execute(gs2StaminaSetting.onError));

                gs2StaminaSetting.onError.RemoveListener(OnError);

                if (exception != null)
                {
                    callback.Invoke(new AsyncResult <object>(null, exception));
                    yield break;
                }
            }

            gs2StaminaSetting.onBuy.Invoke();

            callback.Invoke(new AsyncResult <object>(null, null));
        }
Ejemplo n.º 26
0
        private void Start()
        {
            controller.Initialize();

            if (controller.gs2MatchmakingSetting == null)
            {
                throw new InvalidProgramException("'Gs2MatchmakingSetting' is not null.");
            }
            if (string.IsNullOrEmpty(controller.gs2MatchmakingSetting.matchmakingNamespaceName))
            {
                throw new InvalidProgramException(
                          "'matchmakingNamespaceName' of script 'Gs2MatchmakingSetting' of 'Canvas' is not set. " +
                          "The value to be set for 'matchmakingNamespaceName' can be created by uploading the 'initialize_matchmaking_template.yaml' bundled with the sample as a GS2-Deploy stack." +
                          "Please check README.md for details." +
                          " / " +
                          "'Canvas' の持つスクリプト 'Gs2MatchmakingSetting' の 'matchmakingNamespaceName' が設定されていません。" +
                          "'matchmakingNamespaceName' に設定する値はサンプルに同梱されている 'initialize_matchmaking_template.yaml' を GS2-Deploy のスタックとしてアップロードすることで作成できます。" +
                          "詳しくは README.md をご確認ください。"
                          );
            }

            if (controller.gs2Client == null)
            {
                controller.gs2Client = Gs2Util.LoadGlobalGameObject <Gs2Client>("Gs2Client");
                if (controller.gs2Client == null)
                {
                    throw new InvalidProgramException(
                              "Unable to find GS2 Client" +
                              "You need to set GS2 Client on 'MatchmakingRegistrationLoginController' or place a GameObject named 'Gs2Client' in the scene." +
                              "Please check README.md for details." +
                              " / " +
                              "GS2 Client を見つけられません。" +
                              "'MatchmakingRegistrationLoginController' に GS2 Client を設定するか、'Gs2Client' という名前の GameObject をシーン内に配置する必要があります。" +
                              "詳しくは README.md をご確認ください。"
                              );
                }
            }

            var animator = GetComponent <Animator>();

            if (animator == null)
            {
                throw new InvalidProgramException(
                          "'MatchmakingStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'MatchmakingStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }
            _stateMachine = animator.GetBehaviour <MatchmakingStateMachine>();
            if (_stateMachine == null)
            {
                throw new InvalidProgramException(
                          "'MatchmakingStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'MatchmakingStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }

            _stateMachine.controller = controller;
            _stateMachine.onChangeState.AddListener(
                (_, state) =>
            {
                InActiveAll();
                GetMenuGameObject(state).SetActive(true);
            }
                );

            controller.gs2MatchmakingSetting.onUpdateJoinedPlayerIds.AddListener(
                (gathering, joinedPlayerIds) =>
            {
                displayPlayerNamePrefab.SetActive(false);

                if (joinedPlayersContent != null)
                {
                    foreach (Transform child in joinedPlayersContent.transform)
                    {
                        if (child != null && child.gameObject != displayPlayerNamePrefab)
                        {
                            Destroy(child.gameObject);
                        }
                    }

                    foreach (var joinedPlayerId in joinedPlayerIds)
                    {
                        var gamePlayerName = Instantiate <GameObject>(displayPlayerNamePrefab,
                                                                      joinedPlayersContent.transform);
                        var nameLabel     = gamePlayerName.GetComponent <Text>();
                        nameLabel.text    = joinedPlayerId;
                        nameLabel.enabled = true;
                        gamePlayerName.SetActive(true);
                    }
                }
            }
                );

            controller.gs2MatchmakingSetting.onError.AddListener(
                e => { errorMessage.text = e.Message; }
                );

            // 画面の初期状態を設定
            InActiveAll();
        }
        private void Start()
        {
            controller.Initialize();

            if (controller.gs2AccountSetting == null)
            {
                throw new InvalidProgramException("'Gs2AccountSetting' is not null.");
            }
            if (string.IsNullOrEmpty(controller.gs2AccountSetting.accountNamespaceName))
            {
                throw new InvalidProgramException(
                          "'accountNamespaceName' of script 'Gs2AccountSetting' of 'Canvas' is not set. " +
                          "The value to be set for 'accountNamespaceName' can be created by uploading the 'initialize_account_template.yaml' bundled with the sample as a GS2-Deploy stack." +
                          "Please check README.md for details." +
                          " / " +
                          "'Canvas' の持つスクリプト 'Gs2AccountSetting' の 'accountNamespaceName' が設定されていません。" +
                          "'accountNamespaceName' に設定するべき値はサンプルに同梱されている 'initialize_account_template.yaml' を GS2-Deploy のスタックとしてアップロードすることで作成できます。" +
                          "詳しくは README.md をご確認ください。"
                          );
            }
            if (string.IsNullOrEmpty(controller.gs2AccountSetting.gatewayNamespaceName))
            {
                throw new InvalidProgramException(
                          "'gatewayNamespaceName' of script 'Gs2AccountSetting' of 'Canvas' is not set. " +
                          "The value to be set for 'gatewayNamespaceName' can be created by uploading the 'initialize_account_template.yaml' bundled with the sample as a GS2-Deploy stack." +
                          "Please check README.md for details." +
                          " / " +
                          "'Canvas' の持つスクリプト 'Gs2AccountSetting' の 'gatewayNamespaceName' が設定されていません。" +
                          "'gatewayNamespaceName' に設定するべき値はサンプルに同梱されている 'initialize_account_template.yaml' を GS2-Deploy のスタックとしてアップロードすることで作成できます。" +
                          "詳しくは README.md をご確認ください。"
                          );
            }
            if (string.IsNullOrEmpty(controller.gs2AccountSetting.accountEncryptionKeyId))
            {
                throw new InvalidProgramException(
                          "'accountEncryptionKeyId' of script 'Gs2AccountSetting' of 'Canvas' is not set. " +
                          "The value to be set for 'accountEncryptionKeyId' can be created by uploading the 'initialize_account_template.yaml' bundled with the sample as a GS2-Deploy stack." +
                          "Please check README.md for details." +
                          " / " +
                          "'Canvas' の持つスクリプト 'Gs2AccountSetting' の 'accountEncryptionKeyId' が設定されていません。" +
                          "'accountEncryptionKeyId' に設定するべき値はサンプルに同梱されている 'initialize_account_template.yaml' を GS2-Deploy のスタックとしてアップロードすることで作成できます。" +
                          "詳しくは README.md をご確認ください。"
                          );
            }

            if (controller.gs2Client == null)
            {
                controller.gs2Client = Gs2Util.LoadGlobalGameObject <Gs2Client>("Gs2Client");
                if (controller.gs2Client == null)
                {
                    throw new InvalidProgramException(
                              "Unable to find GS2 Client" +
                              "You need to set GS2 Client on 'AccountRegistrationLoginController' or place a GameObject named 'Gs2Client' in the scene." +
                              "Please check README.md for details." +
                              " / " +
                              "GS2 Client を見つけられません。" +
                              "'AccountRegistrationLoginController' に GS2 Client を設定するか、'Gs2Client' という名前の GameObject をシーン内に配置する必要があります。" +
                              "詳しくは README.md をご確認ください。"
                              );
                }
            }

            var animator = GetComponent <Animator>();

            if (animator == null)
            {
                throw new InvalidProgramException(
                          "'AccountRegistrationLoginStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'AccountRegistrationLoginStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }
            _stateMachine = animator.GetBehaviour <AccountRegistrationLoginStateMachine>();
            if (_stateMachine == null)
            {
                throw new InvalidProgramException(
                          "'AccountRegistrationLoginStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'AccountRegistrationLoginStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }

            _stateMachine.controller = controller;
            _stateMachine.onChangeState.AddListener(
                (_, state) =>
            {
                InActiveAll();
                GetMenuGameObject(state).SetActive(true);
            }
                );
            controller.gs2AccountSetting.onError.AddListener(
                e => { errorMessage.text = e.Message; }
                );

            // 画面の初期状態を設定
            InActiveAll();
        }
Ejemplo n.º 28
0
        private void Start()
        {
            controller.Initialize();

            if (controller.gs2RealtimeSetting == null)
            {
                throw new InvalidProgramException("'Gs2RealtimeSetting' is not null.");
            }
            if (string.IsNullOrEmpty(controller.gs2RealtimeSetting.realtimeNamespaceName))
            {
                throw new InvalidProgramException(
                          "'realtimeNamespaceName' of script 'Gs2RealtimeSetting' of 'Canvas' is not set. " +
                          "The value to be set for 'realtimeNamespaceName' can be created by uploading the 'initialize_realtime_template.yaml' bundled with the sample as a GS2-Deploy stack." +
                          "Please check README.md for details." +
                          " / " +
                          "'Canvas' の持つスクリプト 'Gs2RealtimeSetting' の 'realtimeNamespaceName' が設定されていません。" +
                          "'realtimeNamespaceName' に設定する値はサンプルに同梱されている 'initialize_realtime_template.yaml' を GS2-Deploy のスタックとしてアップロードすることで作成できます。" +
                          "詳しくは README.md をご確認ください。"
                          );
            }

            if (controller.gs2Client == null)
            {
                controller.gs2Client = Gs2Util.LoadGlobalGameObject <Gs2Client>("Gs2Client");
                if (controller.gs2Client == null)
                {
                    throw new InvalidProgramException(
                              "Unable to find GS2 Client" +
                              "You need to set GS2 Client on 'RealtimeRegistrationLoginController' or place a GameObject named 'Gs2Client' in the scene." +
                              "Please check README.md for details." +
                              " / " +
                              "GS2 Client を見つけられません。" +
                              "'RealtimeRegistrationLoginController' に GS2 Client を設定するか、'Gs2Client' という名前の GameObject をシーン内に配置する必要があります。" +
                              "詳しくは README.md をご確認ください。"
                              );
                }
            }

            var animator = GetComponent <Animator>();

            if (animator == null)
            {
                throw new InvalidProgramException(
                          "'RealtimeStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'RealtimeStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }
            _stateMachine = animator.GetBehaviour <RealtimeStateMachine>();
            if (_stateMachine == null)
            {
                throw new InvalidProgramException(
                          "'RealtimeStateMachine' that controls the state is not registered." +
                          "Check if Animator is registered in 'Canvas', if the correct controller is set, or if the script is set in the animator's Behavior" +
                          " / " +
                          "ステートをコントロールする 'RealtimeStateMachine' が登録されていません." +
                          "'Canvas' に Animator が登録されているか、正しいコントローラーが設定されているか、アニメーターの Behaviour にスクリプトが設定されているかを確認してください"
                          );
            }

            _stateMachine.controller = controller;
            _stateMachine.onChangeState.AddListener(
                (_, state) =>
            {
                if (state == RealtimeStateMachine.State.Main)
                {
                    var request           = Gs2Util.LoadGlobalGameObject <RealtimeRequest>("RealtimeRequest");
                    myCharacter.Session   = _stateMachine.session;
                    myCharacter.Messenger = new Messenger(request.encryptionKey);
                    StartCoroutine(myCharacter.SendPosition());
                }

                InActiveAll();
                GetMenuGameObject(state).SetActive(true);
            }
                );

            void JoinPlayerHandler(Gs2.Gs2Realtime.Message.Player player)
            {
                if (myCharacter == null || myCharacter.Session == null)
                {
                    return;
                }
                if (player.ConnectionId == myCharacter.Session.MyConnectionId)
                {
                    return;
                }

                otherPlayerPrefab.SetActive(false);

                var otherPlayer = Instantiate <GameObject>(otherPlayerPrefab, otherPlayerPrefab.transform.parent);

                otherPlayer.SetActive(true);
                players[player.ConnectionId] = otherPlayer.GetComponent <OtherPlayer>();
            }

            controller.gs2RealtimeSetting.onJoinPlayer.AddListener(JoinPlayerHandler);

            controller.gs2RealtimeSetting.onLeavePlayer.AddListener(
                player =>
            {
                if (players.ContainsKey(player.ConnectionId))
                {
                    Destroy(players[player.ConnectionId].gameObject);
                    players.Remove(player.ConnectionId);
                }
            }
                );

            controller.gs2RealtimeSetting.onUpdateProfile.AddListener(
                player =>
            {
                if (players.ContainsKey(player.ConnectionId))
                {
                    var data = player.Profile.ToByteArray();
                    var p    = players[player.ConnectionId];
                    if (p != null)
                    {
                        p.Deserialize(data);
                    }
                }
                else
                {
                    JoinPlayerHandler(player);
                }
            }
                );

            controller.gs2RealtimeSetting.onError.AddListener(
                e => { errorMessage.text = e.Message; }
                );

            // 画面の初期状態を設定
            InActiveAll();
        }