static void Initialize()//单例范本 可学
 {
     if (!initialized)
     {
         if (!Application.isPlaying)
         {
             return;
         }
         initialized = true;
         instance    = new GameObject("GameLoopDispatcher").AddComponent <GameLoopDispatcher>();
     }
 }
예제 #2
0
        //static IEnumerator PostWWW(string url, WWWForm form, Action<string> onSuccess, Action<string> onError)
        //{

        //    using (var www = new WWW(url, form))
        //    {

        //    }
        //}

        //public static IObservable<string> Post(string url)
        //{

        //}

        public static IObservable <string> Get(string url)
        {
            return(AnonymousObservable.Create <string>(observer =>
            {
                var e = GetWWW(url, x =>  //断点1
                {
                    try
                    {
                        observer.OnNext(x);//断点2
                        observer.OnCompleted();
                    }
                    catch (Exception ex)
                    {
                        observer.OnError(ex);
                    }
                }, x => observer.OnError(new Exception(x)));
                //断点3
                GameLoopDispatcher.StartCoroutineRx(e);//开启一个协程 上面这个e直接替换这个e也是可以的
                //如上所示三个断点 经测试 执行顺序是1 3 2 也就是说 很正常的注册流程 开启一个协程就结束了 并没有花里胡哨的操作
                return Disposable.Empty;
            }));
        }
예제 #3
0
 public IDisposable Schedule(Action action, TimeSpan dueTime)
 {
     GameLoopDispatcher.StartCoroutineRx(DelayAction(action, dueTime));
     return(Disposable.Empty);
 }
예제 #4
0
 public IDisposable Schedule(Action action)
 {
     GameLoopDispatcher.Post(action);
     return(Disposable.Empty);
 }
예제 #5
0
        IEnumerator DelayAction(Action action, TimeSpan dueTime)
        {
            yield return(new WaitForSeconds((float)dueTime.TotalSeconds));

            GameLoopDispatcher.Post(action);
        }
 void Awake()
 {
     instance    = this;
     initialized = true;
 }