c#
来源:互联网 发布:淘宝在哪里投诉卖家 编辑:程序博客网 时间:2024/06/05 15:54
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(); }}