ParseSymbol() 정적인 공개 메소드

Parse an embedded symbol, such as [FFAA00] (set color) or [-] (undo color change). Returns whether the index was adjusted.
static public ParseSymbol ( string text, int &index ) : bool
text string
index int
리턴 bool
    void Update()
    {
        if (mReset)
        {
            mOffset = 0;
            mReset  = false;
            mLabel  = GetComponent <UILabel>();
            mText   = mLabel.processedText;
        }

        if (mOffset < mText.Length && mNextChar <= RealTime.time)
        {
            charsPerSecond = Mathf.Max(1, charsPerSecond);

            // Periods and end-of-line characters should pause for a longer time.
            float delay = 1f / charsPerSecond;
            char  c     = mText[mOffset];
            if (c == '.' || c == '\n' || c == '!' || c == '?')
            {
                delay *= 4f;
            }

            // Automatically skip all symbols
            NGUIText.ParseSymbol(mText, ref mOffset);

            mNextChar   = RealTime.time + delay;
            mLabel.text = mText.Substring(0, ++mOffset);
        }
    }
예제 #2
0
    static string ParseSymbol(string str, int l)
    {
        var value = str.Substring(0, l);

        if (l < str.Length)
        {
            var idx = str.LastIndexOf("[", l - 1);
            if (-1 != idx)
            {
                if (idx < str.Length - 2 && '-' == str[idx + 1] && ']' == str[idx + 2])
                {
                    idx = str.LastIndexOf("[", idx - 1);
                }

                if (NGUIText.ParseSymbol(str, ref idx))
                {
                    var idx2 = str.IndexOf("[-]");
                    if (-1 != idx2 && l <= idx2 + 2)
                    {
                        value = str.Substring(0, idx2 + 3);
                    }
                }
            }
        }
        return(value);
    }
예제 #3
0
 static public int ParseSymbol_s(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             System.String a1;
             checkType(l, 1, out a1);
             System.Int32 a2;
             checkType(l, 2, out a2);
             var ret = NGUIText.ParseSymbol(a1, ref a2);
             pushValue(l, true);
             pushValue(l, ret);
             pushValue(l, a2);
             return(3);
         }
         else if (argc == 10)
         {
             System.String a1;
             checkType(l, 1, out a1);
             System.Int32 a2;
             checkType(l, 2, out a2);
             BetterList <UnityEngine.Color> a3;
             checkType(l, 3, out a3);
             System.Boolean a4;
             checkType(l, 4, out a4);
             System.Int32 a5;
             checkType(l, 5, out a5);
             System.Boolean a6;
             checkType(l, 6, out a6);
             System.Boolean a7;
             checkType(l, 7, out a7);
             System.Boolean a8;
             checkType(l, 8, out a8);
             System.Boolean a9;
             checkType(l, 9, out a9);
             System.Boolean a10;
             checkType(l, 10, out a10);
             var ret = NGUIText.ParseSymbol(a1, ref a2, a3, a4, ref a5, ref a6, ref a7, ref a8, ref a9, ref a10);
             pushValue(l, true);
             pushValue(l, ret);
             pushValue(l, a2);
             pushValue(l, a5);
             pushValue(l, a6);
             pushValue(l, a7);
             pushValue(l, a8);
             pushValue(l, a9);
             pushValue(l, a10);
             return(9);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    void Update()
    {
        if (mReset)
        {
            mOffset = 0;
            mReset  = false;
            mLabel  = GetComponent <UILabel>();
            mText   = mLabel.processedText;
        }

        if (mOffset < mText.Length && mNextChar <= RealTime.time)
        {
            charsPerSecond = Mathf.Max(1, charsPerSecond);

            // Periods and end-of-line characters should pause for a longer time.
            float delay = 1f / charsPerSecond;
            char  c     = mText[mOffset];

            if (c == '.')
            {
                if (mOffset + 2 < mText.Length && mText[mOffset + 1] == '.' && mText[mOffset + 2] == '.')
                {
                    delay   += delayOnPeriod * 3f;
                    mOffset += 2;
                }
                else
                {
                    delay += delayOnPeriod;
                }
            }
            else if (c == '!' || c == '?')
            {
                delay += delayOnPeriod;
            }
            else if (c == '\n')
            {
                delay += delayOnNewLine;
            }

            // Automatically skip all symbols
            NGUIText.ParseSymbol(mText, ref mOffset);

            mNextChar   = RealTime.time + delay;
            mLabel.text = mText.Substring(0, ++mOffset);

            // If a scroll view was specified, update its position
            if (scrollView != null)
            {
                scrollView.UpdatePosition();
            }
        }
    }
예제 #5
0
    private static int ParseSymbol(IntPtr L)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(L);
            if (num == 2 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int)))
            {
                string text  = ToLua.ToString(L, 1);
                int    n     = (int)LuaDLL.lua_tonumber(L, 2);
                bool   value = NGUIText.ParseSymbol(text, ref n);
                LuaDLL.lua_pushboolean(L, value);
                LuaDLL.lua_pushinteger(L, n);
                result = 2;
            }
            else if (num == 10 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int), typeof(BetterList <Color>), typeof(bool), typeof(int), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool)))
            {
                string             text2       = ToLua.ToString(L, 1);
                int                n2          = (int)LuaDLL.lua_tonumber(L, 2);
                BetterList <Color> colors      = (BetterList <Color>)ToLua.ToObject(L, 3);
                bool               premultiply = LuaDLL.lua_toboolean(L, 4);
                int                n3          = (int)LuaDLL.lua_tonumber(L, 5);
                bool               value2      = LuaDLL.lua_toboolean(L, 6);
                bool               value3      = LuaDLL.lua_toboolean(L, 7);
                bool               value4      = LuaDLL.lua_toboolean(L, 8);
                bool               value5      = LuaDLL.lua_toboolean(L, 9);
                bool               value6      = LuaDLL.lua_toboolean(L, 10);
                bool               value7      = NGUIText.ParseSymbol(text2, ref n2, colors, premultiply, ref n3, ref value2, ref value3, ref value4, ref value5, ref value6);
                LuaDLL.lua_pushboolean(L, value7);
                LuaDLL.lua_pushinteger(L, n2);
                LuaDLL.lua_pushinteger(L, n3);
                LuaDLL.lua_pushboolean(L, value2);
                LuaDLL.lua_pushboolean(L, value3);
                LuaDLL.lua_pushboolean(L, value4);
                LuaDLL.lua_pushboolean(L, value5);
                LuaDLL.lua_pushboolean(L, value6);
                result = 8;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, "invalid arguments to method: NGUIText.ParseSymbol");
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
예제 #6
0
    static int ParseSymbol(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int)))
            {
                string arg0 = ToLua.ToString(L, 1);
                int    arg1 = (int)LuaDLL.lua_tonumber(L, 2);
                bool   o    = NGUIText.ParseSymbol(arg0, ref arg1);
                LuaDLL.lua_pushboolean(L, o);
                LuaDLL.lua_pushinteger(L, arg1);
                return(2);
            }
            else if (count == 10 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int), typeof(BetterList <UnityEngine.Color>), typeof(bool), typeof(int), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool)))
            {
                string arg0 = ToLua.ToString(L, 1);
                int    arg1 = (int)LuaDLL.lua_tonumber(L, 2);
                BetterList <UnityEngine.Color> arg2 = (BetterList <UnityEngine.Color>)ToLua.ToObject(L, 3);
                bool arg3 = LuaDLL.lua_toboolean(L, 4);
                int  arg4 = (int)LuaDLL.lua_tonumber(L, 5);
                bool arg5 = LuaDLL.lua_toboolean(L, 6);
                bool arg6 = LuaDLL.lua_toboolean(L, 7);
                bool arg7 = LuaDLL.lua_toboolean(L, 8);
                bool arg8 = LuaDLL.lua_toboolean(L, 9);
                bool arg9 = LuaDLL.lua_toboolean(L, 10);
                bool o    = NGUIText.ParseSymbol(arg0, ref arg1, arg2, arg3, ref arg4, ref arg5, ref arg6, ref arg7, ref arg8, ref arg9);
                LuaDLL.lua_pushboolean(L, o);
                LuaDLL.lua_pushinteger(L, arg1);
                LuaDLL.lua_pushinteger(L, arg4);
                LuaDLL.lua_pushboolean(L, arg5);
                LuaDLL.lua_pushboolean(L, arg6);
                LuaDLL.lua_pushboolean(L, arg7);
                LuaDLL.lua_pushboolean(L, arg8);
                LuaDLL.lua_pushboolean(L, arg9);
                return(8);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: NGUIText.ParseSymbol"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
예제 #7
0
    private IEnumerator SignalProcess(UILabel label, String fullText, Int32 targetSignal, Dictionary <Int32, Int32> dynamicCharsPerSecond, Dictionary <Int32, Single> waitList)
    {
        Int32  currentOffset = 0;
        Int32  length        = fullText.Length;
        Single nextCharTime  = 0f;
        Int32  ff9Signal     = 0;

        Dialog.DialogImage insertImage    = (Dialog.DialogImage)null;
        Single             charsPerSecond = 0f;

        while (currentOffset < length)
        {
            while (nextCharTime <= RealTime.time)
            {
                charsPerSecond = ((!dynamicCharsPerSecond.ContainsKey(currentOffset)) ? Mathf.Max(1f, charsPerSecond) : ((Single)dynamicCharsPerSecond[currentOffset]));
                if (waitList.ContainsKey(currentOffset) && waitList[currentOffset] > 0f)
                {
                    Int32  key2;
                    Int32  key = key2 = currentOffset;
                    Single num = waitList[key2];
                    waitList[key] = num - ((!HonoBehaviorSystem.Instance.IsFastForwardModeActive()) ? Time.deltaTime : (Time.deltaTime * (Single)FF9StateSystem.Settings.FastForwardFactor));
                    break;
                }
                if (label.supportEncoding)
                {
                    while (NGUIText.ParseSymbol(fullText, ref currentOffset, ref ff9Signal, ref insertImage))
                    {
                    }
                }
                currentOffset++;
                Single delay = (!HonoBehaviorSystem.Instance.IsFastForwardModeActive()) ? (1f / charsPerSecond) : (1f / (charsPerSecond * (Single)FF9StateSystem.Settings.FastForwardFactor));
                if (nextCharTime == 0f || nextCharTime + delay > RealTime.time)
                {
                    nextCharTime = RealTime.time + delay;
                }
                else
                {
                    nextCharTime += delay;
                }
                NGUIText.ProcessFF9Signal(ref ff9Signal);
            }
            yield return(new WaitForEndOfFrame());
        }
        yield break;
    }
예제 #8
0
    private void Update()
    {
        if (mReset)
        {
            mOffset = 0;
            mReset  = false;
            mLabel  = GetComponent <UILabel>();
            mText   = mLabel.processedText;
        }
        if (mOffset >= mText.Length || !(mNextChar <= RealTime.time))
        {
            return;
        }
        charsPerSecond = Mathf.Max(1, charsPerSecond);
        float num = 1f / (float)charsPerSecond;
        char  c   = mText[mOffset];

        if (c == '.')
        {
            if (mOffset + 2 < mText.Length && mText[mOffset + 1] == '.' && mText[mOffset + 2] == '.')
            {
                num     += delayOnPeriod * 3f;
                mOffset += 2;
            }
            else
            {
                num += delayOnPeriod;
            }
        }
        else if (c == '!' || c == '?')
        {
            num += delayOnPeriod;
        }
        else if (c == '\n')
        {
            num += delayOnNewLine;
        }
        NGUIText.ParseSymbol(mText, ref mOffset);
        mNextChar   = RealTime.time + num;
        mLabel.text = mText.Substring(0, ++mOffset);
        if (scrollView != null)
        {
            scrollView.UpdatePosition();
        }
    }
예제 #9
0
    static int ParseSymbol(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2)
        {
            string arg0 = LuaScriptMgr.GetLuaString(L, 1);
            int    arg1 = (int)LuaScriptMgr.GetNetObject(L, 2, typeof(int));
            bool   o    = NGUIText.ParseSymbol(arg0, ref arg1);
            LuaScriptMgr.Push(L, o);
            LuaScriptMgr.Push(L, arg1);
            return(2);
        }
        else if (count == 10)
        {
            string             arg0 = LuaScriptMgr.GetLuaString(L, 1);
            int                arg1 = (int)LuaScriptMgr.GetNetObject(L, 2, typeof(int));
            BetterList <Color> arg2 = (BetterList <Color>)LuaScriptMgr.GetNetObject(L, 3, typeof(BetterList <Color>));
            bool               arg3 = LuaScriptMgr.GetBoolean(L, 4);
            int                arg4 = (int)LuaScriptMgr.GetNetObject(L, 5, typeof(int));
            bool               arg5 = (bool)LuaScriptMgr.GetNetObject(L, 6, typeof(bool));
            bool               arg6 = (bool)LuaScriptMgr.GetNetObject(L, 7, typeof(bool));
            bool               arg7 = (bool)LuaScriptMgr.GetNetObject(L, 8, typeof(bool));
            bool               arg8 = (bool)LuaScriptMgr.GetNetObject(L, 9, typeof(bool));
            bool               arg9 = (bool)LuaScriptMgr.GetNetObject(L, 10, typeof(bool));
            bool               o    = NGUIText.ParseSymbol(arg0, ref arg1, arg2, arg3, ref arg4, ref arg5, ref arg6, ref arg7, ref arg8, ref arg9);
            LuaScriptMgr.Push(L, o);
            LuaScriptMgr.Push(L, arg1);
            LuaScriptMgr.Push(L, arg4);
            LuaScriptMgr.Push(L, arg5);
            LuaScriptMgr.Push(L, arg6);
            LuaScriptMgr.Push(L, arg7);
            LuaScriptMgr.Push(L, arg8);
            LuaScriptMgr.Push(L, arg9);
            return(8);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: NGUIText.ParseSymbol");
        }

        return(0);
    }
예제 #10
0
 private void Update()
 {
     if (this.mReset)
     {
         this.mOffset = 0;
         this.mReset  = false;
         this.mLabel  = base.GetComponent <UILabel>();
         this.mText   = this.mLabel.processedText;
     }
     if (this.mOffset < this.mText.Length && this.mNextChar <= RealTime.time)
     {
         this.charsPerSecond = Mathf.Max(1, this.charsPerSecond);
         float num = 1f / (float)this.charsPerSecond;
         char  c   = this.mText[this.mOffset];
         if (c == '.' || c == '\n' || c == '!' || c == '?')
         {
             num *= 4f;
         }
         NGUIText.ParseSymbol(this.mText, ref this.mOffset);
         this.mNextChar   = RealTime.time + num;
         this.mLabel.text = this.mText.Substring(0, ++this.mOffset);
     }
 }
예제 #11
0
    private void Update()
    {
        if (!mActive)
        {
            return;
        }
        if (mReset)
        {
            mCurrentOffset = 0;
            mReset         = false;
            mLabel         = GetComponent <UILabel>();
            mFullText      = mLabel.processedText;
            mFade.Clear();
            if (keepFullDimensions && scrollView != null)
            {
                scrollView.UpdatePosition();
            }
        }
        while (mCurrentOffset < mFullText.Length && mNextChar <= RealTime.time)
        {
            int num = mCurrentOffset;
            charsPerSecond = Mathf.Max(1, charsPerSecond);
            while (NGUIText.ParseSymbol(mFullText, ref mCurrentOffset))
            {
            }
            mCurrentOffset++;
            if (mCurrentOffset > mFullText.Length)
            {
                break;
            }
            float num2 = 1f / (float)charsPerSecond;
            char  c    = (num >= mFullText.Length) ? '\n' : mFullText[num];
            if (c == '\n')
            {
                num2 += delayOnNewLine;
            }
            else if (num + 1 == mFullText.Length || mFullText[num + 1] <= ' ')
            {
                switch (c)
                {
                case '.':
                    if (num + 2 < mFullText.Length && mFullText[num + 1] == '.' && mFullText[num + 2] == '.')
                    {
                        num2 += delayOnPeriod * 3f;
                        num  += 2;
                    }
                    else
                    {
                        num2 += delayOnPeriod;
                    }
                    break;

                case '!':
                case '?':
                    num2 += delayOnPeriod;
                    break;
                }
            }
            if (mNextChar == 0f)
            {
                mNextChar = RealTime.time + num2;
            }
            else
            {
                mNextChar += num2;
            }
            if (fadeInTime != 0f)
            {
                FadeEntry item = default(FadeEntry);
                item.index = num;
                item.alpha = 0f;
                item.text  = mFullText.Substring(num, mCurrentOffset - num);
                mFade.Add(item);
            }
            else
            {
                mLabel.text = ((!keepFullDimensions) ? mFullText.Substring(0, mCurrentOffset) : (mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset)));
                if (!keepFullDimensions && scrollView != null)
                {
                    scrollView.UpdatePosition();
                }
            }
        }
        if (mFade.size != 0)
        {
            int num3 = 0;
            while (num3 < mFade.size)
            {
                FadeEntry value = mFade[num3];
                value.alpha += RealTime.deltaTime / fadeInTime;
                if (value.alpha < 1f)
                {
                    mFade[num3] = value;
                    num3++;
                }
                else
                {
                    mFade.RemoveAt(num3);
                }
            }
            if (mFade.size == 0)
            {
                if (keepFullDimensions)
                {
                    mLabel.text = mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset);
                }
                else
                {
                    mLabel.text = mFullText.Substring(0, mCurrentOffset);
                }
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < mFade.size; i++)
            {
                FadeEntry fadeEntry = mFade[i];
                if (i == 0)
                {
                    stringBuilder.Append(mFullText.Substring(0, fadeEntry.index));
                }
                stringBuilder.Append('[');
                stringBuilder.Append(NGUIText.EncodeAlpha(fadeEntry.alpha));
                stringBuilder.Append(']');
                stringBuilder.Append(fadeEntry.text);
            }
            if (keepFullDimensions)
            {
                stringBuilder.Append("[00]");
                stringBuilder.Append(mFullText.Substring(mCurrentOffset));
            }
            mLabel.text = stringBuilder.ToString();
        }
        else if (mCurrentOffset == mFullText.Length)
        {
            current = this;
            EventDelegate.Execute(onFinished);
            current = null;
            mActive = false;
        }
    }
예제 #12
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, verts, uvs, cols);
        }
        else if (!string.IsNullOrEmpty(text))
        {
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

#if DYNAMIC_FONT
            if (isDynamic)
            {
                // NOTE: This shouldn't be used anymore. All dynamic font printing goes directly through NGUIText instead.
                NGUIText.current.size  = mDynamicFontSize;
                NGUIText.current.style = mDynamicFontStyle;
                NGUIText.Print(dynamicFont, text, verts, uvs, cols);
                return;
            }
#endif
            mColors.Add(Color.white);

            int     fs = NGUIText.current.size;
            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (fs + NGUIText.current.spacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
            Color   gb = NGUIText.current.tint * NGUIText.current.gradientBottom;
            Color   gt = NGUIText.current.tint * NGUIText.current.gradientTop;
            Color32 uc = NGUIText.current.tint;

            float invX = uvRect.width / mFont.texWidth;
            float invY = mUVRect.height / mFont.texHeight;

            int  textLength = text.Length;
            bool useSymbols = NGUIText.current.encoding && NGUIText.current.symbolStyle != NGUIText.SymbolStyle.None && hasSymbols && sprite != null;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (NGUIText.current.alignment != TextAlignment.Left)
                    {
                        NGUIText.Align(verts, indexOffset, x - NGUIText.current.spacingX);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                bool isMineColor = false;

                if (NGUIText.current.encoding && NGUIText.ParseSymbol(text, ref i, mColors, NGUIText.current.premultiply, ref isMineColor))
                {
                    Color fc = mColors[mColors.size - 1];

                    if (isMineColor)
                    {
                        fc *= NGUIText.current.tint;
                    }

                    // *******************
                    // add sj.
                    // *******************
                    fc.a = uc.a / 255.0f;
                    // *******************
                    uc = fc;

                    if (NGUIText.current.gradient)
                    {
                        gb = NGUIText.current.gradientBottom * fc;
                        gt = NGUIText.current.gradientTop * fc;
                    }
                    --i;
                    continue;
                }

                // See if there is a symbol matching this text
                BMSymbol symbol = useSymbols ? MatchSymbol(text, i, textLength) : null;

                if (symbol == null)
                {
                    BMGlyph glyph = mFont.GetGlyph(c);
                    if (glyph == null)
                    {
                        continue;
                    }

                    if (prev != 0)
                    {
                        x += glyph.GetKerning(prev);
                    }

                    if (c == ' ')
                    {
                        x   += NGUIText.current.spacingX + glyph.advance;
                        prev = c;
                        continue;
                    }

                    v0.x = (x + glyph.offsetX);
                    v0.y = -(y + glyph.offsetY);

                    v1.x = v0.x + glyph.width;
                    v1.y = v0.y - glyph.height;

                    u0.x = mUVRect.xMin + invX * glyph.x;
                    u0.y = mUVRect.yMax - invY * glyph.y;

                    u1.x = u0.x + invX * glyph.width;
                    u1.y = u0.y - invY * glyph.height;

                    x   += NGUIText.current.spacingX + glyph.advance;
                    prev = c;

                    if (NGUIText.current.gradient)
                    {
                        float min = NGUIText.current.size - glyph.offsetY;
                        float max = min - glyph.height;

                        min /= NGUIText.current.size;
                        max /= NGUIText.current.size;

                        s_c0 = Color.Lerp(gb, gt, min);
                        s_c1 = Color.Lerp(gb, gt, max);

                        cols.Add(s_c0);
                        cols.Add(s_c1);
                        cols.Add(s_c1);
                        cols.Add(s_c0);
                    }
                    else
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(uc);
                        }
                    }
                }
                else
                {
                    v0.x = (x + symbol.offsetX);
                    v0.y = -(y + symbol.offsetY);

                    v1.x = v0.x + symbol.width;
                    v1.y = v0.y - symbol.height;

                    Rect uv = symbol.uvRect;

                    u0.x = uv.xMin;
                    u0.y = uv.yMax;
                    u1.x = uv.xMax;
                    u1.y = uv.yMin;

                    x   += NGUIText.current.spacingX + symbol.advance;
                    i   += symbol.length - 1;
                    prev = 0;

                    if (NGUIText.current.symbolStyle == NGUIText.SymbolStyle.Colored)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(uc);
                        }
                    }
                    else
                    {
                        Color32 col = Color.white;
                        col.a = uc.a;
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }

                verts.Add(new Vector3(v1.x, v0.y));
                verts.Add(new Vector3(v1.x, v1.y));
                verts.Add(new Vector3(v0.x, v1.y));
                verts.Add(new Vector3(v0.x, v0.y));

                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u1.x, u1.y));
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u0.x, u0.y));
            }

            if (NGUIText.current.alignment != TextAlignment.Left && indexOffset < verts.size)
            {
                NGUIText.Align(verts, indexOffset, x - NGUIText.current.spacingX);
                indexOffset = verts.size;
            }
            mColors.Clear();
        }
    }
예제 #13
0
    void Update()
    {
        if (!mActive)
        {
            return;
        }

        if (mReset)
        {
            mCurrentOffset = 0;
            mReset         = false;
            mLabel         = GetComponent <Text>();
            mFullText      = mLabel.text;
            mFade.Clear();
        }

        while (mCurrentOffset < mFullText.Length && mNextChar <= RealTime.time)
        {
            int lastOffset = mCurrentOffset;
            charsPerSecond = Mathf.Max(1, charsPerSecond);

            while (NGUIText.ParseSymbol(mFullText, ref mCurrentOffset))
            {
            }
            ++mCurrentOffset;

            if (mCurrentOffset > mFullText.Length)
            {
                break;
            }

            float delay = 1f / charsPerSecond;
            char  c     = (lastOffset < mFullText.Length) ? mFullText[lastOffset] : '\n';

            if (c == '\n')
            {
                delay += delayOnNewLine;
            }
            else if (lastOffset + 1 == mFullText.Length || mFullText[lastOffset + 1] <= ' ')
            {
                if (c == '.')
                {
                    if (lastOffset + 2 < mFullText.Length && mFullText[lastOffset + 1] == '.' && mFullText[lastOffset + 2] == '.')
                    {
                        delay      += delayOnPeriod * 3f;
                        lastOffset += 2;
                    }
                    else
                    {
                        delay += delayOnPeriod;
                    }
                }
                else if (c == '!' || c == '?')
                {
                    delay += delayOnPeriod;
                }
            }

            if (mNextChar == 0f)
            {
                mNextChar = RealTime.time + delay;
            }
            else
            {
                mNextChar += delay;
            }

            if (fadeInTime != 0f)
            {
                fadeData tempFade = new fadeData();
                tempFade.index = lastOffset;
                tempFade.alpha = 0f;
                tempFade.text  = mFullText.Substring(lastOffset, mCurrentOffset - lastOffset);
                mFade.Add(tempFade);
            }
            else
            {
                mLabel.text = keepFullDimensions ?
                              mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset) :
                              mFullText.Substring(0, mCurrentOffset);
            }
        }

        if (mFade.size != 0)
        {
            for (int i = 0; i < mFade.size;)
            {
                fadeData tempFade = mFade[i];
                tempFade.alpha += RealTime.deltaTime / fadeInTime;

                if (tempFade.alpha < 1f)
                {
                    mFade[i] = tempFade;
                    ++i;
                }
                else
                {
                    mFade.RemoveAt(i);
                }
            }

            if (mFade.size == 0)
            {
                if (keepFullDimensions)
                {
                    mLabel.text = mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset);
                }
                else
                {
                    mLabel.text = mFullText.Substring(0, mCurrentOffset);
                }
            }
            else
            {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < mFade.size; ++i)
                {
                    fadeData tempFade = mFade[i];

                    if (i == 0)
                    {
                        sb.Append(mFullText.Substring(0, tempFade.index));
                    }

                    sb.Append('[');
                    sb.Append(NGUIText.EncodeAlpha(tempFade.alpha));
                    sb.Append(']');
                    sb.Append(tempFade.text);
                }

                if (keepFullDimensions)
                {
                    sb.Append("[00]");
                    sb.Append(mFullText.Substring(mCurrentOffset));
                }

                mLabel.text = sb.ToString();
            }
        }
        else if (mCurrentOffset == mFullText.Length)
        {
            Instance = this;
            EventDelegate.Execute(onFinished);
            Instance = null;
            mActive  = false;
        }
    }
예제 #14
0
 private void Update()
 {
     if (this.mLabel == null)
     {
         this.mLabel            = base.GetComponent <UILabel>();
         this.index             = 0;
         this.maxCount          = 1;
         this.wait              = false;
         this.mText             = new string[1];
         this.mText[this.index] = this.mLabel.processedText;
     }
     if (this.mOffset < this.mText[this.index].Length)
     {
         if (this.mNextChar <= RealTime.time)
         {
             this.charsPerSecond = Mathf.Max(1, this.charsPerSecond);
             float num = 1f / (float)this.charsPerSecond;
             char  c   = this.mText[this.index][this.mOffset];
             if (c == '.' || c == '\n' || c == '!' || c == '?')
             {
                 num *= 4f;
             }
             NGUIText.ParseSymbol(this.mText[this.index], ref this.mOffset);
             this.mNextChar   = RealTime.time + num;
             this.mLabel.text = this.mText[this.index].Substring(0, ++this.mOffset);
         }
     }
     else if (!this.wait)
     {
         this.index++;
         if (this.index >= this.maxCount)
         {
             if (this.WriteComplete != null)
             {
                 this.WriteComplete();
             }
             UnityEngine.Object.Destroy(this);
         }
         else
         {
             this.mOffset = 0;
         }
     }
     if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
     {
         if (this.mOffset < this.mText[this.index].Length)
         {
             this.mLabel.text = this.mText[this.index];
             this.mOffset     = this.mText[this.index].Length;
         }
         else
         {
             this.index++;
             if (this.index >= this.maxCount)
             {
                 if (this.WriteComplete != null)
                 {
                     this.WriteComplete();
                 }
                 UnityEngine.Object.Destroy(this);
             }
             else
             {
                 this.mOffset = 0;
             }
         }
     }
 }
예제 #15
0
    static public Vector3 GetExactCharacterRowList(string text, List <int> rowList, int picIndex)
    {
        Vector3 result = new Vector3(0, 0, 0);

        if (string.IsNullOrEmpty(text))
        {
            text = " ";
        }

        NGUIText.Prepare(text);

        float fullSize = NGUIText.fontSize * NGUIText.fontScale;
        float x = 0f, y = 0f, maxX = 0f;
        float lastY = y + 1.76f;

        int lastIndex = -1;
        int textLength = text.Length, ch = 0, prev = 0;

        for (int i = 0; i < textLength; ++i)
        {
            ch = text[i];
            if (ch == '\n')
            {
                if (x > maxX)
                {
                    maxX = x;
                }

                x    = 0;
                y   += NGUIText.finalLineHeight;
                prev = 0;
                continue;
            }
            else if (ch < ' ')
            {
                prev = 0;
                continue;
            }

            if (NGUIText.encoding && NGUIText.ParseSymbol(text, ref i))
            {
                --i;
                continue;
            }

            // See if there is a symbol matching this text
            BMSymbol symbol = NGUIText.useSymbols ? NGUIText.GetSymbol(text, i, textLength) : null;

            if (symbol == null)
            {
                float gw = NGUIText.GetGlyphWidth(ch, prev);

                if (gw != 0f)
                {
                    float w = gw + NGUIText.finalSpacingX;

                    if (Mathf.RoundToInt(x + w) > NGUIText.regionWidth)
                    {
                        if (x == 0f)
                        {
                            return(result);
                        }

                        x    = 0f;
                        y   += NGUIText.finalLineHeight;
                        prev = 0;
                        --i;
                        continue;
                    }
                    if (lastY != y)
                    {
                        rowList.Add(lastIndex + 1);
                    }
                    if (i == picIndex)
                    {
                        result = new Vector3(x, -y);
                    }
                    prev = ch;
                    x   += w;
                }
            }
            else
            {
                float w = symbol.advance * NGUIText.fontScale + NGUIText.finalSpacingX;

                if (Mathf.RoundToInt(x + w) > NGUIText.regionWidth)
                {
                    if (x == 0f)
                    {
                        return(result);
                    }

                    x    = 0f;
                    y   += NGUIText.finalLineHeight;
                    prev = 0;
                    --i;
                    continue;
                }

                if (lastY != y)
                {
                    rowList.Add(lastIndex + 1);
                }
                if (i == picIndex)
                {
                    result = new Vector3(x, -y);
                }
                i   += symbol.sequence.Length - 1;
                x   += w;
                prev = 0;
            }
            lastY     = y;
            lastIndex = i;
        }

        return(result);
    }
예제 #16
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, verts, uvs, cols);
        }
        else if (!string.IsNullOrEmpty(text))
        {
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

#if DYNAMIC_FONT
            if (isDynamic)
            {
                // NOTE: This shouldn't be used anymore. All dynamic font printing goes directly through NGUIText instead.
                NGUIText.current.size  = mDynamicFontSize;
                NGUIText.current.style = mDynamicFontStyle;
                NGUIText.Print(dynamicFont, text, verts, uvs, cols);
                return;
            }
#endif
            mColors.Add(Color.white);

            int     fs = NGUIText.current.size;
            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (fs + NGUIText.current.spacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
            Color   gb = NGUIText.current.tint * NGUIText.current.gradientBottom;
            Color   gt = NGUIText.current.tint * NGUIText.current.gradientTop;
            Color32 uc = NGUIText.current.tint;

            float invX = uvRect.width / mFont.texWidth;
            float invY = mUVRect.height / mFont.texHeight;

            int  textLength = text.Length;
            bool useSymbols = NGUIText.current.encoding && NGUIText.current.symbolStyle != NGUIText.SymbolStyle.None && hasSymbols && sprite != null;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (NGUIText.current.alignment != TextAlignment.Left)
                    {
                        NGUIText.Align(verts, indexOffset, x - NGUIText.current.spacingX);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                if (NGUIText.current.encoding && NGUIText.ParseSymbol(text, ref i, mColors, NGUIText.current.premultiply))
                {
                    Color fc = NGUIText.current.tint * mColors[mColors.size - 1];
                    uc = fc;

                    if (NGUIText.current.gradient)
                    {
                        gb = NGUIText.current.gradientBottom * fc;
                        gt = NGUIText.current.gradientTop * fc;
                    }
                    --i;
                    continue;
                }

                // See if there is a symbol matching this text
                BMSymbol symbol = useSymbols ? MatchSymbol(text, i, textLength) : null;

                if (symbol == null)
                {
                    BMGlyph glyph = mFont.GetGlyph(c);
                    if (glyph == null)
                    {
                        continue;
                    }

                    if (prev != 0)
                    {
                        x += glyph.GetKerning(prev);
                    }

                    if (c == ' ')
                    {
                        x   += NGUIText.current.spacingX + glyph.advance;
                        prev = c;
                        continue;
                    }

                    v0.x = (x + glyph.offsetX);
                    v0.y = -(y + glyph.offsetY);

                    v1.x = v0.x + glyph.width;
                    v1.y = v0.y - glyph.height;

                    u0.x = mUVRect.xMin + invX * glyph.x;
                    u0.y = mUVRect.yMax - invY * glyph.y;

                    u1.x = u0.x + invX * glyph.width;
                    u1.y = u0.y - invY * glyph.height;

                    x   += NGUIText.current.spacingX + glyph.advance;
                    prev = c;

                    if (glyph.channel == 0 || glyph.channel == 15)
                    {
                        if (NGUIText.current.gradient)
                        {
                            float min = NGUIText.current.size - glyph.offsetY;
                            float max = min - glyph.height;

                            min /= NGUIText.current.size;
                            max /= NGUIText.current.size;

                            s_c0 = Color.Lerp(gb, gt, min);
                            s_c1 = Color.Lerp(gb, gt, max);

                            cols.Add(s_c0);
                            cols.Add(s_c1);
                            cols.Add(s_c1);
                            cols.Add(s_c0);
                        }
                        else
                        {
                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(uc);
                            }
                        }
                    }
                    else
                    {
                        // Packed fonts come as alpha masks in each of the RGBA channels.
                        // In order to use it we need to use a special shader.
                        //
                        // Limitations:
                        // - Effects (drop shadow, outline) will not work.
                        // - Should not be a part of the atlas (eastern fonts rarely are anyway).
                        // - Lower color precision

                        Color col = uc;

                        col *= 0.49f;

                        switch (glyph.channel)
                        {
                        case 1: col.b += 0.51f; break;

                        case 2: col.g += 0.51f; break;

                        case 4: col.r += 0.51f; break;

                        case 8: col.a += 0.51f; break;
                        }

                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }
                else
                {
                    v0.x = (x + symbol.offsetX);
                    v0.y = -(y + symbol.offsetY);

                    v1.x = v0.x + symbol.width;
                    v1.y = v0.y - symbol.height;

                    Rect uv = symbol.uvRect;

                    u0.x = uv.xMin;
                    u0.y = uv.yMax;
                    u1.x = uv.xMax;
                    u1.y = uv.yMin;

                    x   += NGUIText.current.spacingX + symbol.advance;
                    i   += symbol.length - 1;
                    prev = 0;

                    if (NGUIText.current.symbolStyle == NGUIText.SymbolStyle.Colored)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(uc);
                        }
                    }
                    else
                    {
                        Color32 col = Color.white;
                        col.a = uc.a;
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }

                verts.Add(new Vector3(v1.x, v0.y));
                verts.Add(new Vector3(v1.x, v1.y));
                verts.Add(new Vector3(v0.x, v1.y));
                verts.Add(new Vector3(v0.x, v0.y));

                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u1.x, u1.y));
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u0.x, u0.y));
            }

            if (NGUIText.current.alignment != TextAlignment.Left && indexOffset < verts.size)
            {
                NGUIText.Align(verts, indexOffset, x - NGUIText.current.spacingX);
                indexOffset = verts.size;
            }
            mColors.Clear();
        }
    }
예제 #17
0
    static public bool WrapText(string text, out string finalText, bool keepCharCount, bool wrapLineColors, bool eastern)
    {
        if (NGUIText.regionWidth < 1 || NGUIText.regionHeight < 1 || NGUIText.finalLineHeight < 1f)
        {
            finalText = "";
            return(false);
        }

        float height       = (NGUIText.maxLines > 0) ? Mathf.Min(NGUIText.regionHeight, NGUIText.finalLineHeight * NGUIText.maxLines) : NGUIText.regionHeight;
        int   maxLineCount = (NGUIText.maxLines > 0) ? NGUIText.maxLines : 1000000;

        maxLineCount = Mathf.FloorToInt(Mathf.Min(maxLineCount, height / NGUIText.finalLineHeight) + 0.01f);

        if (maxLineCount == 0)
        {
            finalText = "";
            return(false);
        }

        if (string.IsNullOrEmpty(text))
        {
            text = " ";
        }
        NGUIText.Prepare(text);

        StringBuilder sb = new StringBuilder();
        int           textLength = text.Length;
        float         remainingWidth = NGUIText.regionWidth;
        int           start = 0, offset = 0, lineCount = 1, prev = 0;
        bool          lineIsEmpty = true;
        bool          fits        = true;

        Color c             = NGUIText.tint;
        int   subscriptMode = 0;        // 0 = normal, 1 = subscript, 2 = superscript
        bool  bold          = false;
        bool  italic        = false;
        bool  underline     = false;
        bool  strikethrough = false;
        bool  ignoreColor   = false;

        if (!NGUIText.useSymbols)
        {
            wrapLineColors = false;
        }
        if (wrapLineColors)
        {
            NGUIText.mColors.Add(c);
        }

        // Run through all characters
        for (; offset < textLength; ++offset)
        {
            char ch = text[offset];

            // New line character -- start a new line
            if (ch == '\n')
            {
                if (lineCount == maxLineCount)
                {
                    break;
                }
                remainingWidth = NGUIText.regionWidth;

                // Add the previous word to the final string
                if (start < offset)
                {
                    sb.Append(text.Substring(start, offset - start + 1));
                }
                else
                {
                    sb.Append(ch);
                }

                if (wrapLineColors)
                {
                    for (int i = 0; i < NGUIText.mColors.size; ++i)
                    {
                        sb.Insert(sb.Length - 1, "[-]");
                    }

                    for (int i = 0; i < NGUIText.mColors.size; ++i)
                    {
                        sb.Append("[");
                        sb.Append(NGUIText.EncodeColor(NGUIText.mColors[i]));
                        sb.Append("]");
                    }
                }

                lineIsEmpty = true;
                ++lineCount;
                start = offset + 1;
                prev  = 0;
                continue;
            }
            // When encoded symbols such as [RrGgBb] or [-] are encountered, skip past them
            if (NGUIText.encoding)
            {
                if (!wrapLineColors)
                {
                    if (NGUIText.ParseSymbol(text, ref offset))
                    {
                        --offset;
                        continue;
                    }
                }
                else if (NGUIText.ParseSymbol(text, ref offset, NGUIText.mColors, NGUIText.premultiply, ref subscriptMode, ref bold,
                                              ref italic, ref underline, ref strikethrough, ref ignoreColor))
                {
                    if (ignoreColor)
                    {
                        c    = NGUIText.mColors[NGUIText.mColors.size - 1];
                        c.a *= NGUIText.mAlpha * NGUIText.tint.a;
                    }
                    else
                    {
                        c    = NGUIText.tint * NGUIText.mColors[NGUIText.mColors.size - 1];
                        c.a *= NGUIText.mAlpha;
                    }

                    for (int b = 0, bmax = NGUIText.mColors.size - 2; b < bmax; ++b)
                    {
                        c.a *= NGUIText.mColors[b].a;
                    }

                    --offset;
                    continue;
                }
            }

            // See if there is a symbol matching this text
            BMSymbol symbol = NGUIText.useSymbols ? NGUIText.GetSymbol(text, offset, textLength) : null;

            // Calculate how wide this symbol or character is going to be
            float glyphWidth;

            if (symbol == null)
            {
                // Find the glyph for this character
                float w = NGUIText.GetGlyphWidth(ch, prev);
                if (w == 0f)
                {
                    continue;
                }
                glyphWidth = NGUIText.finalSpacingX + w;
            }
            else
            {
                glyphWidth = NGUIText.finalSpacingX + symbol.advance * NGUIText.fontScale;
            }

            // Reduce the width
            remainingWidth -= glyphWidth;

            // If this marks the end of a word, add it to the final string.
            if (NGUIText.IsSpace(ch) && !eastern && start < offset)
            {
                int end = offset - start + 1;

                // Last word on the last line should not include an invisible character
                if (lineCount == maxLineCount && remainingWidth <= 0f && offset < textLength)
                {
                    char cho = text[offset];
                    if (cho < ' ' || NGUIText.IsSpace(cho))
                    {
                        --end;
                    }
                }

                sb.Append(text.Substring(start, end));
                lineIsEmpty = false;
                start       = offset + 1;
                prev        = ch;
            }

            // Doesn't fit?
            if (Mathf.RoundToInt(remainingWidth) < 0)
            {
                // Can't start a new line
                if (lineIsEmpty || lineCount == maxLineCount)
                {
                    // This is the first word on the line -- add it up to the character that fits
                    sb.Append(text.Substring(start, Mathf.Max(0, offset - start)));
                    bool space = NGUIText.IsSpace(ch);
                    if (!space && !eastern)
                    {
                        fits = false;
                    }

                    if (wrapLineColors && NGUIText.mColors.size > 0)
                    {
                        sb.Append("[-]");
                    }

                    if (lineCount++ == maxLineCount)
                    {
                        start = offset;
                        break;
                    }

                    if (keepCharCount)
                    {
                        NGUIText.ReplaceSpaceWithNewline(ref sb);
                    }
                    else
                    {
                        NGUIText.EndLine(ref sb);
                    }

                    if (wrapLineColors)
                    {
                        for (int i = 0; i < NGUIText.mColors.size; ++i)
                        {
                            sb.Insert(sb.Length - 1, "[-]");
                        }

                        for (int i = 0; i < NGUIText.mColors.size; ++i)
                        {
                            sb.Append("[");
                            sb.Append(NGUIText.EncodeColor(NGUIText.mColors[i]));
                            sb.Append("]");
                        }
                    }

                    // Start a brand-new line
                    lineIsEmpty = true;

                    start          = offset;
                    remainingWidth = NGUIText.regionWidth - glyphWidth;

                    prev = 0;
                }
                else
                {
                    // Revert the position to the beginning of the word and reset the line
                    lineIsEmpty    = true;
                    remainingWidth = NGUIText.regionWidth;
                    offset         = start - 1;
                    prev           = 0;

                    if (lineCount++ == maxLineCount)
                    {
                        break;
                    }
                    if (keepCharCount)
                    {
                        NGUIText.ReplaceSpaceWithNewline(ref sb);
                    }
                    else
                    {
                        NGUIText.EndLine(ref sb);
                    }

                    if (wrapLineColors)
                    {
                        for (int i = 0; i < NGUIText.mColors.size; ++i)
                        {
                            sb.Insert(sb.Length - 1, "[-]");
                        }

                        for (int i = 0; i < NGUIText.mColors.size; ++i)
                        {
                            sb.Append("[");
                            sb.Append(NGUIText.EncodeColor(NGUIText.mColors[i]));
                            sb.Append("]");
                        }
                    }
                    continue;
                }
            }
            else
            {
                prev = ch;
            }

            // Advance the offset past the symbol
            if (symbol != null)
            {
                offset += symbol.length - 1;
                prev    = 0;
            }
        }

        if (start < offset)
        {
            sb.Append(text.Substring(start, offset - start));
        }
        if (wrapLineColors && NGUIText.mColors.size > 0)
        {
            sb.Append("[-]");
        }
        finalText = sb.ToString();
        NGUIText.mColors.Clear();
        return(fits && ((offset == textLength) || (lineCount <= Mathf.Min(NGUIText.maxLines, maxLineCount))));
    }
예제 #18
0
 private void Update()
 {
     if (!this.mActive)
     {
         return;
     }
     if (this.mReset)
     {
         this.mCurrentOffset = 0;
         this.ff9Signal      = 0;
         this.mReset         = false;
         this.mLabel         = base.GetComponent <UILabel>();
         this.mFullText      = this.mLabel.processedText;
         this.mFade.Clear();
         if (this.keepFullDimensions && this.scrollView != (UnityEngine.Object)null)
         {
             this.scrollView.UpdatePosition();
         }
     }
     if (String.IsNullOrEmpty(this.mFullText))
     {
         return;
     }
     while (this.mCurrentOffset < this.mFullText.Length && this.mNextChar <= RealTime.time)
     {
         Int32 num = this.mCurrentOffset;
         this.charsPerSecond = (Int32)((!this.mDynamicCharsPerSecond.ContainsKey(this.mCurrentOffset)) ? Mathf.Max(1, this.charsPerSecond) : this.mDynamicCharsPerSecond[this.mCurrentOffset]);
         if (this.mWaitList.ContainsKey(this.mCurrentOffset))
         {
             if (this.mWaitList[this.mCurrentOffset] > 0f)
             {
                 Dictionary <Int32, Single> dictionary2;
                 Dictionary <Int32, Single> dictionary = dictionary2 = this.mWaitList;
                 Int32  key2;
                 Int32  key  = key2 = this.mCurrentOffset;
                 Single num2 = dictionary2[key2];
                 dictionary[key] = num2 - ((!HonoBehaviorSystem.Instance.IsFastForwardModeActive()) ? Time.deltaTime : (Time.deltaTime * (Single)FF9StateSystem.Settings.FastForwardFactor));
                 break;
             }
             this.mNextChar = RealTime.time;
         }
         Dialog.DialogImage dialogImage = (Dialog.DialogImage)null;
         if (this.mLabel.supportEncoding)
         {
             while (NGUIText.ParseSymbol(this.mFullText, ref this.mCurrentOffset, ref this.ff9Signal, ref dialogImage))
             {
             }
         }
         if (this.onCharacterFinished != null && dialogImage != null)
         {
             this.onCharacterFinished(base.gameObject, dialogImage.TextPosition);
         }
         this.mCurrentOffset++;
         if (this.mCurrentOffset > this.mFullText.Length)
         {
             break;
         }
         Single num3 = (!HonoBehaviorSystem.Instance.IsFastForwardModeActive()) ? (1f / (Single)this.charsPerSecond) : (1f / (Single)(this.charsPerSecond * FF9StateSystem.Settings.FastForwardFactor));
         Char   c    = (Char)((num >= this.mFullText.Length) ? '\n' : this.mFullText[num]);
         if (c == '\n')
         {
             num3 += this.delayOnNewLine;
         }
         else if (num + 1 == this.mFullText.Length || this.mFullText[num + 1] <= ' ')
         {
             if (c == '.')
             {
                 if (num + 2 < this.mFullText.Length && this.mFullText[num + 1] == '.' && this.mFullText[num + 2] == '.')
                 {
                     num3 += this.delayOnPeriod * 3f;
                     num  += 2;
                 }
                 else
                 {
                     num3 += this.delayOnPeriod;
                 }
             }
             else if (c == '!' || c == '?')
             {
                 num3 += this.delayOnPeriod;
             }
         }
         if (this.mNextChar == 0f)
         {
             this.mNextChar = RealTime.time + num3;
         }
         else
         {
             this.mNextChar += num3;
         }
         if (this.fadeInTime != 0f)
         {
             TypewriterEffect.FadeEntry item = default(TypewriterEffect.FadeEntry);
             item.index = num;
             item.alpha = 0f;
             item.text  = this.mFullText.Substring(num, this.mCurrentOffset - num);
             this.mFade.Add(item);
         }
         else
         {
             this.mLabel.text = ((!this.keepFullDimensions) ? this.mFullText.Substring(0, this.mCurrentOffset) : (this.mFullText.Substring(0, this.mCurrentOffset) + "[00]" + this.mFullText.Substring(this.mCurrentOffset)));
             if (!this.keepFullDimensions && this.scrollView != (UnityEngine.Object)null)
             {
                 this.scrollView.UpdatePosition();
             }
         }
     }
     if (this.mCurrentOffset >= this.mFullText.Length)
     {
         this.mLabel.text = this.mFullText;
     }
     else if (this.mFade.size != 0)
     {
         Int32 i = 0;
         while (i < this.mFade.size)
         {
             TypewriterEffect.FadeEntry value = this.mFade[i];
             value.alpha += RealTime.deltaTime / this.fadeInTime;
             if (value.alpha < 1f)
             {
                 this.mFade[i] = value;
                 i++;
             }
             else
             {
                 this.mFade.RemoveAt(i);
             }
         }
         if (this.mFade.size == 0)
         {
             if (this.keepFullDimensions)
             {
                 this.mLabel.text = this.mFullText.Substring(0, this.mCurrentOffset) + "[00]" + this.mFullText.Substring(this.mCurrentOffset);
             }
             else
             {
                 this.mLabel.text = this.mFullText.Substring(0, this.mCurrentOffset);
             }
         }
         else
         {
             StringBuilder stringBuilder = new StringBuilder();
             for (Int32 j = 0; j < this.mFade.size; j++)
             {
                 TypewriterEffect.FadeEntry fadeEntry = this.mFade[j];
                 if (j == 0)
                 {
                     stringBuilder.Append(this.mFullText.Substring(0, fadeEntry.index));
                 }
                 stringBuilder.Append('[');
                 stringBuilder.Append(NGUIText.EncodeAlpha(fadeEntry.alpha));
                 stringBuilder.Append(']');
                 stringBuilder.Append(fadeEntry.text);
             }
             if (this.keepFullDimensions)
             {
                 stringBuilder.Append("[00]");
                 stringBuilder.Append(this.mFullText.Substring(this.mCurrentOffset));
             }
             this.mLabel.text = stringBuilder.ToString();
         }
     }
     if (this.mCurrentOffset >= this.mFullText.Length)
     {
         TypewriterEffect.current = this;
         EventDelegate.Execute(this.onFinished);
         TypewriterEffect.current = (TypewriterEffect)null;
         this.mActive             = false;
     }
 }
예제 #19
0
    void Update()
    {
        if (mLabel == null)
        {
            mLabel       = GetComponent <UILabel>();
            index        = 0;
            maxCount     = 1;
            this.wait    = false;
            mText        = new string[1];
            mText[index] = mLabel.processedText;
        }

        if (mOffset < mText[index].Length)
        {
            if (mNextChar <= RealTime.time)
            {
                charsPerSecond = Mathf.Max(1, charsPerSecond);

                // Periods and end-of-line characters should pause for a longer time.
                float delay = 1f / charsPerSecond;
                char  c     = mText[index][mOffset];
                if (c == '.' || c == '\n' || c == '!' || c == '?')
                {
                    delay *= 4f;
                }

                // Automatically skip all symbols
                NGUIText.ParseSymbol(mText[index], ref mOffset);

                mNextChar   = RealTime.time + delay;
                mLabel.text = mText[index].Substring(0, ++mOffset);
            }
        }
        else
        {
            if (!wait)
            {
                index++;
                if (index >= maxCount)
                {
                    if (WriteComplete != null)
                    {
                        WriteComplete();
                    }
                    Destroy(this);
                }
                else
                {
                    mOffset = 0;
                }
            }
        }

        if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
        {
            if (mOffset < mText[index].Length)
            {
                mLabel.text = mText[index];
                mOffset     = mText[index].Length;
            }
            else
            {
                index++;
                if (index >= maxCount)
                {
                    if (WriteComplete != null)
                    {
                        WriteComplete();
                    }
                    Destroy(this);
                }
                else
                {
                    mOffset = 0;
                }
            }
        }
    }
예제 #20
0
    /// <summary>
    /// Text wrapping functionality. The 'width' and 'height' should be in pixels.
    /// </summary>

    public bool WrapText(string text, int size, out string finalText, int width, int height, int maxLines, bool encoding, SymbolStyle symbolStyle)
    {
        if (mReplacement != null)
        {
            return(mReplacement.WrapText(text, size, out finalText, width, height, maxLines, encoding, symbolStyle));
        }

#if DYNAMIC_FONT
        if (isDynamic)
        {
            return(NGUIText.WrapText(text, mDynamicFont, size, mDynamicFontStyle, width, height, maxLines, encoding, out finalText));
        }
#endif
        if (width < 1 || height < 1)
        {
            finalText = "";
            return(false);
        }

        int maxLineCount = (maxLines > 0) ? maxLines : 999999;
        maxLineCount = Mathf.Min(maxLineCount, height / size);

        if (maxLineCount == 0)
        {
            finalText = "";
            return(false);
        }

        StringBuilder sb             = new StringBuilder();
        int           textLength     = text.Length;
        int           remainingWidth = width;
        int           previousChar   = 0;
        int           start          = 0;
        int           offset         = 0;
        bool          lineIsEmpty    = true;
        bool          multiline      = (maxLines != 1);
        int           lineCount      = 1;
        bool          useSymbols     = encoding && symbolStyle != SymbolStyle.None && hasSymbols;

        // Run through all characters
        for (; offset < textLength; ++offset)
        {
            char ch = text[offset];

            // New line character -- start a new line
            if (ch == '\n')
            {
                if (!multiline || lineCount == maxLineCount)
                {
                    break;
                }
                remainingWidth = width;

                // Add the previous word to the final string
                if (start < offset)
                {
                    sb.Append(text.Substring(start, offset - start + 1));
                }
                else
                {
                    sb.Append(ch);
                }

                lineIsEmpty = true;
                ++lineCount;
                start        = offset + 1;
                previousChar = 0;
                continue;
            }

            // If this marks the end of a word, add it to the final string.
            if (ch == ' ' && previousChar != ' ' && start < offset)
            {
                sb.Append(text.Substring(start, offset - start + 1));
                lineIsEmpty  = false;
                start        = offset + 1;
                previousChar = ch;
            }

            // When encoded symbols such as [RrGgBb] or [-] are encountered, skip past them
            if (NGUIText.ParseSymbol(text, ref offset))
            {
                --offset; continue;
            }

            // See if there is a symbol matching this text
            BMSymbol symbol = useSymbols ? MatchSymbol(text, offset, textLength) : null;

            // Calculate how wide this symbol or character is going to be
            int glyphWidth = mSpacingX;

            if (symbol != null)
            {
                glyphWidth += symbol.advance;
            }
            else
            {
                // Find the glyph for this character
                BMGlyph glyph = (symbol == null) ? mFont.GetGlyph(ch) : null;

                if (glyph != null)
                {
                    glyphWidth += (previousChar != 0) ?
                                  glyph.advance + glyph.GetKerning(previousChar) : glyph.advance;
                }

                else
                {
                    continue;
                }
            }

            // Remaining width after this glyph gets printed
            remainingWidth -= glyphWidth;

            // Doesn't fit?
            if (remainingWidth < 0)
            {
                // Can't start a new line
                if (lineIsEmpty || !multiline || lineCount == maxLineCount)
                {
                    // This is the first word on the line -- add it up to the character that fits
                    sb.Append(text.Substring(start, Mathf.Max(0, offset - start)));

                    if (!multiline || lineCount == maxLineCount)
                    {
                        start = offset;
                        break;
                    }
                    NGUIText.EndLine(ref sb);

                    // Start a brand-new line
                    lineIsEmpty = true;
                    ++lineCount;

                    if (ch == ' ')
                    {
                        start          = offset + 1;
                        remainingWidth = width;
                    }
                    else
                    {
                        start          = offset;
                        remainingWidth = width - glyphWidth;
                    }
                    previousChar = 0;
                }
                else
                {
                    // Skip all spaces before the word
                    while (start < textLength && text[start] == ' ')
                    {
                        ++start;
                    }

                    // Revert the position to the beginning of the word and reset the line
                    lineIsEmpty    = true;
                    remainingWidth = width;
                    offset         = start - 1;
                    previousChar   = 0;

                    if (!multiline || lineCount == maxLineCount)
                    {
                        break;
                    }
                    ++lineCount;
                    NGUIText.EndLine(ref sb);
                    continue;
                }
            }
            else
            {
                previousChar = ch;
            }

            // Advance the offset past the symbol
            if (symbol != null)
            {
                offset      += symbol.length - 1;
                previousChar = 0;
            }
        }

        if (start < offset)
        {
            sb.Append(text.Substring(start, offset - start));
        }
        finalText = sb.ToString();
        return(!multiline || offset == textLength || (maxLines > 0 && lineCount <= maxLines));
    }
 private void Update()
 {
     if (!this.mActive)
     {
         return;
     }
     if (this.mReset)
     {
         this.mCurrentOffset = 0;
         this.mReset         = false;
         this.mLabel         = base.GetComponent <UILabel>();
         if (this.customText != null && this.customText != string.Empty)
         {
             this.mFullText = this.customText;
         }
         else
         {
             this.mFullText = this.mLabel.processedText;
         }
         this.mFade.Clear();
         if (this.keepFullDimensions && this.scrollView != null)
         {
             this.scrollView.UpdatePosition();
         }
     }
     while (this.mCurrentOffset < this.mFullText.Length && this.mNextChar <= RealTime.time)
     {
         int num = this.mCurrentOffset;
         this.charsPerSecond = Mathf.Max(1, this.charsPerSecond);
         while (NGUIText.ParseSymbol(this.mFullText, ref this.mCurrentOffset))
         {
         }
         this.mCurrentOffset++;
         if (this.mCurrentOffset > this.mFullText.Length)
         {
             break;
         }
         float num2 = 1f / (float)this.charsPerSecond;
         char  c    = (num >= this.mFullText.Length) ? '\n' : this.mFullText[num];
         if (c == '\n')
         {
             num2 += this.delayOnNewLine;
         }
         else if (num + 1 == this.mFullText.Length || this.mFullText[num + 1] <= ' ')
         {
             if (c == '.')
             {
                 if (num + 2 < this.mFullText.Length && this.mFullText[num + 1] == '.' && this.mFullText[num + 2] == '.')
                 {
                     num2 += this.delayOnPeriod * 3f;
                     num  += 2;
                 }
                 else
                 {
                     num2 += this.delayOnPeriod;
                 }
             }
             else if (c == '!' || c == '?')
             {
                 num2 += this.delayOnPeriod;
             }
         }
         if (this.mNextChar == 0f)
         {
             this.mNextChar = RealTime.time + num2;
         }
         else
         {
             this.mNextChar += num2;
         }
         if (this.fadeInTime != 0f)
         {
             CustomTypewriterEffect.FadeEntry item = default(CustomTypewriterEffect.FadeEntry);
             item.index = num;
             item.alpha = 0f;
             item.text  = this.mFullText.Substring(num, this.mCurrentOffset - num);
             this.mFade.Add(item);
         }
         else
         {
             this.mLabel.text = ((!this.keepFullDimensions) ? this.mFullText.Substring(0, this.mCurrentOffset) : (this.mFullText.Substring(0, this.mCurrentOffset) + "[00]" + this.mFullText.Substring(this.mCurrentOffset)));
             if (!this.keepFullDimensions && this.scrollView != null)
             {
                 this.scrollView.UpdatePosition();
             }
         }
     }
     if (this.mFade.size != 0)
     {
         int i = 0;
         while (i < this.mFade.size)
         {
             CustomTypewriterEffect.FadeEntry value = this.mFade[i];
             value.alpha += RealTime.deltaTime / this.fadeInTime;
             if (value.alpha < 1f)
             {
                 this.mFade[i] = value;
                 i++;
             }
             else
             {
                 this.mFade.RemoveAt(i);
             }
         }
         if (this.mFade.size == 0)
         {
             if (this.keepFullDimensions)
             {
                 this.mLabel.text = this.mFullText.Substring(0, this.mCurrentOffset) + "[00]" + this.mFullText.Substring(this.mCurrentOffset);
             }
             else
             {
                 this.mLabel.text = this.mFullText.Substring(0, this.mCurrentOffset);
             }
         }
         else
         {
             StringBuilder stringBuilder = new StringBuilder();
             for (int j = 0; j < this.mFade.size; j++)
             {
                 CustomTypewriterEffect.FadeEntry fadeEntry = this.mFade[j];
                 if (j == 0)
                 {
                     stringBuilder.Append(this.mFullText.Substring(0, fadeEntry.index));
                 }
                 stringBuilder.Append('[');
                 stringBuilder.Append(NGUIText.EncodeAlpha(fadeEntry.alpha));
                 stringBuilder.Append(']');
                 stringBuilder.Append(fadeEntry.text);
             }
             if (this.keepFullDimensions)
             {
                 stringBuilder.Append("[00]");
                 stringBuilder.Append(this.mFullText.Substring(this.mCurrentOffset));
             }
             this.mLabel.text = stringBuilder.ToString();
         }
     }
     else if (this.mCurrentOffset == this.mFullText.Length)
     {
         CustomTypewriterEffect.current = this;
         EventDelegate.Execute(this.onFinished);
         CustomTypewriterEffect.current = null;
         this.mActive = false;
     }
 }
예제 #22
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, int size, Color32 color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols,
                      bool encoding, SymbolStyle symbolStyle, TextAlignment alignment, int lineWidth, bool premultiply)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, size, color, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth, premultiply);
        }
        else if (text != null)
        {
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

#if DYNAMIC_FONT
            if (isDynamic)
            {
                NGUIText.Print(text, dynamicFont, size, mDynamicFontStyle, color, encoding,
                               alignment, lineWidth, premultiply, verts, uvs, cols);
                return;
            }
#endif
            mColors.Clear();
            mColors.Add(color);

            int     fs = size;
            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (fs + mSpacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;

            float invX = uvRect.width / mFont.texWidth;
            float invY = mUVRect.height / mFont.texHeight;

            int  textLength = text.Length;
            bool useSymbols = encoding && symbolStyle != SymbolStyle.None && hasSymbols && sprite != null;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (alignment != TextAlignment.Left)
                    {
                        NGUIText.Align(verts, indexOffset, alignment, x, lineWidth);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                if (encoding && NGUIText.ParseSymbol(text, ref i, mColors, premultiply))
                {
                    color = mColors[mColors.size - 1];
                    --i;
                    continue;
                }

                // See if there is a symbol matching this text
                BMSymbol symbol = useSymbols ? MatchSymbol(text, i, textLength) : null;

                if (symbol == null)
                {
                    BMGlyph glyph = mFont.GetGlyph(c);
                    if (glyph == null)
                    {
                        continue;
                    }

                    if (prev != 0)
                    {
                        x += glyph.GetKerning(prev);
                    }

                    if (c == ' ')
                    {
                        x   += mSpacingX + glyph.advance;
                        prev = c;
                        continue;
                    }

                    v0.x = (x + glyph.offsetX);
                    v0.y = -(y + glyph.offsetY);

                    v1.x = v0.x + glyph.width;
                    v1.y = v0.y - glyph.height;

                    u0.x = mUVRect.xMin + invX * glyph.x;
                    u0.y = mUVRect.yMax - invY * glyph.y;

                    u1.x = u0.x + invX * glyph.width;
                    u1.y = u0.y - invY * glyph.height;

                    x   += mSpacingX + glyph.advance;
                    prev = c;

                    if (glyph.channel == 0 || glyph.channel == 15)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(color);
                        }
                    }
                    else
                    {
                        // Packed fonts come as alpha masks in each of the RGBA channels.
                        // In order to use it we need to use a special shader.
                        //
                        // Limitations:
                        // - Effects (drop shadow, outline) will not work.
                        // - Should not be a part of the atlas (eastern fonts rarely are anyway).
                        // - Lower color precision

                        Color col = color;

                        col *= 0.49f;

                        switch (glyph.channel)
                        {
                        case 1: col.b += 0.51f; break;

                        case 2: col.g += 0.51f; break;

                        case 4: col.r += 0.51f; break;

                        case 8: col.a += 0.51f; break;
                        }

                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }
                else
                {
                    v0.x = (x + symbol.offsetX);
                    v0.y = -(y + symbol.offsetY);

                    v1.x = v0.x + symbol.width;
                    v1.y = v0.y - symbol.height;

                    Rect uv = symbol.uvRect;

                    u0.x = uv.xMin;
                    u0.y = uv.yMax;
                    u1.x = uv.xMax;
                    u1.y = uv.yMin;

                    x   += mSpacingX + symbol.advance;
                    i   += symbol.length - 1;
                    prev = 0;

                    if (symbolStyle == SymbolStyle.Colored)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(color);
                        }
                    }
                    else
                    {
                        Color32 col = Color.white;
                        col.a = color.a;
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }

                verts.Add(new Vector3(v1.x, v0.y));
                verts.Add(new Vector3(v1.x, v1.y));
                verts.Add(new Vector3(v0.x, v1.y));
                verts.Add(new Vector3(v0.x, v0.y));

                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u1.x, u1.y));
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u0.x, u0.y));
            }

            if (alignment != TextAlignment.Left && indexOffset < verts.size)
            {
                NGUIText.Align(verts, indexOffset, alignment, x, lineWidth);
                indexOffset = verts.size;
            }
        }
    }
예제 #23
0
    public void Show(string text, float width = 0)
    {
        Transform child;

        for (int i = 0; i < transform.childCount; i++)
        {
            child = transform.GetChild(i);
            if (child.name == "Icon(Clone)")
            {
                Destroy(child.gameObject);
            }
        }
        if (label == null)
        {
            label = gameObject.GetComponent <UILabel>();
        }

        if (spriteIcon == null)
        {
            spriteIcon = gameObject.transform.Find("Icon").gameObject.GetComponent <UISprite>();
        }
        label.text = "";
        label.UpdateNGUIText();
        per_height = label.height;
        cur_height = per_height;
        cur_width  = 0;
        if (e_list == null)
        {
            e_list = new List <IconData>();
        }
        m_curIndex = 0;

        max_width = width;
        System.Text.StringBuilder _sb = LuaInterface.StringBuilderCache.Acquire();

        float ch_width = 0.0f;
        int   length = text.Length;
        int   n = 0, m = 0;
        float space_width = NGUIText.CalculatePrintedSize(" ").x;
        int   lengthIcon  = 0;

        if (spriteIcon != null)
        {
            lengthIcon = (int)Math.Ceiling(spriteIcon.localSize.x / space_width);
        }
        for (int i = 0; i < length; i++)
        {
            if (m > i)
            {
                _sb.Append(text[i]);
                continue;
            }
            if (n > 0)
            {
                n--;
                continue;
            }

            if (text[i] == '[')
            {
                int  index     = i;
                bool is_symbol = NGUIText.ParseSymbol(text, ref index);
                if (is_symbol)
                {
                    m = index;
                    _sb.Append(text[i]);
                    continue;
                }
            }

            if (text[i] == '\n' && i + 1 <= length)
            {
                cur_width   = 0;
                cur_height += per_height;
                _sb.Append("\n");
                continue;
            }

            if (text[i] == '[' && text.Substring(i, 5).Equals("[img]"))
            {
                if (cur_width + 2 * space_width > max_width)
                {
                    cur_height += per_height;
                    cur_width   = 0;
                    _sb.Append("\n");
                }
                int      indexEnd     = text.IndexOf("[-]", i);
                string   eName        = text.Substring(i + 5, indexEnd - i - 5);
                IconData e            = null;
                bool     isExpression = false;
                if (eName != null || eName != "")
                {
                    isExpression = true;
                    e            = GetEmoticonByIndex(m_curIndex);
                    m_curIndex++;
                    e.eName    = eName;
                    e.pos.x    = cur_width + 2;
                    e.pos.y    = -1 * cur_height;
                    cur_width += lengthIcon * space_width;
                    for (int j = 0; j < lengthIcon; j++)
                    {
                        _sb.Append(" ");
                    }
                }

                if (!isExpression)
                {
                    _sb.Append(text[i]);
                }
                else
                {
                    n = indexEnd - i + 2;
                }
            }
            else
            {
                ch_width   = NGUIText.CalculatePrintedSize(text[i].ToString()).x;
                cur_width += ch_width;
                if (cur_width > max_width)
                {
                    _sb.Append("\n");
                    cur_height += per_height;
                    cur_width   = ch_width;
                }
                _sb.Append(text[i]);
            }
        }
        label.text = LuaInterface.StringBuilderCache.GetStringAndRelease(_sb);//output_str;
        Show_emoticon();
    }
예제 #24
0
    void Update()
    {
        if (!mActive)
        {
            return;
        }

        if (mReset)
        {
            mCurrentOffset = 0;
            mReset         = false;
            mLabel         = GetComponent <UILabel>();
            mFullText      = mLabel.processedText;
            mFade.Clear();

            if (keepFullDimensions && scrollView != null)
            {
                scrollView.UpdatePosition();
            }
        }

        while (mCurrentOffset < mFullText.Length && mNextChar <= RealTime.time)
        {
            int lastOffset = mCurrentOffset;
            charsPerSecond = Mathf.Max(1, charsPerSecond);

            // Automatically skip all symbols
            while (NGUIText.ParseSymbol(mFullText, ref mCurrentOffset))
            {
            }
            ++mCurrentOffset;

            // Reached the end? We're done.
            if (mCurrentOffset > mFullText.Length)
            {
                break;
            }

            // Periods and end-of-line characters should pause for a longer time.
            float delay = 1f / charsPerSecond;
            char  c     = (lastOffset < mFullText.Length) ? mFullText[lastOffset] : '\n';

            if (c == '\n')
            {
                delay += delayOnNewLine;
            }
            else if (lastOffset + 1 == mFullText.Length || mFullText[lastOffset + 1] <= ' ')
            {
                if (c == '.')
                {
                    if (lastOffset + 2 < mFullText.Length && mFullText[lastOffset + 1] == '.' && mFullText[lastOffset + 2] == '.')
                    {
                        delay      += delayOnPeriod * 3f;
                        lastOffset += 2;
                    }
                    else
                    {
                        delay += delayOnPeriod;
                    }
                }
                else if (c == '!' || c == '?')
                {
                    delay += delayOnPeriod;
                }
            }

            if (mNextChar == 0f)
            {
                mNextChar = RealTime.time + delay;
            }
            else
            {
                mNextChar += delay;
            }

            if (fadeInTime != 0f)
            {
                // There is smooth fading involved
                FadeEntry fe = new FadeEntry();
                fe.index = lastOffset;
                fe.alpha = 0f;
                fe.text  = mFullText.Substring(lastOffset, mCurrentOffset - lastOffset);
                mFade.Add(fe);
            }
            else
            {
                // No smooth fading necessary
                mLabel.text = keepFullDimensions ?
                              mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset) :
                              mFullText.Substring(0, mCurrentOffset);

                // If a scroll view was specified, update its position
                if (!keepFullDimensions && scrollView != null)
                {
                    scrollView.UpdatePosition();
                }
            }
        }

        // Alpha-based fading
        if (mFade.size != 0)
        {
            for (int i = 0; i < mFade.size;)
            {
                FadeEntry fe = mFade[i];
                fe.alpha += RealTime.deltaTime / fadeInTime;

                if (fe.alpha < 1f)
                {
                    mFade[i] = fe;
                    ++i;
                }
                else
                {
                    mFade.RemoveAt(i);
                }
            }

            if (mFade.size == 0)
            {
                if (keepFullDimensions)
                {
                    mLabel.text = mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset);
                }
                else
                {
                    mLabel.text = mFullText.Substring(0, mCurrentOffset);
                }
            }
            else
            {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < mFade.size; ++i)
                {
                    FadeEntry fe = mFade[i];

                    if (i == 0)
                    {
                        sb.Append(mFullText.Substring(0, fe.index));
                    }

                    sb.Append('[');
                    sb.Append(NGUIText.EncodeAlpha(fe.alpha));
                    sb.Append(']');
                    sb.Append(fe.text);
                }

                if (keepFullDimensions)
                {
                    sb.Append("[00]");
                    sb.Append(mFullText.Substring(mCurrentOffset));
                }

                mLabel.text = sb.ToString();
            }
        }
        else if (mCurrentOffset == mFullText.Length)
        {
            current = this;
            EventDelegate.Execute(onFinished);
            current = null;
            mActive = false;
        }
    }
예제 #25
0
    void Update()
    {
        if (mFinished)
        {
            return;
        }
        if (mReset)
        {
            mCurrentOffset = 0;
            mReset         = false;
            mLabel         = GetComponent <UILabel>();
            mFullText      = mLabel.processedText;
        }
        if (string.IsNullOrEmpty(mFullText))
        {
            return;
        }

        while (mCurrentOffset < mFullText.Length && mNextChar <= RealTime.time)
        {
            int lastOffset = mCurrentOffset;
            charsPerSecond = Mathf.Max(1, charsPerSecond);

            // Automatically skip all symbols
            if (mLabel.supportEncoding)
            {
                while (NGUIText.ParseSymbol(mFullText, ref mCurrentOffset))
                {
                }
            }

            ++mCurrentOffset;

            // Reached the end? We're done.
            if (mCurrentOffset > mFullText.Length)
            {
                break;
            }

            float delay = 1f / charsPerSecond;

            if (mNextChar == 0f)
            {
                mNextChar = RealTime.time + delay;
            }
            else
            {
                mNextChar += delay;
            }
            mLabel.text = mFullText.Substring(0, mCurrentOffset);
        }

        // Alpha-based fading
        if (mFullText.Length > 0 && mCurrentOffset >= mFullText.Length)
        {
            mLabel.text = mFullText;
            current     = this;
            EventDelegate.Execute(onFinished);
            current   = null;
            mFinished = true;
        }
    }