public void AddItemNewPile(string itemName, FirDir firDir) { UIHorItem horItem = GetHorItemByName(itemName); if (horItem) { horItem.ShowItemByDir(firDir); if (horItem.IsAllItemEnable()) { for (int i = 0; i < horItemList.Count; i++) { if (horItemList[i].name != itemName) { Vector3 vecTemp = horItemList[i].transform.localPosition; horItemList[i].transform.localPosition = new Vector3(vecTemp.x, vecTemp.y + UIHorItem.itemHeight, vecTemp.z); } else { Score = Score + 1; moveSpeed += 1; int temp = PlayerPrefs.GetInt("MAX_SCORE", 0); if (Score > temp) { PlayerPrefs.SetInt("MAX_SCORE", Score); labMaxScore.text = string.Format("最高得分:{0}", Score); } horItemList.RemoveAt(i); break; } } NGUITools.Destroy(horItem.gameObject); } } }
void Update() { gameObject.transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y + Time.deltaTime * moveSpeed, transform.localPosition.z); horItem = MainController.instance.uiGamePanel.GetHorItemByPos(transform.localPosition); if (gameObject.transform.localPosition.y > 404) { NGUITools.Destroy(gameObject); return; } if (horItem != null) { itemEnable = horItem.ShowItemEnable(curDir); if (itemEnable) { if (string.IsNullOrEmpty(lastGetName)) { //生成新的一行 MainController.instance.uiGamePanel.AddNewHorItem(horItem.transform.localPosition, curDir); } else { //去掉一行 MainController.instance.uiGamePanel.AddItemNewPile(lastGetName, curDir); } NGUITools.Destroy(gameObject); } else { lastGetName = horItem.name; } } }
public void AddNewHorItem(Vector3 lastItemPos, FirDir firDir) { GameObject obj = NGUITools.AddChild(itemParent, uiHorItem.gameObject); obj.transform.localPosition = new Vector3(0, lastItemPos.y - UIHorItem.itemHeight, 0); UIHorItem horItem = obj.GetComponent <UIHorItem>(); horItem.AddNewItem(firDir); obj.SetActive(true); obj.name = genCount.ToString(); genCount++; horItemList.Insert(0, horItem); }