c#

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

public class EndClearPanel : MonoBehaviour {

    public MainUI mainUI;

    public GameObject inventoryParent;
    public GameObject itemListObj;
    public GameObject clearItem;
    private Dictionary<int, GoodsInfo> ownGoods;
    private List<EndClearItem> uilist = new List<EndClearItem>();

    //score calculate
    public int goodsScore;
    public int goldScore;
    public int totalScore;
    public UILabel lgoodsScore;
    public UILabel lgoldScore;
    public UILabel ltotalScore;

    //number anim
    const int FRAME = 40;
    private int targetScore;
    private int goodsScorePerFrame;
    private int goldScorePerFrame;
    private bool ainmbegin = true; //private bool ainmbegin = false;
    private bool flag = true;

    void OnEnable()
    {
        MainUI.curActive_panel = mainUI.shop_panel;
        //ainmbegin = false;
        Init();
    }

    void Init()
    {
       
        collider.enabled = true;
        ownGoods = UserData.player.goodsInBag;
        ownGoods.Clear();
        goodsScore = 0;
        goldScore = UserData.player.tradeMoney;
        totalScore = UserData.player.score;
        foreach (KeyValuePair<int,GoodsInfo> data in ownGoods)
        {
            goodsScore += (data.Value.amount * data.Value.avgPrice);
            GameObject item = NGUITools.AddChild(itemListObj, clearItem);
            EndClearItem script = item.GetComponent<EndClearItem>();
            
            if (script != null) {
                script.SetData(data.Value);
            }
        }
        
        lgoodsScore.text = "" + goodsScore;
        lgoldScore.text = "" + goldScore;
        ltotalScore.text = "" + totalScore;
        targetScore = totalScore + goldScore + goodsScore;

       goodsScorePerFrame = goodsScore / FRAME;
        if (goodsScore > 0 && goodsScorePerFrame <= 0) {
            goodsScorePerFrame = 1;
        }

        goldScorePerFrame = goldScore / FRAME;
        if (goldScore > 0 && goldScorePerFrame <= 0) {
            goldScorePerFrame = 1;
        }
        Invoke("RepositonList", 0.1f);
        
        
    }

    /*void RepositonList()
    {
        UIGrid grid = itemListObj.GetComponent<UIGrid>();
        if (grid != null) {
            grid.repositionNow = true;
            grid.Reposition();
        }
    }*/

   /* void OnClick()
    {
        UserData.player.goodsInBag.Clear();
        
        if (!ainmbegin)
        {
            ainmbegin = true;
            collider.enabled = false;
            return;
          
        }
        else
        {
            mainUI.OnEnterEndPanel();
            collider.enabled = false;
        }
    }
    * */
    void OnClick()
    {
       

        
        mainUI.OnEnterEndPanel();
        collider.enabled = false;
       
    }
        

   void Update()
    {

       
        if (!ainmbegin)
            return;

        if (goodsScore <= 0 && goldScore <= 0) {
            goldScore = 0;
            goodsScore = 0;
            totalScore = targetScore;
            collider.enabled = true;
        } else {
            int addCount = 0;
            if (goodsScore <= 0) {
                goodsScore = 0;
            } else {
                goodsScore -= goodsScorePerFrame;
                addCount = goodsScorePerFrame;
            }

            if (goldScore <= 0) {
                goldScore = 0;
            } else {
                goldScore -= goldScorePerFrame;
                addCount += goldScorePerFrame;
            }
            totalScore += addCount;
        }

        lgoodsScore.text = "" + goodsScore;
        lgoldScore.text = "" + goldScore;
        ltotalScore.text = "" + totalScore;
    }

   void OnDisable()
    {

        ownGoods.Clear();
        //ainmbegin = false;
        foreach (EndClearItem item in uilist)
        {
            NGUITools.Destroy(item.gameObject);
        }
        uilist.Clear();
   }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值