UI 자동화를 위해 바인딩 기능 구현

- 유니티 에셋 인증 오류로 meta 재생성
This commit is contained in:
2026-01-25 01:31:34 +09:00
parent 2ceb28f55d
commit ce83f21c93
1861 changed files with 377882 additions and 211 deletions

View File

@@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: f04a4f1be0f3364478dd7276aebb2f24
guid: f04a4f1be0f3364478dd7276aebb2f24
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -16,6 +16,8 @@ public class PlayerController : MonoBehaviour
// Managers.Input.KeytAction += OnKyeboard;
Managers.Input.MouseAction -= OnMouseClicked;
Managers.Input.MouseAction += OnMouseClicked;
Managers.Resource.Instantiate("UI/UI_Button");
}
public enum PlayerState
@@ -126,7 +128,7 @@ public class PlayerController : MonoBehaviour
Debug.DrawRay(Camera.main.transform.position, ray.direction * 100.0f, Color.red, 1.0f);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 100.0f, LayerMask.GetMask("Wall")));
if(Physics.Raycast(ray, out hit, 100.0f, LayerMask.GetMask("Wall")))
{
_destPos = hit.point;
_state = PlayerState.Moving;

View File

@@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 07c76605d2feab34488f71316e532b7f
guid: 07c76605d2feab34488f71316e532b7f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
public class InputManager
{
@@ -10,6 +11,11 @@ public class InputManager
public void OnUpdate()
{
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
if (Input.anyKey && KeytAction != null)
{
KeytAction.Invoke();

View File

@@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 8affb13a0221d604ebc76b80353674ef
guid: 8affb13a0221d604ebc76b80353674ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 20259f303a81e9c499cd0c47d0948d73
guid: 20259f303a81e9c499cd0c47d0948d73
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 02a54b2c0d9166a4fad881d75ebc136b
guid: 02a54b2c0d9166a4fad881d75ebc136b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Scripts/UI.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ffb9afdbdd56bff41b65f1ec647c330e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UI_Base : MonoBehaviour
{
Dictionary<Type, UnityEngine.Object[]> _objects = new Dictionary<Type, UnityEngine.Object[]>();
// Bind<제네릭>(인자)
protected void Bind<T>(Type type) where T : UnityEngine.Object
{
string[] names = Enum.GetNames(type);
UnityEngine.Object[] objects = new UnityEngine.Object[names.Length];
_objects.Add(typeof(T), objects);
for (int i = 0; i < names.Length; i++)
{
if (typeof(T) == typeof(GameObject))
{
objects[i] = Util.FindChild(gameObject, names[i], true);
}
else
{
objects[i] = Util.FindChild<T>(gameObject, names[i], true);
}
if (objects[i] == null)
{
Debug.Log($"Fail to Bind({names[i]})");
}
}
}
protected T Get<T>(int idx) where T : UnityEngine.Object
{
UnityEngine.Object[] objects = null;
if (_objects.TryGetValue(typeof(T), out objects) == false)
{
return null;
}
return objects[idx] as T;
}
protected TextMeshProUGUI GetText(int idx)
{
return Get<TextMeshProUGUI>(idx);
}
protected Button GetButton(int idx)
{
return Get<Button>(idx);
}
protected Image GetImage(int idx)
{
return Get<Image>(idx);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1e84740b977012741997a345570e2db4

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UI_Button : UI_Base
{
enum Buttons
{
PointButton,
}
enum Texts
{
PointText,
ScoreText,
}
enum GameObjects
{
TestObject
}
private void Start()
{
// Reflection
Bind<Button>(typeof(Buttons));
// Text 대신 TextMeshProUGUI로 변경
Bind<TextMeshProUGUI>(typeof(Texts));
Bind<GameObject>(typeof(GameObjects));
// Get 호출 시에도 타입을 맞춰줍니다.
// Get<TextMeshProUGUI>((int)Texts.ScoreText).text = "Bind Test";
GetText((int)Texts.ScoreText).text = "Bind Test";
}
private int _score = 0;
public void OnButtonClicked()
{
// GetComponentInChildren<TextMeshProUGUI>().text = "텍스트 변경 완료!";
_score += 1;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 16e71df7503657545a650786979749eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: a90e7e545f5f7d849ad6e1d942c43416
guid: a90e7e545f5f7d849ad6e1d942c43416
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
using UnityEngine;
public class Util
{
public static GameObject FindChild(GameObject go, string name = null, bool recursive = false)
{
Transform transform = FindChild<Transform>(go, name, recursive);
if (transform == null)
{
return null;
}
return transform.gameObject;
}
public static T FindChild<T>(GameObject go, string name = null, bool recursive = false) where T : UnityEngine.Object
{
if (go == null)
{
return null;
}
if (recursive == false)
{
for (int i = 0; i < go.transform.childCount; i++)
{
Transform transform = go.transform.GetChild(0);
if (string.IsNullOrEmpty(name) || transform.name == name)
{
T component = transform.GetComponent<T>();
if (component != null)
{
return component;
}
}
}
}
else
{
foreach (T component in go.GetComponentsInChildren<T>())
{
if (string.IsNullOrEmpty(name) || component.name == name)
{
return component;
}
}
}
return null;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4ef5f89f8af03d8459f764d03025ad5d