u3d实现webhttp通信机制

来源:互联网 发布:档案归类软件 编辑:程序博客网 时间:2024/06/11 22:03


    static IEnumerator CommitErrorToWeb(object args)
    {
        if (string.IsNullOrEmpty(ClientErrCommitPath))
        {
            LogToFile("game.log", string.Format("<{0}>{1}\n{2}", LogType.Log, "ClientErrorCommitPath is NULL or Empty!!!!!!!!!!!!!", "nostack"));
            yield return null;
        }
        
        XComitErrInfo info      = TmpCmtErrInfo;        
        string      stack       = "empty!";
        string[]    strArr      = info.stack.Split('\n');
        string      detials     = DeviceInfoStr + info.stack;
                    detials     = detials.Replace("\n", "<br />");


        for (int i = 0; i < strArr.Length; i++)
        {
            if (strArr[i].IndexOf("Assets/Code") > 0)
            {
                stack = strArr[i];
                break;
            }
        }


        string sendStr = string.Format("{0}&{1}&{2}&{3}&{4}&{5}&{6}", PlayerIp, DeviceName, info.type, info.logString, stack, DeviceModelStr, detials);
        byte[] bs = System.Text.Encoding.UTF8.GetBytes(sendStr);
        XHashTable headers = new XHashTable();
        headers.Add("Content-Type", "application/x-www-form-urlencoded");
        WWW www = new WWW(ClientErrCommitPath, bs, headers);
        yield return www;
        LogToFile("game.log", string.Format("<{0}>{1}\n{2}", LogType.Log, "PHP-Result:", www.error));
        UnityEngine.Object.Destroy((GameObject)args);
    }
    
static void OnHandleUnity3DLog(string logString, string stackTrace, LogType type)
{
        if (!IsDebugBuild)
            return;
        
        LogToFile("game.log", string.Format("<{0}>{1}\n{2}", type, logString, stackTrace));


         if (type == LogType.Log || type == LogType.Warning)
             return;


#if !UNITY_EDITOR
        var tmpObj = new GameObject();
        XComitErrInfo info = new XComitErrInfo();
        info.type = type;
        info.logString = logString;
        info.stack = stackTrace;
        TmpCmtErrInfo = info;
        tmpObj.AddComponent<MonoBehaviour>().StartCoroutine(CommitErrorToWeb(tmpObj));
#endif
    }
0 0
原创粉丝点击