NGUI卡片特效脚本-三个抽卡卡牌特效另一个为发牌特效

写了两个卡牌特效。有三种效果。一种是横着的。点击相应卡牌。将点击拍片置顶。另外一种是竖像的。点击卡片。突出并置顶。有移动效果。另外一个为发牌特效。看工程里。

如下图所示:

横向:

NGUI特效制作1

NGUI特效制作2

竖向:

3

4

 

 

 

如下图,修改为竖向。只需将该标志量设置为true

5
好了上代码:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SceneLuckyCard : MonoBehaviour
{

    #region 数据定义
    private List<string> mNameList = new List<string>();
    private GameObject mItem;
    private UIPanel mMovePanel;
    private int CardEffectOffset = 80;

    public List<GameObject> cardList;
    private int indexCard;//当前选中卡--
    private int cardCount;
    private int maxDepth = 50;//最大深度--
    private Vector3 indexPosition;
    public float timeSpan = 0.2f;
    public bool isIEnum = true;
    private List<Vector3> posList;
    public Vector2 offsetCard = new Vector2(20f, 100f);//偏移--
    /// <summary> 是否竖向 </summary>
    public bool direction = false;
    #endregion

    // Use this for initialization
	void Start () 
    {
        mItem = PublicFunction.GetComponentByLocalPath<Transform>(this.gameObject, "PanelMove/Items/Item").gameObject;
        mMovePanel = PublicFunction.GetComponentByLocalPath<UIPanel>(this.gameObject, "PanelMove");

        mNameList.Add("德玛西亚"); mNameList.Add("皮城女警"); mNameList.Add("影流之主"); mNameList.Add("末日浩劫"); mNameList.Add("荒野屠夫"); mNameList.Add("刀锋之影"); mNameList.Add("提莫对账"); mNameList.Add("麦林炮手"); mNameList.Add("荒野屠夫"); mNameList.Add("刀锋之影"); 
        StartCoroutine(CloneItem(mNameList.Count));
        Debug.LogError(mNameList.Count);
        indexCard = mNameList.Count - 1;
        cardCount = mNameList.Count;
	}

    IEnumerator CloneItem(int num)
    {
        if (num >= 9)
        {
            CardEffectOffset -= 15;
        }
        for (int i = 0; i < num; i++)
        {
            GameObject item = Instantiate(mItem) as GameObject;
            item.transform.parent = mItem.transform.parent;
            item.transform.localEulerAngles = Vector3.zero;
            item.transform.localScale = Vector3.one;
            item.transform.localPosition = new Vector3(-900,0,0);
            item.name = i.ToString();
            cardList.Add(item);
            UIEventListener listener = UIEventListener.Get(item);
            listener.onClick = OnClickCard;
            yield return new WaitForSeconds(0.2f) ;
            FlightEffect(i,item);
        }

        if (posList != null && posList.Count > 0) posList.Clear();
        else posList = new List<Vector3>();
        foreach (GameObject go in cardList)
        {
            posList.Add(go.transform.localPosition);
        }

    }

    void FlightEffect(int index,GameObject item)
    {
        TweenPosition tp = item.AddComponent<TweenPosition>();
        tp.from = item.transform.localPosition;
        tp.to = new Vector3(300 - (CardEffectOffset * index), item.transform.localPosition.y, 0);
        tp.duration = 0.2f;
        UIWidget[] tran = item.GetComponentsInChildren<UIWidget>(true);

        foreach (UIWidget tra in tran)
        {
            tra.depth += (index*5);
        }

    }

    void OnClickCard(GameObject go)
    {
        int tempindex = 0;
        for (int i = 0; i < cardList.Count; i++)
        {
            if (cardList[i].name == go.name)
            {
                tempindex = i; break;
            }
        }
        if (tempindex != indexCard)
        {
            //cardList[indexCard].GetComponent<UIWidget>().color = Color.grey;
            indexCard = tempindex;
            UIWidget uw = go.GetComponent<UIWidget>();
            uw.depth = maxDepth;
            uw.color = Color.white;
            indexPosition = new Vector3(0, go.transform.localPosition.y, 0);
            if (direction)
                TweenPosition.Begin(go, timeSpan, indexPosition);
            StartCoroutine(SetCardOrder(timeSpan / 2f, isIEnum, direction));
            SetDepth(uw.depth, go);
        }
    }

    public void SetCardOrder()
    {
        //StartCoroutine(SetCardOrder(0.01f, false));
    }
    public IEnumerator SetCardOrder(float span, bool isienum, bool erect)
    {
        int tempDepth = maxDepth;
        if (indexCard > 0)
        {
            for (int i = indexCard; i > 0; --i)
            {
                Vector3 tempPos = indexPosition;
                if (i != indexCard) { tempPos = posList[i]; }
                GameObject go = cardList[i - 1];
                if (erect)//如果竖立。则有移动效果
                {
                    posList[i - 1] = new Vector3(tempPos.x + offsetCard.x, tempPos.y + offsetCard.y, tempPos.z);
                    TweenPosition.Begin(go, timeSpan, posList[i - 1]);
                }
                UIWidget uw = go.GetComponent<UIWidget>();
                if (uw != null)
                {
                    tempDepth -= 5;
                    uw.depth = tempDepth;
                }
                SetDepth(uw.depth, go);
                //if (isienum) yield return new WaitForSeconds(span);
            }
            tempDepth = maxDepth;
        }
        if (indexCard < cardList.Count - 1)
        {
            for (int i = indexCard; i < cardCount - 1; ++i)
            {
                Vector3 tempPos = indexPosition;
                if (i != indexCard) { tempPos = posList[i]; }
                GameObject go = cardList[i + 1];
                if (erect)//如果竖立。则有移动效果
                {
                    posList[i + 1] = new Vector3(tempPos.x + offsetCard.x, tempPos.y - offsetCard.y, tempPos.z);
                    TweenPosition.Begin(go, timeSpan, posList[i + 1]);
                }
                UIWidget uw = go.GetComponent<UIWidget>();
                if (uw != null)
                {
                    tempDepth -= 5;
                    uw.depth = tempDepth;
                }
                SetDepth(uw.depth, go);
                //if (isienum) yield return new WaitForSeconds(span);
            }
        }
        
        yield return 1;
    }

    void SetDepth(int parentDepth,GameObject obj)
    {
        UIWidget[] tran = obj.GetComponentsInChildren<UIWidget>(true);

        PublicFunction.GetComponentByLocalPath<UILabel>(obj, "Label").depth = parentDepth +1;
        PublicFunction.GetComponentByLocalPath<UISprite>(obj, "Time").depth = parentDepth + 1;
        PublicFunction.GetComponentByLocalPath<UILabel>(obj, "Time/Label").depth = parentDepth + 1;
    }
}

 

最后工程下载地址:http://yunpan.cn/Q7nSyqPjEeRVS  提取码 3d01

本文链接:

https://www.bobsong.net/259.html
1 + 9 =
快来做第一个评论的人吧~