using UnityEngine; using UnityEngine.UI; using UnityEditor; using System; using System.Collections; using System.Collections.Generic; namespace TBTK{ [CustomEditor(typeof(UIPerkScreen))] //[CanEditMultipleObjects] public class I_UIPerkScreenEditor : TBEditorInspector { private UIPerkScreen instance; public override void Awake(){ base.Awake(); instance = (UIPerkScreen)target; instance.SetInstance(); } public override void OnInspectorGUI(){ base.OnInspectorGUI(); EditorGUILayout.Space(); DrawDefaultInspector(); EditorGUILayout.Space(); if(!instance.customLayout) return; string text="Fill up the item list using using the child in Item List Parent. This save you the trouble of manually assinging the item one by one "; text+="but you will still have to manually assign the perk-ID"; text+="\nThis will clear the existing list"; EditorGUILayout.HelpBox(text, MessageType.Info); cont=new GUIContent("Item List Parent:", ""); instance.perkListParent=(Transform)EditorGUILayout.ObjectField(cont, instance.perkListParent, typeof(Transform), true); if(GUILayout.Button("Fill List from Parent")){ FillListFromParent(); } EditorGUILayout.Space(); text="Auto generate the item for all eixisting perks. You can then rearrange the item manually"; text+="\nThis will clear the existing list"; EditorGUILayout.HelpBox(text, MessageType.Info); cont=new GUIContent("Perk Item Prefab:", ""); instance.perkItemPrefab=(GameObject)EditorGUILayout.ObjectField(cont, instance.perkItemPrefab, typeof(GameObject), true); if(GUILayout.Button("Generate Perk Buttons")){ GenerateButtons(); } EditorGUILayout.Space(); text="Rename and assign icon for each item according to their corresponding perk."; text+="\nThis function will also check for any duplicating items or item that doesn't have a valid perk-ID"; EditorGUILayout.HelpBox(text, MessageType.Info); if(GUILayout.Button("Verify and Name Existing Item")){ VerifyAndNameButtons(); } EditorGUILayout.Space(); } private Perk GetPerkFromID(int id){ for(int i=0; i existingList=new List(); for(int i=0; i(); imgIcon.sprite=perk.icon; instance.itemList[i].rootObj.name="pItem_"+perk.prefabID+"_"+perk.name; if(existingList.Contains(perk.prefabID)){ Debug.Log("Perk item contain duplicating ID, index-"+i+" perk-"+perk.name); } else existingList.Add(perk.prefabID); } else{ instance.itemList[i].rootObj.name="pItem_"; } } for(int i=0; i()==null) continue; instance.itemList.Add(new UIPerkScreen.UIPerkItem()); instance.itemList[count].rootObj=child.gameObject; count+=1; } } private void GenerateButtons(){ if(instance.perkItemPrefab==null){ Debug.Log("Invalid Action - No perk item prefab!"); return; } ClearItemList(); for(int i=0; i(); imgIcon.sprite=TBE.perkDB.perkList[i].icon; instance.itemList[i].rootObj.SetActive(true); } } private void ClearItemList(){ for(int i=0; i