using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace TBTK{ public class UIPerkScreen : UIScreen { [Tooltip("Check to use custom layout\n\nYou can use arrange your own layout in the scroll view\nYou will need to manually assign the item to itemList and assign the perk associate to the item")] public bool customLayout=false; public static bool UseCustomLayout(){ return instance.customLayout; } [Space(10)] [Tooltip("A list of all the item in the scroll view\nNeed to be manually assign when using custom layout\nFill up automatically when not using custom layout")] public List itemList=new List(); //[Space(5)] //public RectTransform selectHighlightT; [Space(5)] public Text lbPerkCurrency; public Text lbPerkPoint; [Space(10)] public Text lbPerkName; public Text lbPerkDesp; public Text lbPerkUnavailable; public UIObject perkCostObj; public UIObject perkCurrencyObj; //public List costItemList=new List(); [Space(10)] public UIButton buttonUnlock; public UIButton buttonClose; [Space(8)] [HideInInspector] public Transform perkListParent; [HideInInspector] public GameObject perkItemPrefab; private static UIPerkScreen instance; public void SetInstance(){ instance=this; } //used by custom Inspector public override void Awake(){ base.Awake(); instance=this; } public override void Start(){ if(!PerkManager.PerkSystemEnabled()){ thisObj.SetActive(false); return; } //perkCostObj.Init(); perkCostObj.image.sprite=PerkDB.GetRscIcon(); //perkCurrencyObj.Init(); perkCurrencyObj.image.sprite=PerkDB.GetRscIcon(); if(customLayout){ List perkList=PerkManager.GetPerkList(); for(int i=0; i perkList=PerkManager.GetPerkList(); if(perkList.Count==0){ UIControl.DisablePerkMenu(); thisObj.SetActive(false); return; } if(perkItemPrefab==null) perkItemPrefab=itemList[0].rootObj; for(int i=0; i0) itemList.Add(UIPerkItem.Clone(itemList[0].rootObj, "PerkItem"+(i))); if(i>0) itemList.Add(UIPerkItem.Clone(perkItemPrefab, "PerkItem"+(i))); itemList[i].Init(); int idx=i; itemList[i].button.onClick.AddListener(delegate { OnItem(idx); }); //itemList[i].SetCallback(null, null, this.OnItem, null); itemList[i].linkedPerkPID=perkList[i].prefabID; itemList[i].linkedPerkIdx=i; itemList[i].image.sprite=perkList[i].icon; itemList[i].rootObj.SetActive(true); } } for(int i=0; i"+PerkManager.GetPerkCurrency()+""; lbPerkPoint.text="point: "+PerkManager.GetPerkPoint()+""; } private int selectedIdx=0; public void OnItem(int idx){ //int idx=GetItemIndex(butObj); itemList[selectedIdx].SetHighlight(false); itemList[idx].SetHighlight(true); selectedIdx=idx; //selectHighlightT.localPosition=itemList[idx].rectT.localPosition-new Vector3(35, -35, 0); //Debug.Log(selectHighlightT.localPosition+" "+itemList[idx].rectT.localPosition); Perk perk=PerkManager.GetPerkOfIndex(itemList[idx].linkedPerkIdx); lbPerkName.text=perk.name; lbPerkDesp.text=perk.desp; lbPerkUnavailable.text=perk.IsAvailable();//perk.GetDespUnavailable(); buttonUnlock.label.text="Unlock cost - "+perk.GetCost()+""; //~ if(!PerkManager.UseRscManagerForCost()){ //perkCostObj.label.text=perk.GetCost().ToString("f0"); //~ } //~ else{ //~ List cost=perk.GetPurchaseCostRsc(); //~ for(int i=0; i