Пример #1
0
    public void WriteLog(string message)
    {
#if UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_WIN
        //string strPath = Application.persistentDataPath + "/M1TempLog.txt";

        lock (writeAndroidSDCardLock)
        {
            try
            {
                StreamWriter sw;
                if (File.Exists(strPath))
                {
                    sw = File.AppendText(strPath);
                }
                else
                {
                    sw = File.CreateText(strPath);
                }

                if (sw != null)
                {
                    var sb = HobaText.GetStringBuilder();
                    sb.AppendFormat("[{0}]\t{1}", System.DateTime.Now.TimeOfDay, message);
                    sw.WriteLine(sb.ToString());

                    sw.Close();
                    sw.Dispose();
                }
            }
            catch (Exception)
            {
            }
        }
#endif
    }
Пример #2
0
    /*
     *  /// HashToMD5Hex
     *  public static string HashToMD5Hex(string sourceStr)
     *  {
     *          byte[] Bytes = Encoding.UTF8.GetBytes(sourceStr);
     *          using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
     *          {
     *                  byte[] result = md5.ComputeHash(Bytes);
     *                  StringBuilder builder = HobaString.GetStaticStringBuilder();
     *                  for (int i = 0; i < result.Length; i++)
     *                          builder.Append(result[i].ToString("x2"));
     *                  return builder.ToString();
     *          }
     *  }
     *
     *  /// 计算字符串的MD5值
     *  public static string md5(string source)
     *  {
     *          MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
     *          byte[] data = System.Text.Encoding.UTF8.GetBytes(source);
     *          byte[] md5Data = md5.ComputeHash(data, 0, data.Length);
     *          md5.Clear();
     *
     *          string destString = "";
     *          for (int i = 0; i < md5Data.Length; i++)
     *          {
     *                  destString += System.Convert.ToString(md5Data[i], 16).PadLeft(2, '0');
     *          }
     *          destString = destString.PadLeft(32, '0');
     *          return destString;
     *  }
     */

    /// 计算文件的MD5值
    public static string md5file(string file)
    {
        try
        {
            if (!File.Exists(file))
            {
                return("0");
            }

            FileStream fs = new FileStream(file, FileMode.Open);

            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(fs);
            fs.Close();

            StringBuilder sb = HobaText.GetStringBuilder();
            for (int i = 0; i < retVal.Length; i++)
            {
                sb.Append(retVal[i].ToString("x2"));
            }
            return(sb.ToString());
        }
        catch (Exception ex)
        {
            throw new Exception("md5file() fail, error:" + ex.Message);
        }
    }
Пример #3
0
    private static void ReportException(int type, string name, string reason, string stackTrace, bool quitProgram)
    {
        ConfigCrashReporterType();

        string extraInfo = "";
        Dictionary <string, string> extras = null;

        if (_LogCallbackExtrasHandler != null)
        {
            extras = _LogCallbackExtrasHandler();
        }
        if (extras == null || extras.Count == 0)
        {
            extras = new Dictionary <string, string> ();
            extras.Add("UnityVersion", Application.unityVersion);
        }

        if (extras != null && extras.Count > 0)
        {
            if (!extras.ContainsKey("UnityVersion"))
            {
                extras.Add("UnityVersion", Application.unityVersion);
            }

            StringBuilder builder = HobaText.GetStringBuilder();
            foreach (KeyValuePair <string, string> kvp in extras)
            {
                builder.Append(HobaText.Format("\"{0}\" : \"{1}\"", kvp.Key, kvp.Value)).Append(" , ");
            }
            extraInfo = HobaText.Format("{{ {0} }}", builder.ToString().TrimEnd(" , ".ToCharArray()));
        }

        // 4 is C# exception
        _BuglyReportException(4, name, reason, stackTrace, extraInfo, quitProgram);
    }
Пример #4
0
    public void WriteLine(string message)
    {
        lock (_lock)
        {
            try
            {
                StreamWriter sw;
                if (File.Exists(strPath))
                {
                    sw = File.AppendText(strPath);
                }
                else
                {
                    sw = File.CreateText(strPath);
                }

                if (sw != null)
                {
                    var sb = HobaText.GetStringBuilder();
                    sb.AppendFormat("[{0}]\t{1}", System.DateTime.Now.TimeOfDay, message);
                    sw.WriteLine(sb.ToString());

                    sw.Close();
                    sw.Dispose();
                }
            }
            catch (Exception)
            {
            }
        }
    }
Пример #5
0
    public static string GenerateApplicationInfo()
    {
        var sb = HobaText.GetStringBuilder();

        sb.AppendLine();
        sb.AppendFormat("productName: {0}\n", Application.productName);
        sb.AppendFormat("bundleIdentifier: {0}\n", Application.identifier);
        sb.AppendFormat("appVersion: {0}\n", Application.version);

        return(sb.ToString());
    }
Пример #6
0
    void Update()
    {
        float cur_time    = Time.time;
        float fill_amount = (_EndTime - cur_time) / _MaxTime;

        if (_IsReverse)
        {
            _Sprite.fillAmount = 1 - fill_amount;
        }
        else
        {
            _Sprite.fillAmount = fill_amount;
        }

        var lastSec = Mathf.Abs(_EndTime - cur_time);

        if (lastSec <= 0.01f || (cur_time > _EndTime))
        {
            if (_CDTimeTxt != null && _CDTimeTxt.gameObject.activeSelf)
            {
                _CDTimeTxt.text = "";
                _CDTimeTxt.gameObject.SetActive(false);
            }

            if (_OnFinish != null)
            {
                _OnFinish.Call();
                _OnFinish.Release();
                _OnFinish = null;
            }
            gameObject.SetActive(false);
        }
        else
        {
            if (_CDTimeTxt != null)
            {
                if (!_CDTimeTxt.gameObject.activeSelf)
                {
                    _CDTimeTxt.gameObject.SetActive(true);
                }

                if (_LastSeceond != Mathf.CeilToInt(lastSec))
                {
                    _LastSeceond = Mathf.CeilToInt(lastSec);

                    var sb = HobaText.GetStringBuilder();
                    sb.AppendFormat("{0}", Mathf.CeilToInt(lastSec));
                    _CDTimeTxt.text = sb.ToString();
                }
            }
        }
    }
Пример #7
0
    public static string Normalize(this string str)
    {
        StringBuilder builder = HobaText.GetStringBuilder(str);
        int           len     = str.Length;

        for (int i = 0; i < len; ++i)
        {
            if (str[i] == '\\')
            {
                builder[i] = '/';
            }
        }
        return(builder.ToString());
    }
Пример #8
0
 public static String GetLog()
 {
     lock (m_logs)
     {
         var strBuilder = HobaText.GetStringBuilder();
         strBuilder.AppendLine("=============IO Log=============");
         Double totalTime = 0;
         for (int i = 0; i < m_logs.Count; ++i)
         {
             var log = m_logs[i];
             totalTime += log.time;
             strBuilder.AppendFormat("{0} @ {1} ms", log.file, log.time * 1000);
             strBuilder.AppendLine();
         }
         strBuilder.AppendFormat("total time: {0} ms", totalTime * 1000);
         strBuilder.AppendLine();
         return(strBuilder.ToString());
     }
 }
Пример #9
0
    public static string GenerateDeviceInfo()
    {
        var sb = HobaText.GetStringBuilder();

        sb.AppendLine();
        sb.AppendFormat("locale: {0}\n", CPlatformConfig.GetLocale());
        sb.AppendFormat("platform: {0}\n", CPlatformConfig.GetPlatForm());
        sb.AppendFormat("deviceModel: {0}\n", SystemInfo.deviceModel);
        sb.AppendFormat("deviceName: {0}\n", SystemInfo.deviceName);
        sb.AppendFormat("deviceType: {0}\n", SystemInfo.deviceType);
        sb.AppendFormat("deviceUniqueIdentifier: {0}\n", SystemInfo.deviceUniqueIdentifier);
        sb.AppendFormat("operatingSystem: {0}\n", SystemInfo.operatingSystem);
        sb.AppendFormat("processorCount: {0}\n", SystemInfo.processorCount);
        sb.AppendFormat("processorType: {0}\n", SystemInfo.processorType);
        sb.AppendFormat("processorFrequency: {0}\n", SystemInfo.processorFrequency);
        sb.AppendFormat("graphicsDeviceName: {0}\n", SystemInfo.graphicsDeviceName);
        sb.AppendFormat("systemMemorySize: {0}\n", SystemInfo.systemMemorySize);
        sb.AppendFormat("graphicsMemorySize: {0}\n", SystemInfo.graphicsMemorySize);

        return(sb.ToString());
    }
Пример #10
0
    public static string NormalizeDir(this string str)
    {
        StringBuilder builder = HobaText.GetStringBuilder(str);
        int           len     = str.Length;

        for (int i = 0; i < len; ++i)
        {
            if (str[i] == '\\')
            {
                builder[i] = '/';
            }
        }

        if (len > 0)
        {
            char last = str[len - 1];
            if (last != '/')
            {
                builder.Append('/');
            }
        }
        return(builder.ToString());
    }
Пример #11
0
        public override string ToString()
        {
            var sb = HobaText.GetStringBuilder();

            sb.Append("<b>Pointer Input Module of type: </b>");
            sb.Append(GetType());
            sb.AppendLine();
            for (int i = 0; i < _lastPoints.Count; ++i)
            {
                //if (pointer.Value == null)
                //{
                //    continue;
                //}

                //PointerEventData point = pointer.Value;
                //int key=pointer.Key;
                var pointer            = _lastPoints[i];
                PointerEventData point = pointer.data;
                int key = point.pointerId;

                if (debugParam.Id != -1 && point.pointerId != debugParam.Id)
                {
                    continue;
                }

                sb.AppendLine("<B>Pointer:</b> " + key);
                sb.AppendLine("<B>IsPointUI:</b> " + pointer.notEmpty);

                if (debugParam.isWantPos)
                {
                    sb.AppendLine("<b>Position</b>: " + point.position);
                    sb.AppendLine("<b>delta</b>: " + point.delta);
                }
                if (debugParam.isWantHover)
                {
                    if (point.pointerEnter != null)
                    {
                        sb.AppendLine("<b>pointerEnter</b>: " + point.pointerEnter);
                    }
                    else
                    {
                        sb.AppendLine("<b>pointerEnter</b>: Null");
                    }
                }
                if (debugParam.isWantPress)
                {
                    sb.AppendLine("<b>eligibleForClick</b>: " + point.eligibleForClick);

                    if (point.pointerPress != null)
                    {
                        sb.AppendLine("<b>pointerPress</b>: " + point.pointerPress);
                    }
                    else
                    {
                        sb.AppendLine("<b>pointerPress</b>: Null");
                    }
                    if (point.lastPress != null)
                    {
                        sb.AppendLine("<b>lastPress</b>: " + point.lastPress);
                    }
                    else
                    {
                        sb.AppendLine("<b>lastPress</b>: Null");
                    }
                }
                if (debugParam.isWantDrag)
                {
                    if (point.pointerDrag != null)
                    {
                        sb.AppendLine("<b>pointerDrag</b>: " + point.pointerDrag);
                    }
                    else
                    {
                        sb.AppendLine("<b>pointerDrag</b>: Null");
                    }

                    sb.AppendLine("<b>Use Drag Threshold</b>: " + point.useDragThreshold);
                }
                if (debugParam.isWantRay)
                {
                    sb.AppendLine("<b>Current Rayast:</b>");
                    sb.AppendLine(point.pointerCurrentRaycast.ToString());
                    sb.AppendLine("<b>Press Rayast:</b>");
                    sb.AppendLine(point.pointerPressRaycast.ToString());
                }
            }
            return(sb.ToString());
        }
Пример #12
0
    private static int FindChild(IntPtr L)
    {
        int       count = LuaDLL.lua_gettop(L);
        const int nRet  = 1;

        if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(GameObject), typeof(string)))
        {
            GameObject obj = LuaScriptMgr.GetUnityObject <GameObject>(L, 1);
            if (obj == null)
            {
                LuaScriptMgr.Instance.CallOnTraceBack();
                HobaDebuger.LogError("FindChild: param 1 must be GameObject");
                LuaDLL.lua_pushnil(L);
                return(CheckReturnNum(L, count, nRet));
            }
            string childname = LuaScriptMgr.GetString(L, 2);
#if UNITY_EDITOR
            //HobaDebuger.LogFormat("Lua FindChild {0}", childname);
#endif
            GameObject result = null;
            if (childname.Contains("/"))
            {
                Transform cur_node = obj.transform;

                //Split
                var sl = HobaText.GetStringList();
                var sb = HobaText.GetStringBuilder();
                for (int i = 0; i < childname.Length; ++i)
                {
                    char c = childname[i];
                    if (c == '/')
                    {
                        sl.Add(sb.ToString());      //use
                        sb.Length = 0;
                    }
                    else
                    {
                        sb.Append(c);
                    }
                }
                if (sb.Length > 0)
                {
                    sl.Add(sb.ToString());      //use
                    sb.Length = 0;
                }

                //Use
                for (int i = 0; i < sl.Count; i++)
                {
                    cur_node = cur_node.Find(sl[i]);
                    if (cur_node == null)
                    {
                        result = null;
                        break;
                    }
                    if (i == sl.Count - 1)
                    {
                        result = cur_node.gameObject;
                    }
                }
            }
            else
            {
                result = Util.FindChildDirect(obj, childname, true);
            }

            LuaScriptMgr.Push(L, result);
            return(CheckReturnNum(L, count, nRet));
        }
        else
        {
            LogParamError("FindChild", count);
            LuaDLL.lua_pushnil(L);
            return(CheckReturnNum(L, count, nRet));
        }
    }
Пример #13
0
    public override void SetVerticesDirty()
    {
        //收集富文本信息
        _OriginText = m_Text;
        MatchCollection collections = _TextRegex.Matches(_OriginText);

        _GraphicItemModels.Clear();
        _TextLinkModels.Clear();
        int last_index  = 0;
        int start_index = 0;
        var sb          = HobaText.GetStringBuilder();

        for (var i = 0; i < collections.Count; i++)
        {
            Match  match       = collections[i];
            int    match_index = match.Index;
            string type        = match.Groups[1].Value;
            if (type == ID_EMOTION)
            {
                //TODO: 改成参数
                int my_size = (int)(this.fontSize * GraphicScale);

                sb.Append(_OriginText.Substring(last_index, match_index - last_index));
                start_index = sb.Length;
                string quad = HobaText.Format(TEXT_QUAD, match.Groups[2].Value, (int)(fontSize), (GraphicScale));
                sb.Append(quad);
                GTextEmotionModel model = new GTextEmotionModel();
                model.TextIndex = start_index;
                model.Size      = my_size;

                model.SpriteName = TranslateEmoji(match.Groups[2].Value);

                _GraphicItemModels.Add(model);
            }
            else if (type == ID_LINK)
            {
                string seg = _OriginText.Substring(last_index, match_index - last_index);
                sb.Append(seg);
                start_index = sb.Length;

                GTextLinkModel linkModel = new GTextLinkModel();

                //string link_txt;
                string inner_txt;
                string color_text;

                //colorful text
                MatchCollection collections_con = _LinkRegex.Matches(match.Groups[2].Value);
                if (collections_con.Count == 1 && collections_con[0].Groups.Count == 3)
                {
                    //link_txt = string.Format(TEXT_LINK, collections_con[0].Groups[1].Value, collections_con[0].Groups[2].Value);
                    color_text = collections_con[0].Groups[1].Value;
                    inner_txt  = collections_con[0].Groups[2].Value;
                }
                else
                {
                    //link_txt = string.Format(TEXT_LINK, "yellow", match.Groups[2].Value);
                    color_text = "yellow";
                    inner_txt  = match.Groups[2].Value;
                }

                sb.AppendFormat("<color={0}>", color_text);
                linkModel.StartIndex = sb.Length - 1;
                sb.AppendFormat(inner_txt);
                linkModel.EndIndex = sb.Length - 1;
                sb.Append("</color>");

                //linkModel.Text = inner_txt;

                _TextLinkModels.Add(linkModel);
            }
            last_index = match_index + match.Value.Length;
        }
        sb.Append(_OriginText.Substring(last_index, _OriginText.Length - last_index));
        _BuildText = sb.ToString();

        //重绘请求
        base.SetVerticesDirty();
    }
Пример #14
0
    static int FindChild(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        GameObject obj  = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
        string     arg0 = LuaScriptMgr.GetLuaString(L, 2);
        GameObject g    = null;

#if UNITY_EDITOR
        //Debug.LogFormat("GameObject FindChild {0}", arg0);
#endif
        if (arg0.Contains("/"))
        {
            Transform cur_node = obj.transform;
            //Split
            var sl = HobaText.GetStringList();
            var sb = HobaText.GetStringBuilder();
            for (int i = 0; i < arg0.Length; ++i)
            {
                char c = arg0[i];
                if (c == '/')
                {
                    sl.Add(sb.ToString());      //use
                    sb.Length = 0;
                }
                else
                {
                    sb.Append(c);
                }
            }
            if (sb.Length > 0)
            {
                sl.Add(sb.ToString());      //use
                sb.Length = 0;
            }

            //Use
            for (int i = 0; i < sl.Count; i++)
            {
                cur_node = cur_node.Find(sl[i]);
                if (cur_node == null)
                {
                    g = null;
                    break;
                }
                if (i == sl.Count - 1)
                {
                    g = cur_node.gameObject;
                }
            }
        }
        else
        {
            Transform t = obj.transform.Find(arg0);
            if (t != null)
            {
                g = t.gameObject;
            }
        }

        LuaScriptMgr.Push(L, g);

        return(1);
    }
Пример #15
0
    private static void _reportException(bool uncaught, string name, string reason, string stackTrace)
    {
        if (string.IsNullOrEmpty(name))
        {
            return;
        }

        if (string.IsNullOrEmpty(stackTrace))
        {
            stackTrace = StackTraceUtility.ExtractStackTrace();
        }

        if (string.IsNullOrEmpty(stackTrace))
        {
            stackTrace = "Empty";
        }
        else
        {
            try {
                string[] frames = stackTrace.Split('\n');

                if (frames != null && frames.Length > 0)
                {
                    StringBuilder trimFrameBuilder = HobaText.GetStringBuilder();

                    string frame = null;
                    int    count = frames.Length;
                    for (int i = 0; i < count; i++)
                    {
                        frame = frames [i];

                        if (string.IsNullOrEmpty(frame) || string.IsNullOrEmpty(frame.Trim()))
                        {
                            continue;
                        }

                        frame = frame.Trim();

                        // System.Collections.Generic
                        if (frame.StartsWith("System.Collections.Generic.") || frame.StartsWith("ShimEnumerator"))
                        {
                            continue;
                        }
                        if (frame.StartsWith("Bugly"))
                        {
                            continue;
                        }
                        if (frame.Contains("..ctor"))
                        {
                            continue;
                        }

                        int start = frame.ToLower().IndexOf("(at");
                        int end   = frame.ToLower().IndexOf("/assets/");

                        if (start > 0 && end > 0)
                        {
                            trimFrameBuilder.AppendFormat("{0}(at {1}", frame.Substring(0, start).Replace(":", "."), frame.Substring(end));
                        }
                        else
                        {
                            trimFrameBuilder.Append(frame.Replace(":", "."));
                        }

                        trimFrameBuilder.AppendLine();
                    }

                    stackTrace = trimFrameBuilder.ToString();
                }
            } catch {
                PrintLog(LogSeverity.LogWarning, "{0}", "Error to parse the stack trace");
            }
        }

        PrintLog(LogSeverity.LogError, "ReportException: {0} {1}\n*********\n{2}\n*********", name, reason, stackTrace);

        _uncaughtAutoReportOnce = uncaught && _autoQuitApplicationAfterReport;

        ReportException(uncaught ? EXCEPTION_TYPE_UNCAUGHT : EXCEPTION_TYPE_CAUGHT, name, reason, stackTrace, uncaught && _autoQuitApplicationAfterReport);
    }
Пример #16
0
    private static void _HandleException(System.Exception e, string message, bool uncaught)
    {
        if (e == null)
        {
            return;
        }

        if (!IsInitialized)
        {
            return;
        }

        string name   = e.GetType().Name;
        string reason = e.Message;

        if (!string.IsNullOrEmpty(message))
        {
            reason = HobaText.Format("{0}{1}***{2}", reason, Environment.NewLine, message);
        }

        StringBuilder stackTraceBuilder = HobaText.GetStringBuilder();

        StackTrace stackTrace = new StackTrace(e, true);
        int        count      = stackTrace.FrameCount;

        for (int i = 0; i < count; i++)
        {
            StackFrame frame = stackTrace.GetFrame(i);

            stackTraceBuilder.AppendFormat("{0}.{1}", frame.GetMethod().DeclaringType.Name, frame.GetMethod().Name);

            ParameterInfo[] parameters = frame.GetMethod().GetParameters();
            if (parameters == null || parameters.Length == 0)
            {
                stackTraceBuilder.Append(" () ");
            }
            else
            {
                stackTraceBuilder.Append(" (");

                int pcount = parameters.Length;

                ParameterInfo param = null;
                for (int p = 0; p < pcount; p++)
                {
                    param = parameters [p];
                    stackTraceBuilder.AppendFormat("{0} {1}", param.ParameterType.Name, param.Name);

                    if (p != pcount - 1)
                    {
                        stackTraceBuilder.Append(", ");
                    }
                }
                param = null;

                stackTraceBuilder.Append(") ");
            }

            string fileName = frame.GetFileName();
            if (!string.IsNullOrEmpty(fileName) && !fileName.ToLower().Equals("unknown"))
            {
                fileName = fileName.Replace("\\", "/");

                int loc = fileName.ToLower().IndexOf("/assets/");
                if (loc < 0)
                {
                    loc = fileName.ToLower().IndexOf("assets/");
                }

                if (loc > 0)
                {
                    fileName = fileName.Substring(loc);
                }

                stackTraceBuilder.AppendFormat("(at {0}:{1})", fileName, frame.GetFileLineNumber());
            }
            stackTraceBuilder.AppendLine();
        }

        // report
        _reportException(uncaught, name, reason, stackTraceBuilder.ToString());
    }