84 lines
2.3 KiB
C#
84 lines
2.3 KiB
C#
using TMPro;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using XRLib;
|
|
using XRLib.UI;
|
|
|
|
[CustomEditor(typeof(PanelBase), true)]
|
|
public class PanelBaseEditor : Editor
|
|
{
|
|
PanelBase pb;
|
|
|
|
//1. pb transform의 child Button 목록 cbList 가져오기
|
|
//2. cbList를 순회하며 반복
|
|
//2-1. childButton 의 gameObject.name string 을 '_' 문자로 Split
|
|
//2-2. Split된 문자열 배열에서 가장 마지막 배열의 문자열인 cbName 가져오기
|
|
//2-3. cbName을 childButton 하위의 TextMeshProUGUI의 텍스트로 삽입
|
|
|
|
public void OnEnable()
|
|
{
|
|
//base.OnInspectorGUI();
|
|
pb = target as PanelBase;
|
|
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
base.OnInspectorGUI();
|
|
|
|
if (GUILayout.Button("Button Naming"))
|
|
{
|
|
ButtonNaming();
|
|
}
|
|
|
|
if(GUILayout.Button("Text Titleling"))
|
|
{
|
|
TextTitleling();
|
|
}
|
|
}
|
|
|
|
void TextTitleling()
|
|
{
|
|
//1. pb transform의 child Text 목록 가져오기
|
|
TextMeshProUGUI[] textList = pb.transform.GetComponentsInChildren<TextMeshProUGUI>();
|
|
|
|
//2. child Text의 gameObject.name 을 '_'로 Split
|
|
foreach (var text in textList)
|
|
{
|
|
string[] nameSplit = text.gameObject.name.Split('_');
|
|
|
|
//3. Split된 문자열 배열에서 첫번째 배열의 값이 "Title" 일 경우
|
|
if (nameSplit[0] == "Title")
|
|
{
|
|
//4. 해당 childText에 Split된 문자열 배열의 두번째 배열값 입력
|
|
text.text = nameSplit[1];
|
|
}
|
|
}
|
|
}
|
|
|
|
void ButtonNaming()
|
|
{
|
|
//1. pb transform의 child Button 목록 cbList 가져오기
|
|
Button[] cbList = pb.transform.GetComponentsInChildren<Button>();
|
|
|
|
//2. cbList를 순회하며 반복
|
|
foreach (var cb in cbList)
|
|
{
|
|
//2-1. childButton 의 gameObject.name string 을 '_' 문자로 Split
|
|
string[] nameSplit = cb.gameObject.name.Split('_');
|
|
|
|
//2-2. Split된 문자열 배열에서 가장 마지막 배열의 문자열인 cbName 가져오기
|
|
string cbName = nameSplit[nameSplit.Length - 1];
|
|
|
|
//2-3. cbName을 childButton 하위의 TextMeshProUGUI의 텍스트로 삽입
|
|
TextMeshProUGUI text = cb.GetComponentInChildren<TextMeshProUGUI>();
|
|
if (text != null)
|
|
{
|
|
text.text = cbName;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|