예제 #1
0
        //initialize IAPs, billing systems and database,
        //as well as shop components in this order
        void Awake()
        {
            //make sure we keep one instance of this script in the game
            if (instance)
            {
                Destroy(gameObject);
                return;
            }
            DontDestroyOnLoad(this);
            isDebug = Debug.isDebugBuild;

            //set static reference
            instance = this;
            DBManager dbManager = GetComponent <DBManager>();

            validator = GetComponent <ReceiptValidator>();

            #if PLAYFAB
            playfabManager = null;
            GameObject playfabGO = GameObject.Find("PlayfabManager");
            if (!playfabGO)
            {
                Debug.LogWarning("IAPManager: Playfab is enabled, but could not find PlayfabManager prefab. Have you placed it in the first scene "
                                 + "of your app and started from there? Instantiating temporary copy...");
                playfabGO = Instantiate(Resources.Load("PlayfabManager", typeof(GameObject))) as GameObject;
                //remove clone tag from its name. not necessary, but nice to have
                playfabGO.name = playfabGO.name.Replace("(Clone)", "");
            }

            playfabManager = playfabGO.GetComponent <PlayfabManager>();
            if (validator == null)
            {
                validator = gameObject.AddComponent <ReceiptValidatorService>();
            }

                #if !PLAYFAB_VALIDATION
            dbManager.memoryOnly = true;
            if (isDebug)
            {
                Debug.Log("PlayFab (online mode) is enabled: IAP data will not be saved on devices.");
            }
                #endif
            #endif

            //populate IAP dictionary and arrays with product ids
            SceneManager.sceneLoaded += OnSceneWasLoaded;
            dbManager.Init();
            InitIds();

            //do not self-initialize when using PlayFab services (full):
            //wait for its login callback for querying store later
            #if PLAYFAB && !PLAYFAB_VALIDATION
            return;
            #endif

            Initialize();
        }