update
This commit is contained in:
27
Assets/Plugins/XRLib/UI/ButtonExtension.cs
Normal file
27
Assets/Plugins/XRLib/UI/ButtonExtension.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using static UnityEngine.UI.Button;
|
||||
|
||||
namespace WI
|
||||
{
|
||||
public static class ButtonExtension
|
||||
{
|
||||
public delegate void CustomAction();
|
||||
public delegate void CustomAction<T>(List<T> values);
|
||||
}
|
||||
|
||||
public static class ScrollRectExtension
|
||||
{
|
||||
public static void Clear(this ScrollRect rect)
|
||||
{
|
||||
var childCount = rect.content.transform.childCount;
|
||||
for(int i =0;i<childCount;++i)
|
||||
{
|
||||
GameObject.DestroyImmediate(rect.content.transform.GetChild(0).gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Plugins/XRLib/UI/ButtonExtension.cs.meta
Normal file
11
Assets/Plugins/XRLib/UI/ButtonExtension.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81cdeaa8efd4e2d439f243745c96f72a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Plugins/XRLib/UI/CanvasBase.cs
Normal file
11
Assets/Plugins/XRLib/UI/CanvasBase.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace WI
|
||||
{
|
||||
public abstract class CanvasBase : UIBase, ISingle
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/XRLib/UI/CanvasBase.cs.meta
Normal file
11
Assets/Plugins/XRLib/UI/CanvasBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd7b108b54890e449a6d5e76077d125e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Plugins/XRLib/UI/PanelBase.cs
Normal file
30
Assets/Plugins/XRLib/UI/PanelBase.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
using static UnityEngine.UI.Button;
|
||||
|
||||
namespace WI
|
||||
{
|
||||
public abstract class PanelBase : UIBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static class PanelBaseExtension
|
||||
{
|
||||
public static void SetActive(this PanelBase[] pbs, bool value)
|
||||
{
|
||||
foreach(var p in pbs)
|
||||
{
|
||||
p.SetActive(value);
|
||||
}
|
||||
}
|
||||
public static void SetActive(this PanelBase[] pbs, bool value, int count)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
pbs[i].SetActive(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Plugins/XRLib/UI/PanelBase.cs.meta
Normal file
11
Assets/Plugins/XRLib/UI/PanelBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75a2d50f89d57f344a0664a3b1f72142
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Plugins/XRLib/UI/UIBase.cs
Normal file
30
Assets/Plugins/XRLib/UI/UIBase.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace WI
|
||||
{
|
||||
public abstract class UIBase : MonoBehaviour
|
||||
{
|
||||
public RectTransform rectTransform => GetComponent<RectTransform>();
|
||||
public event Action<UIBase> onEnableEvent;
|
||||
public event Action<UIBase> onDisableEvent;
|
||||
|
||||
public void SetActive(bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
onEnableEvent?.Invoke(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
onDisableEvent?.Invoke(this);
|
||||
}
|
||||
gameObject.SetActive(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/XRLib/UI/UIBase.cs.meta
Normal file
11
Assets/Plugins/XRLib/UI/UIBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd08d05d1c8a53644a9e41f4a7e1a0b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Plugins/XRLib/UI/UIOption.cs
Normal file
10
Assets/Plugins/XRLib/UI/UIOption.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using WI;
|
||||
|
||||
[CreateAssetMenu(fileName = "UIOption", menuName = "UIOption", order = 0)]
|
||||
public class UIOption : ScriptableObject
|
||||
{
|
||||
public SDictionary<string, string> options = new();
|
||||
}
|
||||
11
Assets/Plugins/XRLib/UI/UIOption.cs.meta
Normal file
11
Assets/Plugins/XRLib/UI/UIOption.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc358a0e610272141b3325d2426929e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
223
Assets/Plugins/XRLib/UI/UISettingHelper.cs
Normal file
223
Assets/Plugins/XRLib/UI/UISettingHelper.cs
Normal file
@@ -0,0 +1,223 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using WI;
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public class UISettingHelper : Editor
|
||||
{
|
||||
[MenuItem("Tools/UIClassGenerate")]
|
||||
public static void UIClassGenerate()
|
||||
{
|
||||
Canvas[] canvases = GameObject.FindObjectsOfType<Canvas>();
|
||||
string defalutUsing = "using UnityEngine;\nusing UnityEngine.UI;\nusing WI;\n\n";
|
||||
string defalutNameSpace = "namespace XED\n{\n";
|
||||
|
||||
foreach (Canvas canvas in canvases)
|
||||
{
|
||||
string canvasPath;
|
||||
string canvasFileName = canvas.gameObject.name + ".cs";
|
||||
canvasPath = Path.Combine("Assets/Scripts/UI", canvasFileName);
|
||||
|
||||
var childs = canvas.GetComponentsInChildren<Transform>();
|
||||
List<string> childPanels = new List<string>();
|
||||
Dictionary<string, int> dupleCount = new Dictionary<string, int>();
|
||||
foreach (var c in childs)
|
||||
{
|
||||
if (c.name.Split('_')[0] != "Panel")
|
||||
continue;
|
||||
childPanels.Add(c.gameObject.name);
|
||||
|
||||
if (c.TryGetComponent<PanelBase>(out var tb))
|
||||
continue;
|
||||
|
||||
string panelName = c.gameObject.name + ".cs";
|
||||
string panelPath = Path.Combine("Assets/Scripts/UI", panelName);
|
||||
|
||||
var uiElements = c.FindAll<UIBehaviour>();
|
||||
|
||||
using FileStream fs = File.Create(panelPath);
|
||||
using StreamWriter writer = new StreamWriter(fs);
|
||||
writer.Write(defalutUsing);
|
||||
writer.Write(defalutNameSpace);
|
||||
writer.WriteLine($"\tinternal class {c.gameObject.name} : PanelBase");
|
||||
writer.WriteLine("\t{");
|
||||
Dictionary<string, List<string>> nameTable = new Dictionary<string, List<string>>();
|
||||
foreach (var e in uiElements)
|
||||
{
|
||||
var eType = e.GetType();
|
||||
string eName;
|
||||
if (eType == typeof(TextMeshProUGUI))
|
||||
eName = "text";
|
||||
else
|
||||
eName = eType.Name;
|
||||
|
||||
if (e.name.Contains('_'))
|
||||
eName += $"_{e.name.Split('_').Last()}";
|
||||
else
|
||||
{
|
||||
eName += $"_{e.transform.parent.name.Split('_').Last()}";
|
||||
}
|
||||
|
||||
eName = eName.Replace(" ", "");
|
||||
//writer.WriteLine($"\t\tpublic {eType} {eName.ToLower()};");
|
||||
if (!nameTable.ContainsKey(eType.FullName))
|
||||
nameTable.Add(eType.FullName, new());
|
||||
|
||||
if (!dupleCount.ContainsKey(eName))
|
||||
dupleCount.Add(eName, 0);
|
||||
dupleCount[eName]++;
|
||||
|
||||
if (nameTable[eType.FullName].Contains(eName))
|
||||
{
|
||||
eName += dupleCount[eName];
|
||||
}
|
||||
nameTable[eType.FullName].Add(eName);
|
||||
|
||||
|
||||
}
|
||||
foreach (var nt in nameTable)
|
||||
{
|
||||
var temp = nt.Value.OrderBy(a => a.Length);
|
||||
|
||||
foreach (var en in temp)
|
||||
{
|
||||
writer.WriteLine($"\t\tpublic {nt.Key} {en.ToLower()};");
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
writer.WriteLine("\t}");
|
||||
writer.Write("}");
|
||||
}
|
||||
|
||||
if (canvas.TryGetComponent<CanvasBase>(out var cb))
|
||||
continue;
|
||||
|
||||
using (FileStream fs = File.Open(canvasPath, FileMode.OpenOrCreate))
|
||||
{
|
||||
using StreamWriter writer = new StreamWriter(fs);
|
||||
writer.Write(defalutUsing);
|
||||
writer.Write(defalutNameSpace);
|
||||
writer.WriteLine($"\tpublic class {canvas.gameObject.name} : CanvasBase");
|
||||
writer.WriteLine("\t{");
|
||||
foreach (var cp in childPanels)
|
||||
{
|
||||
writer.WriteLine($"\t\t{cp} {cp.ToLower()};");
|
||||
}
|
||||
writer.WriteLine("\t}");
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
//Debug.Log(canvas.gameObject);
|
||||
}
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
[MenuItem("Tools/UIClassAttach")]
|
||||
public static void UIClassAttach()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
Canvas[] canvases = GameObject.FindObjectsOfType<Canvas>();
|
||||
|
||||
foreach (var canvas in canvases)
|
||||
{
|
||||
var canvasName = canvas.gameObject.name;
|
||||
|
||||
var canvasClassType = assemblies.SelectMany(a => a.GetTypes())
|
||||
.FirstOrDefault(t => t.Name == canvasName);
|
||||
|
||||
if (canvasClassType == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
canvas.transform.GetOrAddComponent(canvasClassType);
|
||||
|
||||
var childPanels = canvas.transform.FindAll<RectTransform>().Where(cr => cr.name.Split('_')[0] == "Panel");
|
||||
foreach (var panel in childPanels)
|
||||
{
|
||||
var panelName = panel.gameObject.name;
|
||||
var panelClassType = assemblies.SelectMany(a => a.GetTypes())
|
||||
.FirstOrDefault(t => t.Name == panelName);
|
||||
|
||||
if (panelClassType == null)
|
||||
continue;
|
||||
|
||||
panel.transform.GetOrAddComponent(panelClassType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/UI HoverText File Generate")]
|
||||
static void UIHoverTextFileGenerate()
|
||||
{
|
||||
// 1. PanelBase를 상속받은 모든 클래스 검색
|
||||
var panelClasses = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(a => a.GetTypes())
|
||||
.Where(t => t.IsSubclassOf(typeof(PanelBase)));
|
||||
|
||||
// 2. Resources/language에 ko.txt 열기
|
||||
string filePath = "Assets/Resources/language/ko.txt";
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
File.Create(filePath).Dispose();
|
||||
}
|
||||
|
||||
// 3. 열린 파일의 모든 줄 읽기
|
||||
Dictionary<string, string> hoverTexts = new Dictionary<string, string>();
|
||||
using (StreamReader reader = new StreamReader(filePath))
|
||||
{
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
// 각 줄은 다음의 구조를 가지고 있음: $"{UIBehaviour.gameObject.name}:anyText"
|
||||
string[] parts = line.Split(':');
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
string gameObjectName = parts[0];
|
||||
string hoverText = parts[1];
|
||||
hoverTexts.Add(gameObjectName, hoverText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 이어서 UIBehaviour.gameObject.name과 anyText로 Dictionary를 생성
|
||||
foreach (Type panelClass in panelClasses)
|
||||
{
|
||||
// 5. 해당 PanelBase의 멤버 변수들 중에서 UIBehaviour를 선별
|
||||
var uiBehaviours = panelClass.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
||||
.Where(f => typeof(UIBehaviour).IsAssignableFrom(f.FieldType));
|
||||
|
||||
foreach (var uiBehaviour in uiBehaviours)
|
||||
{
|
||||
string gameObjectName = uiBehaviour.Name.ToLower();
|
||||
string hoverText = "";
|
||||
|
||||
// 6. Dictionary에 UIBehaviour의 이름이 존재하지 않는다면 추가
|
||||
if (!hoverTexts.ContainsKey(gameObjectName))
|
||||
{
|
||||
hoverTexts.Add(gameObjectName, hoverText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var orderd = hoverTexts.OrderBy(p => p.Key);
|
||||
// 7. 열린 파일에 입력
|
||||
using (StreamWriter writer = new StreamWriter(filePath,false, System.Text.Encoding.UTF8))
|
||||
{
|
||||
foreach (var hoverText in orderd)
|
||||
{
|
||||
writer.WriteLine($"{hoverText.Key}:{hoverText.Value}");
|
||||
}
|
||||
}
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Plugins/XRLib/UI/UISettingHelper.cs.meta
Normal file
11
Assets/Plugins/XRLib/UI/UISettingHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad46ddab56d4de143806d043fd2694bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user