利用HudText来制作连击爆字

利用HudText来制作连击爆字

HudText简介

HudText是NGUI的一个插件,用来显示人物的名字和血条。可以跟随人物移动,在屏幕UI上显示该有的东西,我们今天利用这个插件里面的脚本来制作爆字的功能。

调用方法

每次调用的时候调用ADD这个函数就是可以的了。
第一次调用mList.Count == 0 里面的代码,生成一个Entry1的对象。

public void Add(int obj, Color c, float stayDuration)//颜色已经固定//
    {
        if (!enabled) return;
        float time = Time.time;
        int val = 1;
        /////如果点击事件间隔小于一个值 则 刷新当前的entry的值 否则先删掉当前的entry,然后新建一个entry//
        //点击间隔时间 = time - ent.movementStart//
        // Create a new entry//
        if (mList.Count == 0)
        {
            Entry1 ne2 = Create();
            ne2.stay = stayDuration;
            ne2.label.color = c;
            ne2.val = obj;
            ne2.label.text = ConvertToSpecNum(ne2.val.ToString(), fontname); //使用的bitmap图lianji//

            timelast = ne2.time;
            if (triggerAction != null) triggerAction(1);
        }
        else
        {
            Entry1 ne = mList[0];
            float clickinterval = time - timelast;
            int kicknumbernow = val;
            if (clickinterval < combclickinterval) //如果点击事件小于设定的间隔,则连击数加一//
            {
                kicknumbernow = ne.val + obj;

            }
            else
            {
                kicknumbernow = obj;
            }
            if (triggerAction != null) triggerAction(kicknumbernow);
            Entry1 ne2 = Create();
            Delete(ne);
            ne2.stay = stayDuration;
            ne2.label.color = c;
            ne2.val = kicknumbernow;
            ne2.label.text = ConvertToSpecNum(ne2.val.ToString(), fontname);
            //ne2.label.text =  Mathf.RoundToInt (ne2.val);
            timelast = ne2.time;
        }
    }

创建字体

前两次的mUnused.Count小于等于0,前两次不会调用这个里面的代码,后面就会去调用到这个里面的代码。
这里会使用两个Label 是为了一个创建,一个又生成,且把标签的数字改掉,成为轮流换的形式.类似于放入缓存池里面,不用创建新的对象的。

Entry1 Create()
    {

        // See if an unused entry can be reused
        if (mUnused.Count > 0)
        {
            Entry1 ent = mUnused[mUnused.Count - 1];
            mUnused.RemoveAt(mUnused.Count - 1);
            ent.time = Time.time;
            ent.label.depth = NGUITools.CalculateNextDepth(gameObject);
            NGUITools.SetActive(ent.label.gameObject, true);
            //ent.offset = 0f;
            ent.offset_x = 0f;
            ent.offset_y = 0f;
            mList.Add(ent);
            return ent;
        }


        // New entry
        Entry1 ne = new Entry1();
        ne.time = Time.time;
        GameObject go = GameObject.Instantiate(headwordPrefab);
        go.transform.SetParent(transform);
        go.transform.localPosition = Vector3.zero;
        go.SetActive(true);
        ne.label = go.GetComponent<UILabel>();
        //ne.label = NGUITools.AddWidget<UILabel>(gameObject);
        ne.label.name = counter.ToString();
        //ne.label.bitmapFont = bitmapFont;
        ne.label.fontSize = fonts;
        ne.label.fontStyle = fontStyle;
        ne.label.applyGradient = applyGradient;
        ne.label.gradientTop = gradientTop;
        ne.label.gradientBottom = gradienBottom;
        ne.label.effectStyle = effect;
        ne.label.effectColor = effectColor;
        ne.label.overflowMethod = UILabel.Overflow.ResizeFreely;

        // Make it small so that it's invisible to start with
        ne.label.cachedTransform.localScale = new Vector3(0.001f, 0.001f, 0.001f);
        mList.Add(ne);
        ++counter;
        return ne;
    }

刷新里面的动画效果

对其中的字体进行动画的效果显示,这个是自己定义的动画的曲线,可以自己来使用特定的动画曲线。

    void Update()
    {
        float time = Time.time;
        //== 计算动画播放总时间
        // Adjust alpha and delete old entries
        for (int i = mList.Count; i > 0; )
        {
            Entry1 ent = mList[--i];
            float currentTime = time - ent.time;
            //float ct = currentTime;
            //* totalEnd / ent.stay;
            //ent.offset_y = comb.transform.position.y+0.5f;
            //ent.offset_x = comb.transform.position.x+0.5f;
            ent.offset_x = offsetCurve_x.Evaluate(currentTime)+35f;
            ent.offset_y = offsetCurve_y.Evaluate(currentTime)-5f;
            ent.label.alpha = alphaCurve.Evaluate(currentTime);
            //ent.flyDirection.x *   ent.flyDirection.y * 
            ent.label.cachedTransform.localPosition = new Vector3(ent.offset_x, ent.offset_y, 0);//本地坐标//
            // Make the label scale in
            float s = scaleCurve.Evaluate(time - ent.time);
            //Debug.Log(time - ent.time +" "+ent.label.text);
            if (s < 0.01f) s = 0.01f;
            ent.label.cachedTransform.localScale = new Vector3(s, s, s);
            //修改让文字和数字一起跳动。
            comboWordSpriteObj.gameObject.transform.localScale = new Vector3(s, s, s);
            comboLightSpriteObj.gameObject.transform.localScale = new Vector3(s, s, s);
            ////更改形状////////////////////////////////////////////////////////////
            ent.label.depth = 10;
            ent.label.spacingX = -5;//数字之间的间隔//
            ent.label.pivot = UIWidget.Pivot.BottomLeft;//设定对齐方式为左下角//
            //旋转角度//
            //ent.label.transform.localEulerAngles=new Vector3(labelrotate_x,labelrotate_y,labelrotate_z);
            // Delete the entry when needed
            if (currentTime > ent.stay)
            {
                Delete(ent);
            }
            else
            {
                ent.label.enabled = true;
            }
            islabel = mList.Count;
            if (islabel > 0)
            {
                comboWordSpriteObj.gameObject.SetActive(true);//使comb和light随着数字一起消失和出现//
                comboLightSpriteObj.gameObject.SetActive(true);
            }
            else
            {
                comboWordSpriteObj.gameObject.SetActive(false);
                comboLightSpriteObj.gameObject.SetActive(false);
            }   
        }

    }
-------------------------------------------------- NGUI: HUD Text Copyright 漏 2012-2014 Tasharen Entertainment Version 1.11 http://www.tasharen.com/forum/index.php?topic=997.0 -------------------------------------------------- Thank you for buying NGUI HUD Text! This version of HUDText has been tested with NGUI 3.4.9 If you have NGUI 2.7.0 or earlier, delete the Examples and Scripts folders, then import the contents of the hudtext_ngui270.unitypackage instead. ---------------------------------------------- !! IMPORTANT NOTE !! ---------------------------------------------- Upon importing this package into a brand-new project, you will get compile errors unless that project already has NGUI present! You'll need to import NGUI as well. If you don't have NGUI, but still want to use HUDText, then I am guessing you didn't read the package's description! But... you can still use HUDText. Get in touch with me via support@tasharen.com and I will hook you up. ---------------------------------------------- Usage: 1. Attach the HUDText script to a game object underneath your UIRoot and set the font it should use. 2. To make it follow an object drawn with another camera, attach UIFollowTarget to the same object and set its target. 3. From code, use HUDText's Add() function to add new floating text entries. You can also tweak the splines on the HUDText script, changing the motion of the text as you see fit. Video: http://www.youtube.com/watch?v=diql3UP1KQM ---------------------------------------------- Example Usage: ---------------------------------------------- HUDText hudText = GetComponent<HUDText>(); // This will show damage of 123 in red, and the message will immediately start moving. hudText.Add(-123f, Color.red, 0f); // This will show "Hello World!" and make it stay on the screen for 1 second before moving hudText.Add("Hello World!", Color.white, 1f); // If you don't want your numeric damage values to be added up, pass them as a string instead: float myDamage = 123f; hudText.Add(myDamage.ToString(), Color.red, 1f); ---------------------------------------------- If you have any questions, suggestions, comments or feature requests, please drop by the forums, found here: http://www.tasharen.com/forum/index.php?topic=997.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值