Run() public static méthode

public static Run ( IEnumerator function ) : Coroutine
function IEnumerator
Résultat Coroutine
Exemple #1
0
        void _PreLogin(System.Action <Hashtable> callback)
        {
            _api.PreLogin(delegate(string err, object data) {
                if (!string.IsNullOrEmpty(err))
                {
                    var url = Dot.String("url", data, null);
                    if (!string.IsNullOrEmpty(url))
                    {
                        _UpdateRequired(url);
                        return;
                    }
                    else
                    {
                        _LoginFailed(err);
                        return;
                    }
                }

                var salt = Dot.String("salt", data, string.Empty);
                Coroutines.Run(Protect.CalculateHmac(salt, delegate(string challenge) {
                    var securityData     = Johny.HashtablePool.Claim();
                    securityData["salt"] = salt;
                    securityData["chal"] = challenge;

                    callback(securityData);
                }));
            });
        }
Exemple #2
0
        public int Debit(int value, string reason, System.Action <int, string, Hashtable> callback)
        {
            var id = _next;

            Coroutines.Run(_Call("debit", value, reason, callback));
            return(id);
        }
Exemple #3
0
        public virtual void SetItemsAsync <T>(int capacity, System.Action onComplete, System.Action <T, int> onItem = null) where T : IComponent
        {
            Coroutines.StopAll(this);

            if (capacity == this.Count() && capacity > 0)
            {
                Coroutines.Run(this.ForEachAsync <T>(() => {
                    this.ForEach <T>((item, idx) => {
                        if (item is WindowComponent)
                        {
                            (item as WindowComponent).Show();
                        }
                    });

                    if (onComplete != null)
                    {
                        onComplete.Invoke();
                    }
                }, onItem), this);

                return;
            }

            this.Clear();

            Coroutines.Run(this.SetItemsAsync_INTERNAL(capacity, onComplete, onItem), this);
        }
    private IEnumerator DoRequest(string path, string method, byte[] bodyBytes)
    {
        TcpClient     tcp    = new TcpClient("myhost.com", 80);
        NetworkStream stream = tcp.GetStream();

        string request = method + " " + path + " HTTP/1.0\r\n";

        request += "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
        request += "Content-Length: " + bodyBytes.Length + "\r\n";
        request += "\r\n";

        byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(request);

        stream.Write(requestBytes, 0, requestBytes.Length);
        stream.Write(bodyBytes, 0, bodyBytes.Length);

        headersRaw = "";
        yield return(Coroutines.Run(ReadHeaders(stream)));

        responseHeaders = ParseHeaders(headersRaw);
        if (!responseHeaders.ContainsKey("Content-Length"))
        {
            throw new System.Exception("Invalid server response");
        }

        int contentLength = int.Parse(responseHeaders["Content-Length"]);

        responseText = "";
        yield return(Coroutines.Run(ReadBody(stream, contentLength)));

        succeeded = true;
    }
Exemple #5
0
        public static void TryToLoadCache()
        {
                        #if UNITY_EDITOR
            if (LocalizationSystem.cacheLoaded == true)
            {
                return;
            }
            if (Application.isPlaying == false)
            {
                LocalizationSystem.cacheLoaded = true;

                var    path = LocalizationSystem.GetCachePath();
                string text = null;
                if (PlayerPrefs.HasKey(path) == true)
                {
                    text = PlayerPrefs.GetString(path, string.Empty);
                }
                else
                {
                    if (System.IO.File.Exists(path) == false)
                    {
                        path = LocalizationSystem.GetBuiltinCachePath();
                    }

                    text = System.IO.File.ReadAllText(path);
                }

                LocalizationSystem.TryToSaveCSV(text, loadCacheOnFail: false);
            }
            else
            {
                        #endif

                                #if UNITY_ANDROID && !UNITY_EDITOR
            Coroutines.Run(LocalizationSystem.LoadByWWW(LocalizationSystem.GetCachePath(), LocalizationSystem.GetBuiltinCachePath()));
                                #else
            bool isCacheSupported = FileSystem.instance.IsCacheSupported();
            string text           = null;
            if (isCacheSupported == false && PlayerPrefs.HasKey(LocalizationSystem.PLAYER_PREFS_CACHE_KEY) == true)
            {
                text = ME.UAB.Zipper.UnzipToString(PlayerPrefs.GetString(LocalizationSystem.PLAYER_PREFS_CACHE_KEY, string.Empty));
            }
            else
            {
                var path = LocalizationSystem.GetCachePath();
                if (isCacheSupported == false || System.IO.File.Exists(path) == false)
                {
                    path = LocalizationSystem.GetBuiltinCachePath();
                }

                text = System.IO.File.ReadAllText(path);
            }

            LocalizationSystem.TryToSaveCSV(text, loadCacheOnFail: false);
                                #endif

                        #if UNITY_EDITOR
        }
                        #endif
        }
Exemple #6
0
        public int Purchase(Hashtable items, int cost, System.Action <int, string, Hashtable> callback)
        {
            var id = _next;

            Coroutines.Run(_Call("purchase", items, cost, callback));
            return(id);
        }
Exemple #7
0
        private IEnumerator RequestAmazonUserId()
        {
            EB.Debug.Log("Getting Amazon User ID");
            int   retryCount  = 0;
            float waitSeconds = 1.0f;

            while (retryCount < kMaxRetryCount && string.IsNullOrEmpty(_userId))
            {
                _iapService.GetUserData();
                yield return(new WaitForSeconds(waitSeconds));

                waitSeconds *= 2.0f;
                retryCount++;
            }
            if (!string.IsNullOrEmpty(_userId))
            {
                Coroutines.Run(RetryPendingPurchases());

                ResetInput input = new ResetInput()
                {
                    Reset = false
                };
                _iapService.GetPurchaseUpdates(input);
            }
            EB.Debug.Log("RequestAmazonUserId Finished - Result: {0}", (string.IsNullOrEmpty(_userId) ? "failed." : _userId));
        }
Exemple #8
0
        public int Use(Hashtable items, System.Action <int, string, Hashtable> callback)
        {
            var id = _next;

            Coroutines.Run(_Call("use", items, -1, callback));
            return(id);
        }
Exemple #9
0
        public int Sync(System.Action <int, string, Hashtable> callback)
        {
            var id = _next;

            Coroutines.Run(_Sync(callback));
            return(id);
        }
        IEnumerator DoEnumerate()
        {
            string [] directories;
            _packs.Clear();

            try {
                directories = Directory.GetDirectories(BasePath, "*", SearchOption.TopDirectoryOnly);
            }
            catch {
                directories = new string[0];
            }

            foreach (var directory in directories)
            {
                var pack = new ContentPack();
                pack.folder = directory;
                yield return(Coroutines.Run(DoVerify(pack)));
            }

            // sort highest version first
            _packs.Sort(delegate(ContentPack x, ContentPack y){
                return(y.version.CompareTo(x.version));
            });

            EB.Debug.Log("Enumerated  " + _packs.Count + " packs ");

            yield break;
        }
Exemple #11
0
        internal void AddItemInternal <T, TClosure>(Resource source, TClosure closure, System.Action <T, TClosure> onComplete) where T : WindowComponent where TClosure : UnityEngine.UI.Windows.Components.IListClosureParameters
        {
            var resources = WindowSystem.GetResources();
            var data      = new AddItemClosure <T, TClosure>()
            {
                data       = closure,
                onComplete = onComplete,
                component  = this,
            };

            Coroutines.Run(resources.LoadAsync <T, AddItemClosure <T, TClosure> >(this, data, source, (asset, innerClosure) => {
                if (innerClosure.component.loadedAssets.Contains(asset) == false)
                {
                    if (asset.createPool == true)
                    {
                        WindowSystem.GetPools().CreatePool(asset);
                    }
                    innerClosure.component.loadedAssets.Add(asset);
                }

                var pools    = WindowSystem.GetPools();
                var instance = pools.Spawn(asset, innerClosure.component.GetRoot());
                innerClosure.component.RegisterSubObject(instance);
                innerClosure.component.items.Add(instance);
                innerClosure.component.NotifyModulesComponentAdded(instance);
                innerClosure.component.OnElementsChanged();
                if (innerClosure.onComplete != null)
                {
                    innerClosure.onComplete.Invoke(instance, innerClosure.data);
                }
            }));
        }
Exemple #12
0
        public void LoadAsync(LayoutWindowType windowInstance, System.Action onComplete)
        {
            windowInstance.Setup(windowInstance);

            var used       = new HashSet <WindowLayout>();
            var layoutItem = this;

            Coroutines.Run(layoutItem.InitLayoutInstance(windowInstance, windowInstance, layoutItem.windowLayout, used, onComplete));
        }
Exemple #13
0
        public static void TryToLoadCache()
        {
                        #if UNITY_EDITOR
            if (LocalizationSystem.cacheLoaded == true)
            {
                return;
            }
            if (Application.isPlaying == false)
            {
                LocalizationSystem.cacheLoaded = true;

                var path = LocalizationSystem.GetCachePath();
                                #if STORAGE_NOT_SUPPORTED
                if (PlayerPrefs.HasKey(path) == false)
                {
                    return;
                }
                var text = PlayerPrefs.GetString(path, string.Empty);
                                #else
                if (System.IO.File.Exists(path) == false)
                {
                    path = LocalizationSystem.GetBuiltinCachePath();
                }
                var text = System.IO.File.ReadAllText(path);
                                #endif

                LocalizationSystem.TryToSaveCSV(text, loadCacheOnFail: false);
            }
            else
            {
                        #endif

                                #if UNITY_ANDROID
            Coroutines.Run(LocalizationSystem.LoadByWWW(LocalizationSystem.GetCachePath(), LocalizationSystem.GetBuiltinCachePath()));
                                #else
            var path = LocalizationSystem.GetCachePath();
                                #if STORAGE_NOT_SUPPORTED
            if (PlayerPrefs.HasKey(path) == false)
            {
                return;
            }
            var text = PlayerPrefs.GetString(path, string.Empty);
                                #else
            if (System.IO.File.Exists(path) == false)
            {
                path = LocalizationSystem.GetBuiltinCachePath();
            }
            var text = System.IO.File.ReadAllText(path);
                                #endif

            LocalizationSystem.TryToSaveCSV(text, loadCacheOnFail: false);
                                #endif

                        #if UNITY_EDITOR
        }
                        #endif
        }
Exemple #14
0
 void SendProbe()
 {
     if (_sent < _num)
     {
         Coroutines.Run(_Send());
     }
     else if (OnComplete != null)
     {
         OnComplete();
     }
 }
        private void LoadRefCounter_INTERNAL <T>(IResourceReference reference, ResourceBase resource, System.Action <T> callbackOnLoad, System.Action callbackOnFailed, bool async, string customResourcePath)       /*where T : Object*/
        {
            if (resource.IsLoadable() == true)
            {
                //Debug.Log("Check: " + resource.assetPath + ", typeof: " + typeof(T).ToString());
                Item item;
                if (this.IsLoaded <T>(reference, resource, out item, callbackOnLoad, callbackOnFailed) == false)
                {
                    //Debug.Log("Loading: " + resource.assetPath);
                    Coroutines.Run(resource.Load <T>(reference, customResourcePath, (data) => {
                        //Debug.Log("Loaded: " + resource.assetPath + " >> " + data);
                        if (data == null)
                        {
                            //Debug.LogWarning(string.Format("Failed to load resource in {0}", resource.assetPath));

                            item.loadingResult = false;
                            if (item.onObjectFailed != null)
                            {
                                item.onObjectFailed.Invoke(item);
                            }

                            item.onObjectLoaded = null;
                            item.onObjectFailed = null;
                            //if (callbackOnFailed != null) callbackOnFailed.Invoke();
                            //WindowSystemLogger.Error(image, string.Format("Error in ResourcesManager: Required resource can't loaded. Resource: {0}", image.GetResource().GetId()));
                            return;
                        }

                        item.loadingResult = true;
                        item.loadedObject  = data;
                        item.loaded        = true;

                        if (item.onObjectLoaded != null)
                        {
                            item.onObjectLoaded.Invoke(item);
                        }
                        item.onObjectLoaded = null;
                        item.onObjectFailed = null;

                        //callbackOnLoad(data);
                    }, async));
                }
            }
            else
            {
                if (callbackOnFailed != null)
                {
                    callbackOnFailed.Invoke();
                }
            }
        }
Exemple #16
0
        public static void TestConversion()
        {
            Coroutines cors = new Coroutines();

            cors.Run(OnePlusTwoFrames(Cancellable.Null));
            cors.Step();
            Assert.AreEqual(cors.Count, 1);
            IEnumerator ienum = cors.AsIEnum();

            Assert.IsTrue(ienum.MoveNext());
            Assert.IsFalse(ienum.MoveNext());
            ienum = cors.AsIEnum();
            Assert.IsFalse(ienum.MoveNext());
        }
        public virtual void SetItemsAsync <T>(int capacity, System.Action onComplete, System.Action <T, int> onItem = null) where T : IComponent
        {
            Coroutines.StopAll(this);

            if (capacity == this.Count() && capacity > 0)
            {
                Coroutines.Run(this.ForEachAsync <T>(onComplete, onItem), this);
                return;
            }

            this.Clear();

            Coroutines.Run(this.SetItemsAsync_INTERNAL(capacity, onComplete, onItem), this);
        }
        IEnumerator DoCheck()
        {
            // enumerate local content
            Notify(Localizer.GetString("ID_SPARX_CONTENT_CHECKING"));
            yield return(Coroutines.Run(DoEnumerate()));

            // check server
            yield return(Coroutines.Run(DoCheckServer()));

            // mount if we haven't already
            if (_mounted == null && _packs.Count > 0)
            {
                Mount(_packs[0]);
            }

            Notify(string.Empty);
        }
Exemple #19
0
        private void Init(System.Action callback)
        {
            if (_initialized)
            {
                SetState(LoginState.Initialized);
                callback();
                return;
            }

            SetState(LoginState.Initializing);

            _api.Init(delegate(string err, object data) {
                if (!string.IsNullOrEmpty(err))
                {
                    _LoginFailed(err);
                    return;
                }
                Coroutines.Run(_PostInit(data, callback));
            });
        }
        public virtual void AddItem <T>(Resource source, System.Action <T> onComplete = null) where T : WindowComponent
        {
            var resources = WindowSystem.GetResources();
            var pools     = WindowSystem.GetPools();

            Coroutines.Run(resources.LoadAsync <T>(this, source, (asset) => {
                if (this.loadedAssets.Contains(asset) == false)
                {
                    this.loadedAssets.Add(asset);
                }

                var instance = pools.Spawn(asset, this.GetRoot());
                this.RegisterSubObject(instance);
                if (onComplete != null)
                {
                    onComplete.Invoke(instance);
                }
                this.items.Add(instance);
                this.OnElementsChanged();
            }));
        }
        public void SetImage(Resource resource)
        {
            if (this.prevResourceLoad.IsEquals(resource) == false)
            {
                this.prevResourceLoad = resource;

                var resources = WindowSystem.GetResources();
                if (this.isLoading == true)
                {
                    resources.StopLoadAll(this);
                    resources.Delete(this, ref this.currentLoaded);
                }

                var data = new SetImageClosure()
                {
                    component = this,
                };
                this.isLoading = true;
                switch (resource.objectType)
                {
                case Resource.ObjectType.Sprite:
                    Coroutines.Run(resources.LoadAsync <Sprite, SetImageClosure>(this, data, resource, (asset, closure) => {
                        closure.component.currentLoaded = asset;
                        closure.component.SetImage(asset);
                        closure.component.isLoading = false;
                    }));
                    break;

                case Resource.ObjectType.Texture:
                    Coroutines.Run(resources.LoadAsync <Texture, SetImageClosure>(this, data, resource, (asset, closure) => {
                        closure.component.currentLoaded = asset;
                        closure.component.SetImage(asset);
                        closure.component.isLoading = false;
                    }));
                    break;
                }
            }
        }
Exemple #22
0
        public void SetImage(Resource resource)
        {
            var resources = WindowSystem.GetResources();

            resources.StopLoadAll(this);
            resources.Delete(this, ref this.currentLoaded);
            switch (resource.objectType)
            {
            case Resource.ObjectType.Sprite:
                Coroutines.Run(resources.LoadAsync <Sprite>(this, resource, (asset) => {
                    this.currentLoaded = asset;
                    this.SetImage(asset);
                }));
                break;

            case Resource.ObjectType.Texture:
                Coroutines.Run(resources.LoadAsync <Texture>(this, resource, (asset) => {
                    this.currentLoaded = asset;
                    this.SetImage(asset);
                }));
                break;
            }
        }
 public void LoadAsync <T>(Resource resource, System.Action <T> onComplete = null) where T : WindowObject
 {
     Coroutines.Run(this.LoadAsync_YIELD(resource, onComplete));
 }
Exemple #24
0
        private IEnumerator AuthenticateParallel(object authData)
        {
            endPoint.AddData("stoken", Hub.ApiEndPoint.GetData("stoken"));

            bool?  prelogin     = null;
            object preloginData = null;

            EB.Debug.Log("HuaweiSDKManager.Authenticate: Start PreLogin");
            api.PreLogin(delegate(string preloginError, object preloginResult)
            {
                if (!string.IsNullOrEmpty(preloginError))
                {
                    prelogin = false;

                    var url = Dot.String("url", preloginResult, null);
                    if (!string.IsNullOrEmpty(url))
                    {
                        Hub.Config.LoginConfig.Listener.OnUpdateRequired(url);
                        return;
                    }
                    else
                    {
                        Hub.FatalError(preloginError);
                        return;
                    }
                }

                prelogin     = true;
                preloginData = preloginResult;
                EB.Debug.Log("HuaweiSDKManager.Authenticate: PreLogin Success");
            });

            while (!prelogin.HasValue)
            {
                yield return(null);
            }

            if (!prelogin.Value)
            {
                yield break;
            }

            var salt = Dot.String("salt", preloginData, string.Empty);

            yield return(Coroutines.Run(Protect.CalculateHmac(salt, delegate(string challenge)
            {
                var securityData = new Hashtable();
                securityData["salt"] = salt;
                securityData["chal"] = challenge;

                EB.Debug.Log("HuaweiSDKManager.Authenticate: Start Login");
                api.Login("huawei", new Hashtable()
                {
                    { "huawei", authData }
                }, securityData, delegate(string loginError, object loginResult)
                {
                    if (!string.IsNullOrEmpty(loginError))
                    {
                        Hub.FatalError(loginError);
                        return;
                    }

                    EB.Debug.Log("HuaweiSDKManager.Authenticate: Login success");
                });
            })));
        }
Exemple #25
0
 public static void LoadResource <T>(ResourceBase resource, System.Action <T> callback, bool async)       /*where T : Object*/
 {
     Coroutines.Run(WindowSystemResources.instance.LoadResource_INTERNAL <T>(resource, component: null, customResourcePath: null, callback: callback, async: async));
 }
Exemple #26
0
 public static void LoadCustom(System.Collections.Generic.IEnumerator <byte> routine)
 {
     Coroutines.Run(routine);
 }
Exemple #27
0
 public void LoadAsync(WindowBase window, System.Action onComplete)
 {
     Coroutines.Run(this.InitModules(window, onComplete));
 }
 public Coroutine Wait()
 {
     return(Coroutines.Run(WaitImpl()));
 }
 /**
  * Create a new request with a string for the request body.
  * IT IS YOUR RESPONSIBILITY TO ENCODE THE BODY PROPERLY ACCORDING TO THE HTTP SPEC.
  * The response from the request will be stored in responseHeaders and responseText when the request has completed.
  * Check isBusy to find out when it's completed.
  */
 public HttpRequest(string path, string method, string body)
 {
     Coroutines.Run(DoRequest(path, method, body));
 }
Exemple #30
0
        public void Enumerate()
        {
            if (m_LastFrameCount == UnityEngine.Time.frameCount)
            {
                return;
            }
            m_LastFrameCount = UnityEngine.Time.frameCount;
            EB.Debug.Log("--------------------SparxLoginManager : Enumerate------------------------");
            Init(delegate
            {
                EB.Debug.Log("InitAuthorizes: Init ok, silent authorize ...");

                Coroutines.Run(_Authorize(true, delegate(string err, object authData)
                {
                    if (!string.IsNullOrEmpty(err))
                    {
                        _LoginFailed(err);
                        return;
                    }

                    _authData = authData as Hashtable;
                    if (_authData.Count <= 0)
                    {
                        string LastAuthenticator = PlayerPrefs.GetString("LastAuthenticator", string.Empty);
                        EB.Debug.Log("最后一次的登入平台为:LastAuthenticator = {0},不为空的话,就直接拿去验证最后一次平台", LastAuthenticator);
                        Authenticator auth = null;
                        if (!string.IsNullOrEmpty(LastAuthenticator))
                        {
                            auth = GetAuthenticator(LastAuthenticator);
                        }
                        if (auth != null)
                        {
                            LoginExtraListener.OnEnumerate(new Authenticator[] { auth });
                        }
                        else
                        {
                            LoginExtraListener.OnEnumerate(_authenticators.ToArray());
                        }
                        return;
                    }

                    Authenticator bestAuthenticator = null;
                    foreach (DictionaryEntry entry in _authData)
                    {
                        Authenticator authenticator = GetAuthenticator(entry.Key.ToString());
                        if (bestAuthenticator == null)
                        {
                            bestAuthenticator = authenticator;
                        }
                        else if (authenticator.IsLoggedIn && (int)authenticator.Quailty > (int)bestAuthenticator.Quailty)
                        {
                            bestAuthenticator = authenticator;
                        }

                        if (!string.IsNullOrEmpty(_lastAuthenticator) && bestAuthenticator.Name == _lastAuthenticator)
                        {
                            break;
                        }
                    }

                    EB.Debug.Log("InitAuthorizes: Choose best authenticator = {0} to login ...", bestAuthenticator.Name);
                    Login(bestAuthenticator.Name);
                }));
            });
        }