using System; using System.Collections.Generic; using UnityEngine; using System.Linq; #if UNITY_EDITOR using UnityEditor; #endif public enum eTabType { BGColorChange, BGImageChange, OnOff } [Serializable] public class TabUIData { /// /// (자동설정) 탭 순서 0~ /// public int m_Index { get; set; } public bool SetImg = true; public int n_btnName = 0; public string btnName, imgName_On, imgName_Off; public int n_Update = 0; public bool CanTouch = true; /// /// 버튼을 터치했을 때 액션 /// public Action onClick; /// /// (자동설정) 선택된 탭 설정, 탭 UI 상태 갱신 /// [HideInInspector] public Action onTabAction; } public class TabUIBase : uScrollViewMgr { [Header("Tab to be open on first run (-1 == None)")] public int FirstTab = 0; int m_Index = 0; [Header("Individual tab settings should be configured in the child object (tab_dontDelete).")] [Header("(Required) Please set the tab data (list_tabData).")] [Header("n_btnName : Local table int Key")] [Header("btnName : Use text instead of local key (e.g. 1 2 3, etc.)")] [Header("n_Update : Local key for content scheduled for update (0 == None)")] [Header("CanTouch : Whether the button can be touched (usually controlled by script)")] public List list_tabData; public override void Set(Action action) { if (go_card.activeSelf) go_card.SetActive(false); for (int i = 0; i < list_tabData.Count; i++) { list_tabData[i].m_Index = i; list_tabData[i].onTabAction = OnClick_Tab; list_tabData[i].onClick = action; } Set_ScrollView(list_tabData); Set_Index(FirstTab); if (FirstTab == -1) { FirstTab = -2; Set_Index(-1); } else { if (FirstTab > -1) Set_Index(FirstTab); OnClick_Tab(m_Index); } Set_UI(); } public override void Set_UI() { for (int i = 0; i < list_CardBase.Count; i++) { if (list_CardBase[i].Get_IntData() == m_Index) list_CardBase[i].Set_CardType(eUICardType.UI); else list_CardBase[i].Set_CardType(eUICardType.NoTouch); } } public void Set_Index_Set_UI(int index) { if (Get_Index() != index) { Set_Index(index); Set_UI(); } } public void Set_Index(int index) { m_Index = index; } public int Get_Index() { return m_Index; } public void OnClick_Tab_byScript(int index) { for (int i = 0; i < list_CardBase.Count; i++) { if (list_CardBase[i].Get_IntData() == index) { (list_CardBase[i] as TabCardBase).OnClickTab_Force(); break; } } } void OnClick_Tab(int index) { if (list_tabData[index].n_Update > 0) Popup.Ins.Set(ePopupType.One, list_tabData[index].n_Update); else { m_Index = FirstTab == -2 && index == m_Index ? -1 : index; Set_UI(); } } // 인스펙터에서 값이 변경될 때마다 이 함수가 호출됩니다. [SerializeField, HideInInspector] private int prevCount = 0; private void OnValidate() { if (list_tabData == null) return; // 요소가 추가된 경우 if (list_tabData.Count > prevCount) { for (int i = prevCount; i < list_tabData.Count; i++) { var tab = list_tabData[i]; tab.CanTouch = true; } } // 요소가 삭제된 경우 else if (list_tabData.Count < prevCount) { // prevCount를 현재 개수로 맞춰줌 // (데이터 수정은 필요 없음) } // 현재 개수 기록 prevCount = list_tabData.Count; } } #if UNITY_EDITOR [CustomEditor(typeof(TabCardBase))] public class TabUIEditor : Editor { public override void OnInspectorGUI() { serializedObject.Update(); SerializedProperty tabTypeProp = serializedObject.FindProperty("m_TabType"); EditorGUILayout.PropertyField(tabTypeProp); // enum-based fields eTabType type = (eTabType)tabTypeProp.enumValueIndex; switch (type) { case eTabType.BGColorChange: EditorGUILayout.PropertyField(serializedObject.FindProperty("color_bg_on")); EditorGUILayout.PropertyField(serializedObject.FindProperty("color_bg_off")); break; case eTabType.BGImageChange: EditorGUILayout.PropertyField(serializedObject.FindProperty("Tab_BG_Img_on")); EditorGUILayout.PropertyField(serializedObject.FindProperty("Tab_BG_Img_off")); break; case eTabType.OnOff: EditorGUILayout.PropertyField(serializedObject.FindProperty("go_TabOnOff_on")); EditorGUILayout.PropertyField(serializedObject.FindProperty("go_TabOnOff_off")); break; } // common EditorGUILayout.PropertyField(serializedObject.FindProperty("color_text_on")); EditorGUILayout.PropertyField(serializedObject.FindProperty("color_text_off")); EditorGUILayout.PropertyField(serializedObject.FindProperty("color_img_on")); EditorGUILayout.PropertyField(serializedObject.FindProperty("color_img_off")); EditorGUILayout.PropertyField(serializedObject.FindProperty("Tab_Img_on")); EditorGUILayout.PropertyField(serializedObject.FindProperty("Tab_Img_off")); EditorGUILayout.PropertyField(serializedObject.FindProperty("gos_off")); EditorGUILayout.PropertyField(serializedObject.FindProperty("m_btn")); EditorGUILayout.PropertyField(serializedObject.FindProperty("images")); EditorGUILayout.PropertyField(serializedObject.FindProperty("texts")); serializedObject.ApplyModifiedProperties(); // 버튼 추가 if (GUILayout.Button("이미지[1] 삭제")) { TabCardBase tabCard = (TabCardBase)target; if (tabCard.images != null && tabCard.images.Length > 1 && tabCard.images[1] != null) { // 씬 오브젝트 삭제 (Undo 가능하게) Undo.DestroyObjectImmediate(tabCard.images[1].gameObject); // 값 null 처리 var lst = tabCard.images.ToList(); lst.RemoveAt(1); tabCard.images = lst.ToArray(); // 변경사항 저장 EditorUtility.SetDirty(tabCard); } else { Debug.LogWarning("images[1]가 없습니다."); } } } } #endif