예제 #1
0
        /**
         *      purchase item in asynchronously.
         *
         *      string purchaseId: you can set id for this purchase. this param will back in done or failed handler.
         *      string productId: platform-shard product id string.
         *      Action<string> done: fire when purchase is done in succeessful. string is purchaseId.
         *      Action<string, PurchaseRouter.PurchaseError, string, AutoyaStatus> failed: fire when purchase is failed. 1st string is purchaseId.
         */
        public static void Purchase(string purchaseId, string productId, Action <string> done, Action <string, PurchaseRouter.PurchaseError, string, AutoyaStatus> failed)
        {
            if (autoya == null)
            {
                Debug.LogWarning("not yet. 1");
                // var cor = new AssetBundleLoadErrorInstance(assetName, "Autoya is null.", loadFailed).Coroutine();
                // autoya.mainthreadDispatcher.Commit(cor);
                return;
            }
            if (!Autoya.Auth_IsAuthenticated())
            {
                Debug.LogWarning("not yet. 2");
                // var cor = new AssetBundleLoadErrorInstance(assetName, "not authenticated.", loadFailed).Coroutine();
                // autoya.mainthreadDispatcher.Commit(cor);
                return;
            }

            if (autoya.purchaseFeatureState != PurchaseFeatureState.Ready)
            {
                Debug.LogWarning("not yet. 3");
                return;
            }

            var purchasability = autoya._purchaseRouter.IsPurchaseReady();

            if (!purchasability)
            {
                Debug.LogWarning("not yet. 4");
                return;
            }

            autoya.mainthreadDispatcher.Commit(autoya._purchaseRouter.PurchaseAsync(purchaseId, productId, done, failed));
        }
예제 #2
0
        public static ProductInfo[] Purchase_ProductInfos()
        {
            if (autoya == null)
            {
                return(new ProductInfo[] {});
            }
            if (!Autoya.Auth_IsAuthenticated())
            {
                return(new ProductInfo[] {});
            }

            return(autoya._purchaseRouter.ProductInfos());
        }
예제 #3
0
        /**
         *              purchase item asynchronously.
         *
         *              string purchaseId: the id for this purchase. this param will back in done or failed handler.
         *              string productId: platform-shard product id string.
         *              Action<string> done: fire when purchase is done in succeessful. string is purchaseId.
         *              Action<string, PurchaseRouter.PurchaseError, string> failed: fire when purchase is failed. 1st string is purchaseId.
         */
        public static void Purchase(string purchaseId, string productId, Action <string> done, Action <string, ErrorCodes, string, AutoyaStatus> failed)
        {
            if (autoya == null)
            {
                Debug.LogWarning("not yet. 1");
                // var cor = new AssetBundleLoadErrorInstance(assetName, "Autoya is null.", loadFailed).Coroutine();
                // autoya.mainthreadDispatcher.Commit(cor);
                return;
            }

            if (!Autoya.Auth_IsAuthenticated())
            {
                Debug.LogWarning("not yet. 2");
                // var cor = new AssetBundleLoadErrorInstance(assetName, "not authenticated.", loadFailed).Coroutine();
                // autoya.mainthreadDispatcher.Commit(cor);
                return;
            }

            if (autoya.purchaseState != PurchaseFeatureState.Ready)
            {
                Debug.LogWarning("not yet. 3");
                return;
            }

            if (!autoya._purchaseRouter.IsPurchaseReady())
            {
                Debug.LogWarning("not yet. 4");
                return;
            }

            purchaseErrorStatus = new AutoyaStatus();

            Action <string, PurchaseRouter.PurchaseError, int, string> _failed = (p1, p2, p3, p4) =>
            {
                failed(p1, new ErrorCodes(p2, p3), p4, purchaseErrorStatus);
            };

            autoya.mainthreadDispatcher.Commit(
                autoya._purchaseRouter.PurchaseAsync(purchaseId, productId, done, _failed)
                );
        }
예제 #4
0
        public static ProductInfo[] Purchase_ProductInfos()
        {
            if (autoya == null)
            {
                return(new ProductInfo[] { });
            }
            if (!Autoya.Auth_IsAuthenticated())
            {
                return(new ProductInfo[] { });
            }
            if (autoya.purchaseState != PurchaseFeatureState.Ready)
            {
                return(new ProductInfo[] { });
            }
            if (!autoya._purchaseRouter.IsPurchaseReady())
            {
                return(new ProductInfo[] { });
            }

            return(autoya._purchaseRouter.ProductInfos());
        }
예제 #5
0
        /*
         *              public apis.
         */

        public static bool Purchase_IsReady()
        {
            if (autoya == null)
            {
                return(false);
            }
            if (!Autoya.Auth_IsAuthenticated())
            {
                return(false);
            }

            if (autoya.purchaseState != PurchaseFeatureState.Ready)
            {
                return(false);
            }

            if (!autoya._purchaseRouter.IsPurchaseReady())
            {
                return(false);
            }

            return(true);
        }
예제 #6
0
        public static void AssetBundle_LoadAsset <T> (string assetName, Action <string, T> loadSucceeded, Action <string, AssetBundleLoader.AssetBundleLoadError, string, AutoyaStatus> loadFailed) where T : UnityEngine.Object
        {
            if (autoya == null)
            {
                var cor = new AssetBundleLoadErrorInstance(assetName, "Autoya is null.", loadFailed).Coroutine();
                autoya.mainthreadDispatcher.Commit(cor);
                return;
            }
            if (!Autoya.Auth_IsAuthenticated())
            {
                var cor = new AssetBundleLoadErrorInstance(assetName, "not authenticated.", loadFailed).Coroutine();
                autoya.mainthreadDispatcher.Commit(cor);
                return;
            }

            if (autoya._assetBundleLoader == null)
            {
                autoya._assetBundleLoader = new AssetBundleLoader(AssetBundlesSettings.ASSETBUNDLES_URL_DOWNLOAD_ASSET, new AssetBundleList() /*このへんで、リストを読み出す? もっといい仕組みがある気がする。*/, autoya.assetBundleRequestHeaderDelegate, autoya.httpResponseHandlingDelegate);
            }

            autoya.mainthreadDispatcher.Commit(
                autoya._assetBundleLoader.LoadAsset(assetName, loadSucceeded, loadFailed)
                );
        }
예제 #7
0
        public static string Http_Put(
            string url,
            byte[] data,
            Action <string, byte[]> succeeded,
            Action <string, int, string, AutoyaStatus> failed,
            Dictionary <string, string> additionalHeader = null,
            double timeoutSec       = BackyardSettings.HTTP_TIMEOUT_SEC,
            string userConnectionId = null
            )
        {
            var connectionId = Guid.NewGuid().ToString();

            if (!string.IsNullOrEmpty(userConnectionId))
            {
                connectionId = userConnectionId;
            }


            if (autoya == null)
            {
                var cor = new ConnectionErrorInstance(connectionId, "Autoya is null.", new AutoyaStatus(), failed).Coroutine();
                autoya.mainthreadDispatcher.Commit(cor);
                return(connectionId);
            }
            if (!Autoya.Auth_IsAuthenticated())
            {
                var cor = new ConnectionErrorInstance(connectionId, "not authenticated.", new AutoyaStatus(false, true), failed).Coroutine();
                autoya.mainthreadDispatcher.Commit(cor);

                return(connectionId);
            }

            if (additionalHeader == null)
            {
                additionalHeader = new Dictionary <string, string>();
            }

            autoya.AddFrameworkHeaderParam(additionalHeader);

            var headers = autoya.httpRequestHeaderDelegate("PUT", url, additionalHeader, data);

            autoya.mainthreadDispatcher.Commit(
                autoya._autoyaHttp.Put(
                    connectionId,
                    headers,
                    url,
                    data,
                    (string conId, int code, Dictionary <string, string> responseHeader, string resultData) =>
            {
                autoya.HttpResponseHandling(conId, responseHeader, code, resultData, string.Empty,
                                            (_conId, _data) =>
                {
                    var byteData  = _data as byte[];
                    var reason    = string.Empty;
                    var validated = autoya.OnValidateHttpResponse("PUT", url, responseHeader, byteData, out reason);
                    if (!validated)
                    {
                        failed(connectionId, code, reason, new AutoyaStatus());
                        return;
                    }

                    succeeded(_conId, byteData);
                },
                                            failed
                                            );
            },
                    (conId, code, reason, responseHeader) =>
            {
                autoya.HttpResponseHandling(conId, responseHeader, code, string.Empty, reason, (_conId, _data) => { },
                                            (_conId, _code, _reason, _status) =>
                {
                    // use validated reason for some security appearance.
                    var validatedReason = autoya.OnValidateFailedHttpResponse("PUT", url, _code, responseHeader, _reason);
                    failed(_conId, _code, validatedReason, _status);
                }
                                            );
            },
                    timeoutSec
                    )
                );

            return(connectionId);
        }
        // request & response by bytes[]
        public static string Http_Post(
            string url,
            byte[] data,
            Action <string, byte[]> succeeded,
            Action <string, int, string, AutoyaStatus> failed,
            Dictionary <string, string> additionalHeader = null,
            double timeoutSec       = BackyardSettings.HTTP_TIMEOUT_SEC,
            string userConnectionId = null
            )
        {
            Uri myUri = new Uri(url);
            var ip    = System.Net.Dns.GetHostAddresses(myUri.Host)[0];

            Debug.Log("ip:" + ip);

            var connectionId = Guid.NewGuid().ToString();

            if (!string.IsNullOrEmpty(userConnectionId))
            {
                connectionId = userConnectionId;
            }


            if (autoya == null)
            {
                var cor = new ConnectionErrorInstance(connectionId, "Autoya is null.", new AutoyaStatus(), failed).Coroutine();
                autoya.mainthreadDispatcher.Commit(cor);
                return(connectionId);
            }
            if (!Autoya.Auth_IsAuthenticated())
            {
                var cor = new ConnectionErrorInstance(connectionId, "not authenticated.", new AutoyaStatus(false, true), failed).Coroutine();
                autoya.mainthreadDispatcher.Commit(cor);

                return(connectionId);
            }

            if (additionalHeader == null)
            {
                additionalHeader = new Dictionary <string, string>();
            }

            autoya.AddFrameworkHeaderParam(additionalHeader);

            var headers = autoya.httpRequestHeaderDelegate("POST", url, additionalHeader, data);

            autoya.mainthreadDispatcher.Commit(
                autoya._autoyaHttp.Post(
                    connectionId,
                    headers,
                    url,
                    data,
                    (string conId, int code, Dictionary <string, string> responseHeader, byte[] resultData) =>
            {
                autoya.HttpResponseHandling(conId, responseHeader, code, resultData, string.Empty,
                                            (_conId, _data) =>
                {
                    var byteData  = _data as byte[];
                    var message   = string.Empty;
                    var validated = autoya.OnValidateHttpResponse("POST", url, responseHeader, byteData, out message);
                    if (!validated)
                    {
                        failed(connectionId, code, message, new AutoyaStatus(false, false, true));
                        return;
                    }

                    succeeded(_conId, byteData);
                },
                                            failed
                                            );
            },
                    (conId, code, reason, responseHeader) =>
            {
                autoya.HttpResponseHandling(conId, responseHeader, code, string.Empty, reason, (_conId, _data) => { }, failed);
            },
                    timeoutSec
                    )
                );

            return(connectionId);
        }
예제 #9
0
        public static string Http_Post(
            string url,
            string data,
            Action <string, string> succeeded,
            Action <string, int, string, AutoyaStatus> failed,
            Dictionary <string, string> additionalHeader = null,
            double timeoutSec = BackyardSettings.HTTP_TIMEOUT_SEC
            )
        {
            var connectionId = Guid.NewGuid().ToString();

            if (autoya == null)
            {
                var cor = new ConnectionErrorInstance(connectionId, "Autoya is null.", failed).Coroutine();
                autoya.mainthreadDispatcher.Commit(cor);
                return(connectionId);
            }
            if (!Autoya.Auth_IsAuthenticated())
            {
                var cor = new ConnectionErrorInstance(connectionId, "not authenticated.", failed).Coroutine();
                autoya.mainthreadDispatcher.Commit(cor);

                return(connectionId);
            }

            if (additionalHeader == null)
            {
                additionalHeader = new Dictionary <string, string>();
            }
            var headers = autoya.httpRequestHeaderDelegate(HttpMethod.Post, url, additionalHeader, data);

            autoya.mainthreadDispatcher.Commit(
                autoya._autoyaHttp.Post(
                    connectionId,
                    headers,
                    url,
                    data,
                    (conId, code, responseHeader, resultData) => {
                autoya.HttpResponseHandling(conId, responseHeader, code, resultData, string.Empty,
                                            (_conId, _data) => {
                    var stringData = _data as string;
                    var message    = string.Empty;
                    var validated  = autoya.OnValidateHttpResponse(HttpMethod.Post, url, responseHeader, stringData, out message);
                    if (!validated)
                    {
                        failed(connectionId, code, message, new AutoyaStatus(false, false, true));
                        return;
                    }

                    succeeded(_conId, stringData);
                },
                                            failed
                                            );
            },
                    (conId, code, reason, responseHeader) => {
                autoya.HttpResponseHandling(conId, responseHeader, code, string.Empty, reason, (_conId, _data) => {}, failed);
            },
                    timeoutSec
                    )
                );

            return(connectionId);
        }