using System; using System.Collections; using System.Collections.Generic; using cfg.BlacksmithData; using UnityEngine; using UnityEngine.UI; public class DrawingPanel : MonoBehaviour { [SerializeField] private List DrawingItems; [SerializeField] private Image icon; [SerializeField] private Slider _slider; [SerializeField] private Text name; [SerializeField] private Text sliderNum; [SerializeField] private Text attack; [SerializeField] private Text hp; [SerializeField] private Text speed; [SerializeField] private List lvList = new List(); [SerializeField] private Button _button; [SerializeField] private List _itemObjs; [SerializeField] private GameObject parent; [SerializeField] private FreePanel _freePanel; [SerializeField] private Button closeFreeButton; [SerializeField] private Button closeDrawData; private WeaponAttributeData wData; private void OnEnable() { _button.onClick.AddListener(UpDrawing); closeFreeButton.onClick.AddListener(CloseFree); closeDrawData.onClick.AddListener(CloseDrawing); } private void OnDisable() { _button.onClick.RemoveListener(UpDrawing); closeFreeButton.onClick.RemoveListener(CloseFree); closeDrawData.onClick.RemoveListener(CloseDrawing); } public void OpenPanel() { Reset(); CloseDrawing(); CloseFree(); } public void OpenDrawing() { parent.SetActive(true); } public void CloseDrawing() { parent.SetActive(false); } public void OpenFree(int itemId) { _freePanel.gameObject.SetActive(true); _freePanel.OpenFreePanel(itemId); } public void CloseFree() { _freePanel.gameObject.SetActive(false); Reset(); } // Start is called before the first frame update public void Reset() { var drawData = JsonTab.Instance.tables.Weapon.DataList; for (int i = 0; i < DrawingItems.Count; i++) { DrawingItems[i].InitData(drawData[i].ID,this); } } public void OpenDrawDataPanel(int id) { var le=DataManager.GetDrawLevel(id); var data = JsonTab.Instance.tables.Weapon.Get(id); wData = JsonTab.Instance.attributeData(data.ID, le); var datas=JsonTab.Instance.Attribute[data.ID]; var skillList = new List(); icon.sprite = AssetBundleManager.ins.Sprite(data.Icon, AtlasType.DrawingIcon); foreach (var v in datas) { if (v.Value.Getskill!=0) { skillList.Add(v.Value); } } for (int i = 0; i < skillList.Count; i++) { var lsData = JsonTab.Instance.attributeData(data.ID, skillList[i].Level); lvList[i].text = "等级lv" + skillList[i].Level + "获得" + JsonTab.Instance.tables.Skill.Get(lsData.Getskill).Skillname; if (DataManager.GetDrawLevel(id)>skillList[i].Level) { lvList[i].color = Color.green; } else { lvList[i].color = Color.grey; } } name.text = data.Name; _slider.value = (float)DataManager.GetItem(wData.Upgrade)/wData.Upgradenumber; sliderNum.text = DataManager.GetItem(wData.Upgrade) + " / " + wData.Upgradenumber; string nextHP = ""; string nexAttack = ""; if (le+1<=40) { var nexData=JsonTab.Instance.attributeData(data.ID, le+1); nextHP = "+"+nexData.HP.ToString(); nexAttack="+"+nexData.Attack.ToString(); } hp.text = wData.HP.ToString()+""+ nextHP +""; attack.text = wData.Attack.ToString()+""+ nexAttack +""; if (DataManager.GetItem(wData.Upgrade)>=wData.Upgradenumber) { sliderNum.color=Color.green; } else { sliderNum.color=Color.red; } for (int i = 0; i < data.Include.Count; i++) { _itemObjs[i].SetData(data.Include[i],DataManager.GetItem(data.Include[i])); _itemObjs[i].panel = this; } } public void UpDrawing() { if (DataManager.GetItem(wData.Upgrade) >= wData.Upgradenumber) { SoundSystem.ins.LevelAudio(); DataManager.SaveDrawLevel(wData.Arms,DataManager.GetDrawLevel(wData.Arms)+1); DataManager.RemoveItem(wData.Upgrade,wData.Upgradenumber); var attributeData=JsonTab.Instance.attributeData(wData.Arms, DataManager.GetDrawLevel(wData.Arms)); if (attributeData.Unlock!=0) { var craftData = JsonTab.Instance.tables.CraftingRecipes.Get(attributeData.Unlock); DataManager.SaveItemUnLock(craftData.ID,true); if (craftData.Levelprops1!=0) { DataManager.SaveItemUnLock(craftData.Levelprops1,true); } if (craftData.Levelprops2!=0) { DataManager.SaveItemUnLock(craftData.Levelprops2,true); } if (craftData.Levelprops3!=0) { DataManager.SaveItemUnLock(craftData.Levelprops3,true); } if (craftData.Levelprops4!=0) { DataManager.SaveItemUnLock(craftData.Levelprops4,true); } } } else { } OpenDrawDataPanel(wData.Arms); Reset(); } }