コード例 #1
0
        public void PutLog(Level lv, string log, bool prefix = true, params RichTextStyle[] styles)
        {
            if (log == null)
            {
                log = "";
            }
            RichTextStyle defStyle;

            switch (lv)
            {
            case Level.info:
                defStyle = infoStyle;
                break;

            case Level.warning:
                defStyle = warningStyle;
                break;

            case Level.error:
                defStyle = errorStyle;
                break;

            case Level.debug:
                defStyle = debugStyle;
                break;

            default:
                defStyle       = new RichTextStyle();
                defStyle.color = "#ffffff";
                break;
            }
            defStyle.start = 0;
            defStyle.end   = log.Length;
            LinkedList <RichTextStyle> setting = null;

            RichTextStyle.AddStyle(ref setting, defStyle, true);
            for (int i = 0; i < styles.Length; i++)
            {
                RichTextStyle.AddStyle(ref setting, styles[i], true);
            }
            RichTextStyle.Optimization(setting);
            string s = RichTextStyle.UseStyles(setting, log);

            if (prefix)
            {
                string pcolor = pColors[Mathf.Min(pColors.Length - 1, pid)];
                string pname  = pid > 0 ? ("P" + pid) : "MAIN";
                string pre    = string.Format("<color={0}>[<i>{1}</i>,{2}] ></color> ", pcolor, pname, System.DateTime.Now.ToString("d/M HH:mm:ss.ffff"));
                s = pre + s;
            }

            logs.AddLast(s);
            maxLog = Mathf.Max(10, maxLog);
            while (logs.Count > maxLog)
            {
                logs.RemoveFirst();
            }
            newLog = true;
            if (m_OpenWhenPrint && !mOpened)
            {
                Open = true;
            }
        }
コード例 #2
0
        void formatInput()
        {
            mTimer -= Time.unscaledDeltaTime;
            if (mTimer < 0)
            {
                mTimer = 1.6f;
            }
            bool newCur = mTimer <= 0.8f;

            if (mText != null && !ireader.IsDirty && (newCur == mCursorLight))
            {
                return;
            }
            mCursorLight = newCur;
            mText        = ireader.Text;
            if (mText == null)
            {
                mText = "";
            }

            string curColor = mCursorLight ? "#ffffffff" : "#808080ff";
            LinkedList <RichTextStyle> styles = null;
            int off;

            if (useStyle)
            {
                if (mReader == null)
                {
                    wordReard.Reload(mText);
                    off = wordReard.getTempOffset();
                    string atomStr;
                    while (wordReard.hasNext())
                    {
                        wordReard.fixCharsOffset();
                        noteStyle.start = off;
                        noteStyle.end   = wordReard.getTempOffset();
                        RichTextStyle.AddStyle(ref styles, noteStyle, true);
                        off     = wordReard.getTempOffset();
                        atomStr = wordReard.nextWord(mEngine);
                        if (atomStr == null)
                        {
                            break;
                        }
                        RichTextStyle set;
                        if (RTSConverter.getCompileValue(atomStr) != null || atomStr.StartsWith("\""))
                        {
                            set = valueStyle;
                        }
                        else if (mEngine.containsVar(atomStr))
                        {
                            set = variableStyle;
                        }
                        else
                        {
                            set = mEngine.isKeyWord(atomStr) ? keyWordStyle : normalStyle;
                        }
                        set.start = off;
                        set.end   = wordReard.getTempOffset();
                        RichTextStyle.AddStyle(ref styles, set, true);
                        off = wordReard.getTempOffset();
                    }
                }
                else
                {
                    readStyle.start = 0;
                    readStyle.end   = mText.Length;
                    RichTextStyle.AddStyle(ref styles, readStyle, true);
                }
            }
            off = Mathf.Min(ireader.SelectStart, ireader.SelectEnd);
            int end = Mathf.Max(ireader.SelectStart, ireader.SelectEnd);

            selectionStyle.start = off;
            selectionStyle.end   = end;
            RichTextStyle.AddStyle(ref styles, selectionStyle, true);
            int curIndex = ireader.SelectStart;

            if (curIndex == ireader.Length)
            {
                mText += "_";
            }
            else
            {
                char c = mText[curIndex];
                if (c == ' ')
                {
                    mText = mText.Remove(curIndex, 1);
                    mText = mText.Insert(curIndex, "_");
                }
                else if (c == '\n')
                {
                    mText = mText.Insert(curIndex, "_");
                }
            }

            RichTextStyle.AddStyle(ref styles, new RichTextStyle(curIndex, curIndex + 1, curColor, mReader == null ? 0 : readStyle.size, 0), true);
            RichTextStyle.Optimization(styles);

            mText = RichTextStyle.UseStyles(styles, mText, RichTextType.gui_style);
            if (mReader != null)
            {
                mText = mReaderName + "$" + mText;
            }
        }