예제 #1
0
 public static void CheckConfigAndClearDir()
 {
     #region 检查多余
     //if (!File.Exists(Application.dataPath + "/RushDevelopFW/PackageConfig.txt"))
     //{
     //    return;
     //}
     //ConfigJson currentConfig = JsonUtility.FromJson<ConfigJson>(File.ReadAllText(Application.dataPath + "/RushDevelopFW/PackageConfig.txt"));
     //ConfigJson downloadConfig = JsonUtility.FromJson<ConfigJson>(File.ReadAllText(@"C:\Users\Administrator\Desktop" + "/PackageConfig.txt"));
     //int currentConfigLength = currentConfig.direct.Count;
     //int downConfigLength = downloadConfig.direct.Count;
     //if (currentConfigLength > downConfigLength)
     //{
     //    for (int i = 0; i < currentConfigLength; i++)
     //    {
     //        if (!downloadConfig.direct.Contains(currentConfig.direct[i]))
     //        {
     //            Debug.LogError("在框架库中发现多余脚本:" + currentConfig.direct[i] + ",可前往删除!");
     //        }
     //    }
     //}
     #endregion
     //下载版本号 对比是否需要更新
     //用playerPrefs永久序列化更新标志位到本地
     WebRequestInEdior.GetIns().GetVersion();
 }
        /// <summary>
        /// 获取最新版本信息
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        IEnumerator GetVersion(Action <string> action)
        {
            UnityWebRequest unityWebRequest = UnityWebRequest.Get(RDUpdateConfig.url);

            yield return(unityWebRequest.SendWebRequest());

            if (unityWebRequest.error != null)
            {
                Debug.Log(unityWebRequest.error);
            }
            else
            {
                if (unityWebRequest.responseCode == 200)
                {
                    string version = unityWebRequest.downloadHandler.text;
                    //Debug.Log(version);
                    //执行委托
                    action?.Invoke(version);
                }
            }
            unityWebRequest.Abort();
            unityWebRequest.Dispose();
            unityWebRequest = null;
            DestroyImmediate(gameObject);
            requestIns = null;
        }
        /// <summary>
        /// 下载最新的版本包
        /// </summary>
        /// <param name="action">下载完成后,执行的委托</param>
        /// <returns></returns>
        IEnumerator GetPackage(Action <string> action)
        {
            UnityWebRequest unityWebRequest = UnityWebRequest.Get(RDUpdateConfig.packageUrl);

            yield return(unityWebRequest.SendWebRequest());

            if (unityWebRequest.error != null)
            {
                Debug.Log(unityWebRequest.error);
            }
            else
            {
                if (unityWebRequest.responseCode == 200)
                {
                    byte[] package = unityWebRequest.downloadHandler.data;
                    if (package.Length > 0)
                    {
                        //将版本包的byte[]数据,写在本地,生成unitypackage
                        File.WriteAllBytes(Application.dataPath + "/RD.unitypackage", package);
                    }
                    //yield return new WaitForSeconds(1.0f);
                    //执行下载并生成好版本包之后的委托,进行安装
                    action?.Invoke(Application.dataPath + "/RD.unitypackage");
                }
            }
            unityWebRequest.Dispose();
            DestroyImmediate(gameObject);
            requestIns = null;
        }
 public static WebRequestInEdior GetIns()
 {
     if (requestIns == null)
     {
         GameObject gameObject = new GameObject("WebRequest");
         requestIns = gameObject.AddComponent <WebRequestInEdior>();
     }
     return(requestIns);
 }
 private void OnGUI()
 {
     GUILayout.BeginArea(middleCenterRect);
     GUILayout.BeginVertical();
     EditorGUILayout.LabelField("检测到R.D.发布了新版本" + versionNum + ",是否更新?", labelStyle, GUILayout.Width(200));
     GUILayout.Space(20);
     GUILayout.BeginHorizontal();
     if (GUILayout.Button("是", GUILayout.Width(80)))
     {
         //Debug.Log("更新");
         Close();
         //开始下载package
         WebRequestInEdior.GetIns().GetNewPackage();
     }
     GUILayout.Space(20);
     if (GUILayout.Button("否", GUILayout.Width(80)))
     {
         Debug.Log("取消更新");
         Close();
     }
     GUILayout.EndHorizontal();
     GUILayout.EndVertical();
     GUILayout.EndArea();
 }