/// <summary>
 /// 单个文件上传完成回调
 /// </summary>
 /// <param name="over"></param>
 /// <param name="msg"></param>
 private static void UpVideoCallBack(bool over, string msg)
 {
     if (over == false)
     {
         m_ReturnoMsg = "failure";
         WDebuger.LogError("文件上传失败,请检查! 消息:" + msg);
         //EditorUtility.ClearProgressBar();
         //if (ChinarMessage.ShowRetryCancel("文件上传失败,请检查! 消息:" + msg, "警告"))
         UpToServer();
         return;
     }
     WDebuger.Log("文件上传成功!文件名:" + m_ResFileName[m_ItemResFilePath[0]]);
     m_ReturnoMsg = "over";
     m_ResServerPath.Add(m_ResFileName[m_ItemResFilePath[0]], msg);
     m_ItemResFilePath.RemoveAt(0);
     if (m_ItemResFilePath.Count <= 0)
     {
         m_UploadConfig = true;
         return;
     }
     try
     {
         string itemResPath      = m_ItemResFilePath[0];
         string itemResCloudName = m_ResFileName[m_ItemResFilePath[0]];
         WillAliyunUpload.Instance.UploadData(itemResPath, ConstData.companyname, ConstData.projectname + "/" + itemResCloudName, UpVideoCallBack, UploadProgressChangedEvent);
     }
     catch (Exception e)
     {
         WDebuger.LogError("文件上传失败,请检查! 消息:" + e.Message);
         //EditorUtility.ClearProgressBar();
         //if (ChinarMessage.ShowRetryCancel("文件上传失败,请检查! 消息:" + msg, "警告"))
         UpToServer();
         throw;
     }
 }
        /// <summary>
        /// Get方法访问服务器
        /// </summary>
        /// <param name="httpUrl">服务器地址</param>
        /// <param name="callBack">回调函数</param>
        /// <param name="Coerce">关闭之前的协程,强制执行新请求</param>
        /// <param name="HttpGetType">请求类型</param>
        /// <param name="parameters">回调携带的参数</param>
        public void Get(string httpUrl, HttpCallBack callBack = null, bool Coerce = false, HttpGetType type = HttpGetType.normal, object[] parameters = null)
        {
//#if UNITY_EDITOR
//            if (!InitBaseData(httpUrl, callBack, parameters)) return;
//            m_HttpGetType = type;
//            m_IsCanNext = true;
//            EditorCoroutineLooper.StartLoop(m_CoroutinesMono, HttpCoroutines());
//            return;
//#endif
            if (Coerce == true)
            {
                m_CoroutinesMono.StopCoroutine(m_Coroutine);
                m_Coroutine = null;
            }
            if (m_Coroutine == null)
            {
                if (!InitBaseData(httpUrl, callBack, parameters))
                {
                    return;
                }
                m_HttpGetType = type;
                m_IsCanNext   = true;
                m_Coroutine   = m_CoroutinesMono.StartCoroutine(HttpCoroutines());
            }
            else
            {
                WDebuger.Log("上一个请求尚未完成,请稍等");
            }
        }
        /// <summary>
        /// 通过ftp上传字节数据到服务器
        /// </summary>
        /// <param name="data">字节数据</param>
        /// <param name="fileName">存储到服务器的文件名,带后缀</param>
        /// <param name="callBack">完成回调函数</param>
        /// <param name="progress">进度改变回调函数</param>
        public void UploadData(byte[] data, string fileName, WillFtpUploadCallBack callBack, WillFtpUploadProgressChangedEvent proEvent = null)
        {
            if (string.IsNullOrEmpty(m_FTPHost) || string.IsNullOrEmpty(m_FTPUserName))
            {
                WDebuger.LogError("未进行初始化,请检查!");
                return;
            }
            if (string.IsNullOrEmpty(fileName))
            {
                WDebuger.LogError("存储文件名不能为空,请检查! 参数:" + fileName);
            }
            m_FTPUploadCallBack   = callBack;
            m_UploadProgressEvent = proEvent;
            m_UploadDataByteCount = data.Length;
            m_Progreess           = 0;
            m_WebClient           = new WebClient();
            m_WebClient.Encoding  = Encoding.UTF8;
            Uri uri = new Uri(m_FTPHost + fileName);

            m_WebClient.UploadDataCompleted   += new UploadDataCompletedEventHandler(OnDataUploadCompleted);
            m_WebClient.UploadProgressChanged += new UploadProgressChangedEventHandler(OnDataUploadProgressChanged);
            m_WebClient.Credentials            = new NetworkCredential(m_FTPUserName, m_FTPPasswork);

            m_WebClient.UploadDataAsync(uri, "STOR", data);
        }
        /// <summary>
        /// Post方法将资源上传到服务器,资源类型字节数组
        /// </summary>
        /// <param name="httpUrl">服务器地址</param>
        /// <param name="postData">资源字节数组</param>
        /// <param name="callBack">回调函数</param>
        /// <param name="Corece">关闭之前的协程,强制执行新请求</param>
        /// <param name="parameters">回调携带的参数</param>
        public void Post(string httpUrl, byte[] postData, string fileName = "data", HttpCallBack callBack = null, bool Corece = false, object[] parameters = null)
        {
//#if UNITY_EDITOR
//            if (!InitBaseData(httpUrl, callBack, parameters)) return;
//            m_IsCanNext = true;
//            m_PostData = postData;
//            m_DataName = fileName;
//            EditorCoroutineLooper.StartLoop(m_CoroutinesMono, HttpCoroutines());
//            return;
//#endif
            if (Corece == true)
            {
                m_CoroutinesMono.StopCoroutine(m_Coroutine);
                m_Coroutine = null;
            }
            if (m_Coroutine == null)
            {
                if (!InitBaseData(httpUrl, callBack, parameters))
                {
                    return;
                }
                m_PostData  = postData;
                m_DataName  = fileName;
                m_Coroutine = m_CoroutinesMono.StartCoroutine(HttpCoroutines());
            }
            else
            {
                WDebuger.Log("上一个请求尚未完成,请稍等");
            }
        }
Пример #5
0
    public static void LogError(object message, object context)
    {
        message = "Log >>>  " + message + " ";
        string str = WDebuger.GetLogTime() + message;

        UnityEngine.Debug.LogError(WDebuger.Prefix + str, (UnityEngine.Object)context);
        WDebuger.LogToFile("[Error]" + str, true);
    }
Пример #6
0
 public static void LogError(string tag, object message)
 {
     tag     = "Log >>>  " + tag + " ";
     message = "Log >>>  " + message + " ";
     message = WDebuger.GetLogTime(tag, message);
     UnityEngine.Debug.LogError(WDebuger.Prefix + message, null);
     WDebuger.LogToFile("[Error]" + message, true);
 }
Пример #7
0
    public static void LogWarning(object message)
    {
        message = "Log >>>  " + message + " ";
        string str = WDebuger.GetLogTime() + message;

        UnityEngine.Debug.LogWarning(WDebuger.Prefix + str, null);
        WDebuger.LogToFile("[Warning]" + str, true);
    }
 private static void UpOver()
 {
     m_AllUploadOver = false;
     WDebuger.Log("文件上传成功!文件名:" + m_ConfigFileName);
     //ChinarMessage.ShowOK("上传完成!上传文件数量:" + (m_ResFilePath.Count + 1), "完成消息");
     WDebuger.Log("上传完成!上传文件数量:" + (m_ResFilePath.Count + 1));
     //EditorUtility.ClearProgressBar();
     //m_Window.Close();
 }
Пример #9
0
    public static void LogError(string tag, string format, params object[] args)
    {
        tag += "Log >>>  " + tag + " ";
        string message = "Log >>>  " + string.Format(format, args) + " ";
        string logText = WDebuger.GetLogTime(tag, string.Format(format, args));

        UnityEngine.Debug.LogError(WDebuger.Prefix + logText, null);
        WDebuger.LogToFile("[Error]" + logText, true);
    }
 protected virtual void Awake()
 {
     if (instance == null)
     {
         instance = (T)this;
     }
     else
     {
         WDebuger.LogError("Gat a second instance of this calss" + this.GetType());
     }
 }
 /// <summary>
 /// 初始化ftp上传
 /// </summary>
 /// <param name="ftpHost">ftp地址</param>
 /// <param name="ftpUserName">ftp密码,默认为匿名登录:anonymous</param>
 /// <param name="ftpPasswork">ftp密码,默认为匿名登录的空密码</param>
 public void Init(string ftpHost, string ftpUserName, string ftpPasswork)
 {
     if (string.IsNullOrEmpty(ftpHost))
     {
         WDebuger.LogError("ftp地址为空,请检查! 参数:" + ftpHost);
         return;
     }
     m_FTPHost     = ftpHost;
     m_FTPUserName = ftpUserName;
     m_FTPPasswork = ftpPasswork;
 }
 /// <summary>
 /// 错误消息处理
 /// </summary>
 /// <param name="errorMsg">错误消息</param>
 protected virtual void ErrorMessage(string errorMsg)
 {
     Progress    = 1;
     HttpMessage = errorMsg;
     HttpData    = null;
     if (m_CallBack != null)
     {
         m_CallBack(m_HttpUrl, false, errorMsg, HttpData, null, m_Parameters);
     }
     WDebuger.LogError(HttpMessage);
 }
        private IEnumerator GetToSave()
        {
            float waitTime   = 0;
            int   waitCount  = 0;
            bool  isContinue = true;

            while (true)
            {
                try
                {
                    m_WWW = new WWW(m_HttpUrl);
                }
                catch (Exception e)
                {
                    WDebuger.LogError(e.Message);
                }
                if (m_IsCanNext == true)
                {
                    while (m_WWW.isDone == false)
                    {
                        Progress = m_WWW.progress;
                        yield return(new WaitForEndOfFrame());

                        waitTime += Time.deltaTime;
                        if (m_WaitTime <= waitTime)
                        {
                            waitCount++;
                            if (waitCount >= m_WaitCount)
                            {
                                ErrorMessage("Error: 网络连接失败,请检查! 参数:" + m_HttpUrl);
                                isContinue = false;
                            }
                            waitTime = 0;
                            break;
                        }
                    }
                    if (isContinue == true && m_WWW.isDone == true)
                    {
                        SetMessage();
                        break;
                    }
                    else if (m_WWW.error != null)
                    {
                        ErrorMessage(m_WWW.error);
                        break;
                    }
                    else if (isContinue == false)
                    {
                        Progress = 1;
                        break;
                    }
                }
            }
        }
 private void DownloadCallBack(bool downloadOver, string downloadMsg, object[] parameters)
 {
     if (downloadOver == true)
     {
         InitGameStart();
     }
     else
     {
         WDebuger.LogError("资源下载失败!");
     }
 }
 /// <summary>
 /// 单个下载回调
 /// 会继续执行后面的下载
 /// 加载完成会调用回调
 /// </summary>
 /// <param name="ftpHost"></param>
 /// <param name="downloadSucceed"></param>
 /// <param name="callBackMessage"></param>
 /// <param name="downloadData"></param>
 /// <param name="e"></param>
 private void DownloadFileCallBack(string ftpHost, bool downloadSucceed, string callBackMessage, byte[] downloadData, DownloadDataCompletedEventArgs e)
 {
     if (downloadSucceed == false)
     {
         WDebuger.LogError("下载失败,请检查网络!");
         m_CallBack(false, "下载失败,请检查网络!", m_Parameters);
         m_CanChack = true;
         return;
     }
     WDebuger.Log("文件下载成功!:[" + ftpHost + "]");
     m_Coroutine = m_CoroutinesMono.StartCoroutine(SaveFile(downloadData));
 }
Пример #16
0
    public static void Log(object message, object context)
    {
        message = "Log >>>  " + message + " ";
        bool flag = !WDebuger.EnableLog;

        if (!flag)
        {
            string str = WDebuger.GetLogTime() + message;
            UnityEngine.Debug.Log(WDebuger.Prefix + str, (UnityEngine.Object)context);
            WDebuger.LogToFile("[Log]" + str, true);
        }
    }
Пример #17
0
    public static void Log(string tag, string format, params object[] args)
    {
        tag = "Log >>>  " + tag + " ";
        string message = "Log >>>  " + string.Format(format, args) + " ";
        bool   flag    = !WDebuger.EnableLog;

        if (!flag)
        {
            string logText = WDebuger.GetLogTime(tag, message);
            UnityEngine.Debug.Log(WDebuger.Prefix + logText, null);
            WDebuger.LogToFile("[Log]" + logText, true);
        }
    }
Пример #18
0
    public static void Log(string tag, object message)
    {
        tag     = "Log >>>  " + tag + " ";
        message = "Log >>>  " + message + " ";
        bool flag = !WDebuger.EnableLog;

        if (!flag)
        {
            message = WDebuger.GetLogTime(tag, message);
            UnityEngine.Debug.Log(WDebuger.Prefix + message, null);
            WDebuger.LogToFile("[Log]" + message, true);
        }
    }
Пример #19
0
    public static void Log(object message)
    {
        //message = "<color=#00ff00>" + message + " ";
        message = "Log >>>  " + message + " ";
        bool flag = !WDebuger.EnableLog;

        if (!flag)
        {
            string str = WDebuger.GetLogTime() + message;
            UnityEngine.Debug.Log(WDebuger.Prefix + str, null);
            WDebuger.LogToFile("[Log]" + str, true);
        }
    }
 /// <summary>
 /// 检查更新回调
 /// </summary>
 /// <param name="overOrFailed"></param>
 /// <param name="message"></param>
 /// <param name="parameters"></param>
 private void UpdataResCallBack(bool overOrFailed, string message, object[] parameters = null)
 {
     WDebuger.Log(message);
     if (overOrFailed == true)
     {
         m_CallBack(true, "下载完成", m_Parameters);
         Destroy(gameObject);
     }
     else
     {
         m_CallBack(false, message, m_Parameters);
         WDebuger.LogError("错误");
     }
 }
 /// <summary>
 /// 通过ftp上传文件到服务器
 /// </summary>
 /// <param name="filePath">文件路径</param>
 /// <param name="fileName">存储到服务器的文件名,带后缀</param>
 /// <param name="callBack">完成回调函数</param>
 /// <param name="progress">进度改变回调函数</param>
 public void UploadData(string filePath, string fileName, WillFtpUploadCallBack callBack, WillFtpUploadProgressChangedEvent proEvent = null)
 {
     if (string.IsNullOrEmpty(filePath))
     {
         WDebuger.LogError("文件地址为空,请检查! 参数:" + filePath);
         return;
     }
     if (!File.Exists(filePath))
     {
         WDebuger.LogError("找不到文件,请检查! 参数" + filePath);
         return;
     }
     byte[] data = File.ReadAllBytes(filePath);
     UploadData(data, fileName, callBack, proEvent);
 }
 //下载完成
 private void OnDataUploadCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     m_DownloadOver = true;
     WDebuger.Log(m_FTPHost);
     if (e.Error != null)
     {
         m_DownloadSucceed = false;
         m_FtpDownloadCallBack?.Invoke(m_FTPHost, m_DownloadSucceed, e.Error.Message, null, e);
     }
     else
     {
         m_DownloadSucceed = true;
         m_FtpDownloadCallBack?.Invoke(m_FTPHost, m_DownloadSucceed, "Succeed", e.Result, e);
     }
 }
    public static void UpToServer()
    {
        m_ResFilePath.Clear();
        m_ItemResFilePath.Clear();
        m_ResFileName.Clear();
        m_ResServerPath.Clear();
        m_UploadConfig  = false;
        m_AllUploadOver = false;
        m_NowUpCount    = 0;
        //m_ResPath = Application.dataPath + ConstData.ABNEWPAT;
        m_ResPath = Application.persistentDataPath + "/" + ConstData.WorldMapUrl;
        GetWorldMap();
        DirectoryInfo dir = new DirectoryInfo(m_ResPath);

        FileInfo[] info = dir.GetFiles();
        print(info.Length);
        for (int i = 0; i < info.Length; i++)
        {
            print("This file : " + i);
            if (info[i].Name.Contains(".json"))
            {
                m_ConfigPath     = info[i].FullName;
                m_ConfigFileName = info[i].Name;
            }
            m_ResFilePath.Add(info[i].FullName);
            m_ItemResFilePath.Add(info[i].FullName);
            m_ResFileName.Add(info[i].FullName, info[i].Name);
        }
        WillAliyunUpload.Instance.InitAliyun(ConstData.OSSpath, ConstData.OSSkey, ConstData.OSSpassword);
        try
        {
            print("m_ItemResFilePath : " + m_ItemResFilePath.Count);
            print("m_ResFileName : " + m_ResFileName.Count);
            string itemResPath      = m_ItemResFilePath[0];
            string itemResCloudName = m_ResFileName[m_ItemResFilePath[0]];
            WillAliyunUpload.Instance.UploadData(itemResPath, ConstData.companyname, ConstData.projectname + "/" + itemResCloudName, UpVideoCallBack, UploadProgressChangedEvent);
        }
        catch (Exception e)
        {
            WDebuger.LogError(e.Message);
            throw;
        }
    }
        /// <summary>
        /// 检查资源更新
        /// </summary>
        /// <param name="mono"></param>
        /// <param name="callBack"></param>
        /// <param name="parameters"></param>
        public void UpdataRes(LoadCloudResCallBack callBack, object[] parameters)
        {
            //if (!ResourceManager.Instance.m_LoadFormAssetBundle)
            //{
            //    callBack(true, "Test", parameters);
            //    return;
            //}
            if (m_CanChack == true)
            {
                m_CanChack = false;
                m_CallBack = callBack;
                if (m_CoroutinesMono == null)
                {
                    m_CallBack(false, "", parameters);
                    m_CanChack = true;
                    WDebuger.LogError("未初始化管理器,请检查!");
                    return;
                }
                m_Parameters = parameters;
                m_DownLoadFileName.Clear();
                m_DownLoadFileNameItem.Clear();
                m_DownLoadFileList.Clear();
                string configPath = m_SavePath + ConstData.WLOCALCONFIG;
                if (!File.Exists(configPath))
                {
                    worldMapData.version = "1.0";
                    worldMapData.date    = System.DateTime.Now.ToString();
                    if (!Directory.Exists(m_SavePath))
                    {
                        Directory.CreateDirectory(m_SavePath);
                    }
                    m_DownLoadFileName.Add("WorldMap.json");
                    m_DownLoadFileNameItem.Add("WorldMap.json");
                    worldMapData.SaveJson(configPath);
                }
                worldMapData = WillData.LoadJson <WorldMapData>(configPath);

                WillFTPDownloadManager.Instance.Init(ConstData.FTPname, ConstData.FTPPassword);
                WillFTPDownloadManager.Instance.DownLoadData(ConstData.DownloadServerFtp + "WorldMap.json", DowlLoadConfigCallBack);
            }
        }
        /// <summary>
        /// 通过ftp从服务器下载资源
        /// </summary>
        /// <param name="downloadHost">ftp地址</param>
        /// <param name="callBack">完成回调函数</param>
        /// <param name="progress">进度改变回调函数</param>
        public void DownLoadData(string downloadHost, WillFtpDownloadCallBack callBack, WillFtpDownloadProgressChangerEvent progress = null)
        {
            if (string.IsNullOrEmpty(downloadHost))
            {
                WDebuger.Log("ftp地址为空,请检查! 参数:" + downloadHost);
                return;
            }
            m_FTPHost               = downloadHost;
            m_FtpDownloadCallBack   = callBack;
            m_DownloadProgressEvent = progress;
            m_Progreess             = 0;
            m_DownloadData          = null;
            m_DownloadSucceed       = false;
            m_DownloadOver          = false;
            m_WebClient             = new WebClient();
            Uri uri = new Uri(downloadHost);

            m_WebClient.DownloadDataCompleted   += new DownloadDataCompletedEventHandler(OnDataUploadCompleted);
            m_WebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnDownloadDataProgressChanged);
            m_WebClient.Credentials              = new NetworkCredential(m_FTPUserName, m_FTPPasswork);

            m_WebClient.DownloadDataAsync(uri);
        }
        private IEnumerator SaveFile(byte[] file)
        {
            WDebuger.Log(m_DownLoadFileNameItem[0]);
            m_DownloadMessage = "保存文件中";
            if (!Directory.Exists(m_SavePath))
            {
                Directory.CreateDirectory(m_SavePath);
            }
            FileInfo fileInfo = new FileInfo(m_SavePath + m_DownLoadFileNameItem[0]);

            if (fileInfo.Exists)
            {
                fileInfo.Delete();
            }

            Stream sw = fileInfo.Create();

            yield return(sw.WriteAsync(file, 0, file.Length));

            yield return(null);

            sw.Flush();
            sw.Close();
            sw.Dispose();
            m_DownLoadFileNameItem.RemoveAt(0);

            if (m_DownLoadFileNameItem.Count <= 0)//所有资源加载完成
            {
                UpdateConfig();
            }
            else
            {
                m_DownloadProgress = (m_DownLoadFileName.Count - m_DownLoadFileNameItem.Count) / m_DownLoadFileName.Count;
                DownLoadFile();
            }
        }
        /// <summary>
        /// 下载配置文件回调
        /// 处理下载后文件对比
        /// </summary>
        /// <param name="ftpHost"></param>
        /// <param name="downloadSucceed"></param>
        /// <param name="callBackMessage"></param>
        /// <param name="downloadData"></param>
        /// <param name="e"></param>
        private void DowlLoadConfigCallBack(string ftpHost, bool downloadSucceed, string callBackMessage, byte[] downloadData, DownloadDataCompletedEventArgs e)
        {
            Debug.Log(Application.persistentDataPath);
            if (downloadSucceed == false)
            {
                WDebuger.LogError("下载文件失败,请检查网络!");
                m_CallBack(true, "下载文件失败,请检查网络!", m_Parameters);
                m_CanChack = true;
                return;
            }
            if (downloadData == null)
            {
                WDebuger.LogError("下载文件失败,下载内容为空,请检查网络!");
                m_CallBack(true, "下载文件失败,下载内容为空,请检查网络!", m_Parameters);
                m_CanChack = true;
                return;
            }

            Debug.Log("Data : " + Encoding.Default.GetString(downloadData));
            s_worldMapData = JsonMapper.ToObject <WorldMapData>(Encoding.Default.GetString(downloadData));

            ContrastConfig();
            Debug.Log("配置表下载成功!");
        }
Пример #28
0
 /// <summary>
 /// 预制体的加载
 /// </summary>
 public virtual void OnStartScene()
 {
     //这里编写需要加载的场景
     WDebuger.LogError("scene manger please override OnStartScene method!");
 }
Пример #29
0
 public virtual void SetScenename()
 {
     SceneName = "";
     WDebuger.LogError("SceneName need Set!");
 }