1
This commit is contained in:
82
unity/Assets/Script/LevelUpSystem/LevelItem.cs
Normal file
82
unity/Assets/Script/LevelUpSystem/LevelItem.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Managers;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LevelItem : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
public int LevelId;
|
||||
public int PreId;//前置节点
|
||||
public Text need;
|
||||
public Text activeText;
|
||||
private void Awake()
|
||||
{
|
||||
foreach (var date in Date.Instance.UpDate)
|
||||
{
|
||||
if (date.UpId == LevelId)
|
||||
{
|
||||
if(PlayerInfo.Instance.info.UpValue[date.UpId])
|
||||
{
|
||||
activeText.text = "已激活";
|
||||
need.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
activeText.text = "未激活";
|
||||
need.text = date.useNum.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
foreach (var date in Date.Instance.UpDate)
|
||||
{
|
||||
if (date.UpId == LevelId&&!PlayerInfo.Instance.info.UpInfo[date.UpId])
|
||||
{
|
||||
if(CheckUp(LevelId))
|
||||
{
|
||||
if(!PlayerInfo.Instance.info.BagInfo.ContainsKey(date.userId))
|
||||
{
|
||||
Debug.Log("所用道具不足");
|
||||
return;
|
||||
}
|
||||
if(PlayerInfo.Instance.info.BagInfo[date.userId]>=date.useNum)
|
||||
{
|
||||
PlayerInfo.Instance.BagMgr.UserItem(date.userId, date.useNum);
|
||||
PlayerInfo.Instance.ItemLevel(date);
|
||||
activeText.text = "已激活";
|
||||
need.gameObject.SetActive(false);
|
||||
|
||||
//保存数据
|
||||
PlayerInfo.Instance.info.UpValue[date.UpId] = true;
|
||||
PlayerInfo.Instance.info.UpInfo[date.UpId] = PlayerInfo.Instance.info.UpValue[date.UpId];
|
||||
SaveSystem.SaveDate(PlayerInfo.Instance.info.DatePath, PlayerInfo.Instance.info);
|
||||
|
||||
return;
|
||||
}
|
||||
Debug.Log("所用道具不足");
|
||||
return;
|
||||
}
|
||||
Debug.Log("前置条件没有升级");
|
||||
}
|
||||
}
|
||||
}
|
||||
bool CheckUp(int id)
|
||||
{
|
||||
if(id==0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!PlayerInfo.Instance.info.UpValue[Date.Instance.UpDate[id].PreId])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user