Пример #1
0
 public void ClearCallback()
 {
     if (StartDelayChanged != null)
     {
         foreach (Delegate d in StartDelayChanged.GetInvocationList())
         {
             StartDelayChanged -= (EventHandler)d;
         }
     }
     if (DurationChanged != null)
     {
         foreach (Delegate d in DurationChanged.GetInvocationList())
         {
             DurationChanged -= (EventHandler)d;
         }
     }
     if (PositionRequest != null)
     {
         foreach (Delegate d in PositionRequest.GetInvocationList())
         {
             PositionRequest -= (EventHandler)d;
         }
     }
     if (StartCallback != null)
     {
         foreach (Delegate d in StartCallback.GetInvocationList())
         {
             StartCallback -= (EventHandler)d;
         }
     }
     if (StopCallback != null)
     {
         foreach (Delegate d in StopCallback.GetInvocationList())
         {
             StopCallback -= (EventHandler)d;
         }
     }
     if (NextCallback != null)
     {
         foreach (Delegate d in NextCallback.GetInvocationList())
         {
             NextCallback -= (EventHandler)d;
         }
     }
     if (PrevCallback != null)
     {
         foreach (Delegate d in PrevCallback.GetInvocationList())
         {
             PrevCallback -= (EventHandler)d;
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 更新回调
        /// </summary>
        /// <param name="utype"></param>
        /// <param name="isWeb"></param>
        /// <param name="cb"></param>
        /// <returns></returns>
        public virtual IEnumerator OnNextUpdate(UpdateType utype, bool isWeb, NextCallback cb)
        {
            switch (utype)
            {
            case UpdateType.kConfig:
                _pkgConfig.SetUpdateOnWeb(isWeb);
                _pkgConfig.SetCallback(cb);
                StartCoroutine(_pkgConfig.OnDownload());
                break;

            case UpdateType.kVersion:
                _pkgVersion.SetUpdateOnWeb(isWeb);
                _pkgVersion.SetCallback(cb);
                StartCoroutine(_pkgVersion.OnDownload());
                break;

            case UpdateType.kBundle:
                _pkgBundle.SetUpdateOnWeb(isWeb);
                _pkgBundle.SetCallback(cb);
                StartCoroutine(_pkgBundle.OnDownload());
                break;

            case UpdateType.kLua:
                _pkgLua.SetUpdateOnWeb(isWeb);
                _pkgLua.SetCallback(cb);
                StartCoroutine(_pkgLua.OnDownload());
                break;

            case UpdateType.kFileList:
                _pkgFileList.SetUpdateOnWeb(isWeb);
                _pkgFileList.SetCallback(cb);
                StartCoroutine(_pkgFileList.OnDownload());
                break;

            case UpdateType.kSetting:       // Add By Pancake
                string filePath = Application.persistentDataPath + "/" + Const.Setting_Coinfig_Path;
                if (!File.Exists(filePath))
                {
                    StartCoroutine(ToCopy(Const.Setting_Coinfig_Path, cb));
                }
                else
                {
                    cb(true, string.Empty);
                }
                break;

            default:
                break;
            }
            yield break;
        }
Пример #3
0
        /// <inheritdocs/>
        protected override bool OnMessage(int message, IntPtr parameter1, IntPtr parameter2)
        {
            switch ((uint)message)
            {
            case NativeMethods.MOM_POSITIONCB:
                var buffer = this.BufferManager.FindBuffer(parameter1);

                if (buffer != null && NextCallback != null)
                {
                    NextCallback.LongData(buffer, MidiDataCallbackType.Notification);
                }
                return(true);
            }
            return(base.OnMessage(message, parameter1, parameter2));
        }
 public void Next(StartCo startCo, NextCallback callback, int[] rank)
 {
     if (type == Type.Test)
     {
         AI[0] = "AI/AI1.dll";
     }
     else if (type == Type.Machine)
     {
         AI[0] = "";
     }
     if (type != Type.Match)
     {
         callback();
         return;
     }
     times++;
     // TODO: calc next AI
     startCo(DoNext(callback, rank));
 }
Пример #5
0
        IEnumerator ToCopy(string fileName, NextCallback cb)
        {
            string src = Const.getStreamingPath_for_www(fileName);
            string des = Application.persistentDataPath + "/" + fileName;
            WWW    www = new WWW(src);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log("www.error: " + www.error);
            }
            else
            {
                FileStream fsDes = new FileStream(des, FileMode.Create);
                fsDes.Write(www.bytes, 0, www.bytes.Length);
                fsDes.Flush();
                fsDes.Close();
            }
            www.Dispose();
            cb(true, string.Empty);
        }
Пример #6
0
        /// <summary>
        /// 更新回调
        /// </summary>
        /// <param name="utype"></param>
        /// <param name="isWeb"></param>
        /// <param name="cb"></param>
        /// <returns></returns>
        public virtual IEnumerator OnNextUpdate(UpdateType utype, bool isWeb, NextCallback cb)
        {
            switch (utype)
            {
            case UpdateType.kConfig:
                _pkgConfig.SetUpdateOnWeb(isWeb);
                _pkgConfig.SetCallback(cb);
                StartCoroutine(_pkgConfig.OnDownload());
                break;

            case UpdateType.kVersion:
                _pkgVersion.SetUpdateOnWeb(isWeb);
                _pkgVersion.SetCallback(cb);
                StartCoroutine(_pkgVersion.OnDownload());
                break;

            case UpdateType.kBundle:
                _pkgBundle.SetUpdateOnWeb(isWeb);
                _pkgBundle.SetCallback(cb);
                StartCoroutine(_pkgBundle.OnDownload());
                break;

            case UpdateType.kLua:
                _pkgLua.SetUpdateOnWeb(isWeb);
                _pkgLua.SetCallback(cb);
                StartCoroutine(_pkgLua.OnDownload());
                break;

            case UpdateType.kFileList:
                _pkgFileList.SetUpdateOnWeb(isWeb);
                _pkgFileList.SetCallback(cb);
                StartCoroutine(_pkgFileList.OnDownload());
                break;

            default:
                break;
            }
            yield break;
        }
Пример #7
0
 /// <summary>
 /// 设置回调
 /// </summary>
 /// <param name="cb"></param>
 public virtual void SetCallback(NextCallback cb)
 {
     callback = cb;
 }
    public IEnumerator DoNext(NextCallback callback, int[] rank)
    {
#if MATCH
        map_id = (new System.Random().Next() % 3) + 1;
        UnityWebRequest req;
        bool            temp_first = first;
        if (first)
        {
            first = false;
            while (true)
            {
                req = UnityWebRequest.Get(host + "/current");
                yield return(req.SendWebRequest());

                if (req.responseCode != 200)
                {
                    continue;
                }
                current = int.Parse(req.downloadHandler.text);
                break;
            }
        }
        else
        {
            //提交
            string sign   = salt;
            Result result = new Result();
            result.id   = new int[4];
            result.rank = new int[4];
            for (int i = 0; i < 4; i++)
            {
                result.id[i] = curPlayer[i];
                sign        += curPlayer[i].ToString();
                if (rank != null)
                {
                    result.rank[i] = rank[i];
                }
            }
            SHA256 sha256 = SHA256.Create();
            byte[] signB  = sha256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(sign));
            sign = "";
            foreach (byte b in signB)
            {
                sign += b.ToString("X2");
            }
            result.sign = sign;
            if (rank == null)
            {
                result.canceled = true;
            }
            while (true)
            {
                req = UnityWebRequest.Get(host + "/result");
                req.SetRequestHeader("Content-Type", "application/json");
                req.method                    = "POST";
                req.uploadHandler             = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(JsonUtility.ToJson(result)));
                req.uploadHandler.contentType = "application/json";
                yield return(req.SendWebRequest());

                if (req.responseCode == 200)
                {
                    break;
                }
            }
            current++;
        }
        if (rank != null || (rank == null && temp_first == false))
        {
            callback();
        }
        while (true)
        {
            req = UnityWebRequest.Get(host + "/match?id=" + current.ToString());
            yield return(req.SendWebRequest());

            if (req.responseCode == 200)
            {
                break;
            }
            if (req.responseCode == 404)
            {
                //System.IO.FileStream ffs = new System.IO.FileStream("log.txt", System.IO.FileMode.Create);
                //ffs.Write(System.Text.Encoding.UTF8.GetBytes("404"), 0, System.Text.Encoding.UTF8.GetByteCount("404"));
                //ffs.Close();
                if (!System.IO.File.Exists(".tc.finish"))
                {
                    System.IO.File.Create(".tc.finish");
                }
                Application.Quit();
                yield return(null);

                yield break;
            }
        }
        Match m = (Match)JsonUtility.FromJson(req.downloadHandler.text, typeof(Match));
        curPlayer[0] = m.player1;
        curPlayer[1] = m.player2;
        curPlayer[2] = m.player3;
        curPlayer[3] = m.player4;
        for (int i = 0; i < 4; i++)
        {
            AI[i] = "AI/" + curPlayer[i].ToString() + "/AI" + (i + 1).ToString() + ".dll";
        }
        //System.IO.FileStream fs = new System.IO.FileStream("log.txt", System.IO.FileMode.Create);
        //fs.Write(System.Text.Encoding.UTF8.GetBytes(req.downloadHandler.text), 0, System.Text.Encoding.UTF8.GetByteCount(req.downloadHandler.text));
        //fs.Close();
#else
        yield return(null);
#endif
        callback();
    }
Пример #9
0
 public void OnComplete(NextCallback cb)
 {
     onComplete = cb;
     isStart    = true;
     Next();
 }
Пример #10
0
 public void Next()
 {
     NextCallback?.Invoke(this, new EventArgs());
 }