844 lines
34 KiB
C#
844 lines
34 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using TMPro;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
using UnityEngine.UI;
|
|
using static UnityEngine.Rendering.DebugUI;
|
|
using Button = UnityEngine.UI.Button;
|
|
|
|
public static class MyEditorUtil
|
|
{
|
|
struct TransformData
|
|
{
|
|
public Vector3 localPosition;
|
|
public Quaternion localRotation;
|
|
public Vector3 localScale;
|
|
|
|
public TransformData(Vector3 localPosition, Quaternion localRotation, Vector3 localScale)
|
|
{
|
|
this.localPosition = localPosition;
|
|
this.localRotation = localRotation;
|
|
this.localScale = localScale;
|
|
}
|
|
}
|
|
private static TransformData _data;
|
|
|
|
[MenuItem("Edit/Copy Transform Values &c", false, -101)]
|
|
public static void CopyTransformValues()
|
|
{
|
|
if (Selection.gameObjects.Length == 0) return;
|
|
var selectionTr = Selection.gameObjects[0].transform;
|
|
_data = new TransformData(selectionTr.localPosition, selectionTr.localRotation, selectionTr.localScale);
|
|
}
|
|
|
|
[MenuItem("Edit/Paste Transform Values &v", false, -101)]
|
|
public static void PasteTransformValues()
|
|
{
|
|
foreach (var selection in Selection.gameObjects)
|
|
{
|
|
Transform selectionTr = selection.transform;
|
|
Undo.RecordObject(selectionTr, "Paste Transform Values");
|
|
selectionTr.localPosition = _data.localPosition;
|
|
selectionTr.localRotation = _data.localRotation;
|
|
selectionTr.localScale = _data.localScale;
|
|
}
|
|
}
|
|
|
|
[MenuItem("Edit/Del All Child", false, -102)]
|
|
public static void DelAllChild()
|
|
{
|
|
foreach (var selection in Selection.gameObjects)
|
|
{
|
|
Transform selectionTr = selection.transform;
|
|
for (int i = 0; i < selectionTr.childCount; i++)
|
|
{
|
|
GameObject.DestroyImmediate(selectionTr.GetChild(i).gameObject);
|
|
--i;
|
|
}
|
|
}
|
|
}
|
|
|
|
[MenuItem("Edit/Set Mob Data", false, -103)]
|
|
public static void SetMobData()
|
|
{ // 설정된 몹 프리팹을 지우고 몹 데이터만 남긴다. 해당 데이터로 게임 내에서 몹을 동적 로딩한다.
|
|
foreach (var selection in Selection.gameObjects)
|
|
{
|
|
var mobs = selection.GetComponentsInChildren<Actor>();
|
|
var dic_wave = new Dictionary<string, LoadMobData>();
|
|
for (int i = 0; i < mobs.Length; i++)
|
|
{
|
|
var parent = mobs[i].transform.parent;
|
|
if (!dic_wave.ContainsKey(parent.name))
|
|
{
|
|
var loaddata = parent.GetComponent<LoadMobData>();
|
|
if (loaddata == null) loaddata = parent.gameObject.AddComponent<LoadMobData>();
|
|
dic_wave.Add(parent.name, loaddata);
|
|
}
|
|
|
|
var detaildata = new LoadMobDetailData
|
|
{
|
|
m_Position = mobs[i].transform.position,
|
|
m_Rotation = mobs[i].transform.rotation,
|
|
m_Role = mobs[i].m_Role,
|
|
m_SubRole = mobs[i].m_SubRole,
|
|
m_MagicID = (mobs[i] as MobActor).MagicID,
|
|
};
|
|
|
|
if (mobs[i].name.Contains("("))
|
|
{
|
|
var split = mobs[i].name.Split(' ');
|
|
detaildata.m_PrefabName = "";
|
|
if (split.Length == 2)
|
|
detaildata.m_PrefabName = split[0];
|
|
else
|
|
for (int j = 0; j < split.Length - 1; j++)
|
|
{
|
|
if (j == split.Length - 2)
|
|
detaildata.m_PrefabName += split[j];
|
|
else
|
|
detaildata.m_PrefabName += split[j] + " ";
|
|
}
|
|
}
|
|
else
|
|
detaildata.m_PrefabName = mobs[i].name;
|
|
|
|
var witch = mobs[i] as WitchEnemyActor;
|
|
if (witch != null)
|
|
detaildata.list_MagicID = witch.list_MagicID;
|
|
|
|
dic_wave[parent.name].list_mobdata.Add(detaildata);
|
|
GameObject.DestroyImmediate(mobs[i].gameObject);
|
|
}
|
|
}
|
|
}
|
|
[MenuItem("Edit/Optimize Mesh", false, -104)]
|
|
public static void OptimizeMesh()
|
|
{ // 메쉬 렌더러를 찾아서 최적화 한다.
|
|
if (Selection.activeObject)
|
|
{
|
|
var meshrenderer = (Selection.activeObject as GameObject).GetComponentsInChildren<MeshRenderer>();
|
|
for (int i = 0; i < meshrenderer.Length; i++)
|
|
{
|
|
if (meshrenderer[i].tag.Equals("Untagged"))
|
|
{
|
|
var om = meshrenderer[i].GetComponent<OptimizeMesh>();
|
|
if (om == null) om = meshrenderer[i].gameObject.AddComponent<OptimizeMesh>();
|
|
om.Start();
|
|
om.DecimateMesh_byPath();
|
|
om.SaveMesh("Assets/ResWork/Optimized/");
|
|
GameObject.DestroyImmediate(om);
|
|
}
|
|
}
|
|
|
|
EditorUtility.DisplayDialog("메시 최적화", "완료", "알았다");
|
|
}
|
|
}
|
|
|
|
[MenuItem("Edit/GetFolderFileNames", false, -105)]
|
|
public static void GetFolderFileNames()
|
|
{
|
|
DirectoryInfo di = new DirectoryInfo("Assets/ResWork/UIPrefabs/Title");
|
|
var ext = ".prefab"; // ".mat";
|
|
|
|
var filenames = "";
|
|
foreach (FileInfo file in di.GetFiles("*" + ext))
|
|
filenames += file.Name.Replace(ext, "") + "\n";
|
|
Debug.Log(filenames);
|
|
}
|
|
|
|
private static List<ObjectSettings> objectSettingsList = new List<ObjectSettings>();
|
|
|
|
[MenuItem("Edit/MobSetting &s", false, -1001)]
|
|
static void MobSetting()
|
|
{
|
|
var selectedObjects = Selection.gameObjects;
|
|
|
|
foreach (var go in selectedObjects)
|
|
{
|
|
var ma = go.GetComponent<MobActor>();
|
|
if (ma == null) ma = go.AddComponent<MobActor>();
|
|
|
|
var m_bc = go.GetComponent<BoxCollider>();
|
|
if (m_bc == null) m_bc = go.AddComponent<BoxCollider>();
|
|
|
|
var longd = go.GetComponent<NoSeeLongDMob>();
|
|
if (longd == null) go.AddComponent<NoSeeLongDMob>();
|
|
|
|
CommonSetting(go, 51);
|
|
}
|
|
}
|
|
|
|
[MenuItem("Edit/PetSetting", false, -1002)]
|
|
static void PetSetting()
|
|
{
|
|
var selectedObjects = Selection.gameObjects;
|
|
|
|
foreach (var go in selectedObjects)
|
|
{
|
|
var ma = go.GetComponent<PetActor>();
|
|
if (ma == null) ma = go.AddComponent<PetActor>();
|
|
ma.m_Role = eRole.Pet;
|
|
|
|
CommonSetting(go, 51);
|
|
}
|
|
}
|
|
[MenuItem("Edit/PCSetting", false, -1003)]
|
|
static void PCSetting()
|
|
{
|
|
var selectedObjects = Selection.gameObjects;
|
|
|
|
foreach (var go in selectedObjects)
|
|
{
|
|
// 프리팹 에셋 경로 가져오기
|
|
string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go);
|
|
|
|
// Prefab인지 확인
|
|
if (!string.IsNullOrEmpty(prefabPath))
|
|
{
|
|
// Prefab Asset 가져오기
|
|
var prefabAsset = PrefabUtility.LoadPrefabContents(prefabPath);
|
|
|
|
var ma = prefabAsset.GetComponent<WizardActor>();
|
|
if (ma == null) ma = prefabAsset.AddComponent<WizardActor>();
|
|
ma.m_Role = eRole.PC;
|
|
|
|
var navmesh = prefabAsset.GetComponent<NavMeshAgent>();
|
|
if (navmesh == null) navmesh = prefabAsset.AddComponent<NavMeshAgent>();
|
|
navmesh.speed = 6f;
|
|
navmesh.angularSpeed = 300f;
|
|
navmesh.acceleration = 140f;
|
|
navmesh.stoppingDistance = 4f;
|
|
navmesh.autoBraking = true;
|
|
navmesh.radius = 0.4f;
|
|
navmesh.height = 2f;
|
|
navmesh.avoidancePriority = 50;
|
|
navmesh.obstacleAvoidanceType = ObstacleAvoidanceType.LowQualityObstacleAvoidance;
|
|
|
|
Set_CommonRigidBody(prefabAsset);
|
|
|
|
var cc = prefabAsset.GetComponent<CapsuleCollider>();
|
|
if (cc == null) cc = prefabAsset.AddComponent<CapsuleCollider>();
|
|
cc.center = Vector3.up * 0.79f;
|
|
cc.radius = 0.55f;
|
|
cc.height = 1.58f;
|
|
cc.direction = 1;
|
|
|
|
var pcactor = prefabAsset.GetComponent<PCActor>();
|
|
List<Transform> list_tr = new List<Transform>();
|
|
|
|
// 프리팹 내부 수정
|
|
var wristL = FindDeepChild(prefabAsset.transform, "Wrist_L");
|
|
var wristR = FindDeepChild(prefabAsset.transform, "Wrist_R");
|
|
|
|
if (wristL != null)
|
|
{
|
|
var strName = "w_shield";
|
|
var shield = FindDeepChild(prefabAsset.transform, strName);
|
|
if (shield == null) shield = new GameObject(strName).transform;
|
|
shield.parent = wristL;
|
|
shield.localPosition = new Vector3(0.1238701f, -0.02092049f, -0.1054159f);
|
|
shield.localEulerAngles = new Vector3(32.28088f, 2.733658f, 4.798194f);
|
|
shield.localScale = Vector3.one * 0.5f;
|
|
list_tr.Add(shield);
|
|
}
|
|
if (wristR != null)
|
|
{
|
|
var strName = "w_righthand";
|
|
var mace = FindDeepChild(prefabAsset.transform, strName);
|
|
if (mace == null) mace = new GameObject(strName).transform;
|
|
mace.parent = wristR;
|
|
mace.localPosition = new Vector3(-0.04300008f, 0.02999998f, -0.01899974f);
|
|
mace.localEulerAngles = new Vector3(-85.83548f, -95.7005f, -3.785309f);
|
|
mace.localScale = Vector3.one * 0.8958604f;
|
|
list_tr.Add(mace);
|
|
}
|
|
|
|
if (wristR != null)
|
|
{
|
|
var strName = "w_onehand";
|
|
var onehand = FindDeepChild(prefabAsset.transform, strName);
|
|
if (onehand == null) onehand = new GameObject(strName).transform;
|
|
onehand.parent = wristR;
|
|
onehand.localPosition = new Vector3(-0.0546f, -0.001f, -0.0271f);
|
|
onehand.localEulerAngles = new Vector3(0f, 107.83f, 0f);
|
|
onehand.localScale = Vector3.one * 0.8f;
|
|
list_tr.Add(onehand);
|
|
}
|
|
|
|
if (wristL != null)
|
|
{
|
|
var strName = "w_bladedancer_l";
|
|
var bd_l = FindDeepChild(prefabAsset.transform, strName);
|
|
if (bd_l == null) bd_l = new GameObject(strName).transform;
|
|
bd_l.parent = wristL;
|
|
bd_l.localPosition = new Vector3(0.0413f, 0.015f, 0.0255f);
|
|
bd_l.localEulerAngles = new Vector3(6.747354f, -168.0254f, 157.2563f);
|
|
bd_l.localScale = Vector3.one;
|
|
list_tr.Add(bd_l);
|
|
}
|
|
if (wristR != null)
|
|
{
|
|
var strName = "w_bladedancer_r";
|
|
var bd_r = FindDeepChild(prefabAsset.transform, strName);
|
|
if (bd_r == null) bd_r = new GameObject(strName).transform;
|
|
bd_r.parent = wristR;
|
|
bd_r.localPosition = new Vector3(-0.0546f, -0.001f, -0.0271f);
|
|
bd_r.localEulerAngles = new Vector3(0f, 107.83f, 0f);
|
|
bd_r.localScale = Vector3.one * 0.8f;
|
|
list_tr.Add(bd_r);
|
|
}
|
|
|
|
pcactor.tfs_weapon = list_tr.ToArray();
|
|
|
|
// 수정한 프리팹 저장
|
|
PrefabUtility.SaveAsPrefabAsset(prefabAsset, prefabPath);
|
|
PrefabUtility.UnloadPrefabContents(prefabAsset);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"{go.name}은(는) 프리팹 인스턴스가 아닙니다!");
|
|
}
|
|
}
|
|
}
|
|
static Transform FindDeepChild(Transform parent, string name)
|
|
{
|
|
foreach (Transform child in parent)
|
|
{
|
|
if (child.name == name)
|
|
return child;
|
|
var result = FindDeepChild(child, name);
|
|
if (result != null)
|
|
return result;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static void CommonSetting(GameObject go, int avoidancePriority)
|
|
{
|
|
var m_bc = go.GetComponent<BoxCollider>();
|
|
if (m_bc == null) m_bc = go.AddComponent<BoxCollider>();
|
|
|
|
var navmesh = go.GetComponent<NavMeshAgent>();
|
|
if (navmesh == null) navmesh = go.AddComponent<NavMeshAgent>();
|
|
navmesh.speed = 4.5f;
|
|
navmesh.angularSpeed = 300f;
|
|
navmesh.acceleration = 140f;
|
|
navmesh.stoppingDistance = 0.1f;
|
|
navmesh.autoBraking = true;
|
|
navmesh.radius = 0.25f;
|
|
navmesh.height = 2f;
|
|
navmesh.avoidancePriority = avoidancePriority;
|
|
navmesh.obstacleAvoidanceType = ObstacleAvoidanceType.GoodQualityObstacleAvoidance;
|
|
|
|
Set_CommonRigidBody(go);
|
|
|
|
var rds = go.GetComponentsInChildren<SkinnedMeshRenderer>();
|
|
SkinnedMeshRenderer m_smr = null;
|
|
if (rds.Length == 1) m_smr = rds[0];
|
|
else
|
|
{
|
|
for (int i = 0; i < rds.Length; i++)
|
|
{
|
|
if (rds[i].name.ToLower().Contains("skin"))
|
|
{
|
|
m_smr = rds[i];
|
|
break;
|
|
}
|
|
}
|
|
if (m_smr == null) m_smr = rds[0];
|
|
}
|
|
|
|
m_smr.updateWhenOffscreen = true;
|
|
|
|
objectSettingsList.Add(new ObjectSettings { m_bc = m_bc, m_smr = m_smr, tick = 10 });
|
|
|
|
EditorApplication.update += UpdateAllObjects;
|
|
}
|
|
static void Set_CommonRigidBody(GameObject go)
|
|
{
|
|
var rigidbody = go.GetComponent<Rigidbody>();
|
|
if (rigidbody == null) rigidbody = go.AddComponent<Rigidbody>();
|
|
rigidbody.useGravity = false;
|
|
rigidbody.mass = 1;
|
|
rigidbody.drag = 0;
|
|
rigidbody.angularDrag = 0.05f;
|
|
rigidbody.automaticCenterOfMass = true;
|
|
rigidbody.automaticInertiaTensor = true;
|
|
rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
|
|
rigidbody.constraints = RigidbodyConstraints.FreezeAll;
|
|
}
|
|
|
|
private static void UpdateAllObjects()
|
|
{
|
|
for (int i = objectSettingsList.Count - 1; i >= 0; i--)
|
|
{
|
|
var settings = objectSettingsList[i];
|
|
if (settings.tick < 0)
|
|
{
|
|
var bounds = settings.m_smr.bounds;
|
|
settings.m_bc.center = bounds.center;
|
|
settings.m_bc.size = bounds.size;
|
|
settings.m_smr.updateWhenOffscreen = false;
|
|
objectSettingsList.RemoveAt(i);
|
|
}
|
|
else
|
|
{
|
|
settings.tick--;
|
|
}
|
|
}
|
|
|
|
if (objectSettingsList.Count == 0)
|
|
{
|
|
EditorApplication.update -= UpdateAllObjects;
|
|
}
|
|
}
|
|
|
|
private class ObjectSettings
|
|
{
|
|
public BoxCollider m_bc;
|
|
public SkinnedMeshRenderer m_smr;
|
|
public int tick;
|
|
}
|
|
|
|
|
|
[MenuItem("Edit/FairySetting", false, -1000)]
|
|
static void FairySetting()
|
|
{
|
|
foreach (var selectedObject in Selection.objects)
|
|
{
|
|
var go = selectedObject as GameObject;
|
|
if (go == null) continue;
|
|
|
|
var fa = go.GetComponent<FairyActor>();
|
|
if (fa == null) fa = go.AddComponent<FairyActor>();
|
|
|
|
var navmesh = go.GetComponent<NavMeshAgent>();
|
|
if (navmesh == null) navmesh = go.AddComponent<NavMeshAgent>();
|
|
|
|
// NavMeshAgent 설정
|
|
navmesh.speed = 3.5f;
|
|
navmesh.angularSpeed = 120f;
|
|
navmesh.acceleration = 1000f;
|
|
navmesh.stoppingDistance = 0;
|
|
navmesh.autoBraking = false;
|
|
navmesh.radius = 0.05f;
|
|
navmesh.height = 1f;
|
|
navmesh.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;
|
|
navmesh.avoidancePriority = 51;
|
|
}
|
|
}
|
|
|
|
//[MenuItem("Edit/Find All Particle", false, -103)]
|
|
//public static void FindAllParticle()
|
|
//{
|
|
// foreach (var selection in Selection.gameObjects)
|
|
// {
|
|
// var pats = selection.transform.GetComponentsInChildren<ParticleSystem>();
|
|
// for (int i = 0; i < pats.Length; i++)
|
|
// Debug.Log(pats[i].name);
|
|
// }
|
|
//}
|
|
|
|
|
|
//[MenuItem("Ino/Test %g")]
|
|
//static void Ino_Test()
|
|
//{
|
|
// ModelImporter modelImporter = (ModelImporter)AssetImporter.GetAtPath("Assets/ResWork/Quirky Series Vol.1 [v1.3]/Arctic Vol.1/Animations/Penguin_Animations.fbx");
|
|
// for (int i = 0; i < modelImporter.clipAnimations.Length; i++)
|
|
// {
|
|
// switch(modelImporter.clipAnimations[i].name)
|
|
// {
|
|
// case "Attack":
|
|
// break;
|
|
// }
|
|
|
|
// }
|
|
//}
|
|
|
|
//[MenuItem("Ino/Test")]
|
|
//static void FindHUD()
|
|
//{
|
|
// Debug.Log("시작");
|
|
// for (int i = 0; i < Selection.gameObjects.Length; i++)
|
|
// {
|
|
// var hud = Selection.gameObjects[i].transform.Find("HUD");
|
|
// if (hud == null) Debug.Log(Selection.gameObjects[i]);
|
|
// }
|
|
// Debug.Log("끝");
|
|
//}
|
|
|
|
//[MenuItem("Ino/Bip001 to Bip002")]
|
|
//static void ChangeBip01Bip02()
|
|
//{
|
|
// var tf = Selection.activeGameObject.transform;
|
|
// ChangeName(tf);
|
|
//}
|
|
|
|
// 자식까지 포함해서 레이어를 재귀적으로 설정하는 함수
|
|
static void SetLayerRecursively(GameObject obj, string newLayer = "UI")
|
|
{
|
|
obj.layer = LayerMask.NameToLayer(newLayer);
|
|
|
|
foreach (Transform child in obj.transform)
|
|
SetLayerRecursively(child.gameObject, newLayer); // 재귀 호출로 자식까지 처리
|
|
}
|
|
|
|
[MenuItem("GameObject/UI/New Image &i")] // &i는 Alt + I를 의미
|
|
static void CreateUIImage()
|
|
{
|
|
GameObject imageObject = new GameObject("New Image", typeof(Image));
|
|
|
|
// 생성된 오브젝트에 대한 Undo 기록 추가
|
|
Undo.RegisterCreatedObjectUndo(imageObject, "New Image");
|
|
|
|
var img = imageObject.GetComponent<Image>();
|
|
img.raycastTarget = false;
|
|
img.sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/ResWork/UI/NewRes/bg/whitebg.png");
|
|
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
imageObject.transform.SetParent(Selection.activeGameObject.transform, false);
|
|
SetLayerRecursively(imageObject);
|
|
|
|
// 새로 생성된 오브젝트를 선택
|
|
Selection.activeGameObject = imageObject;
|
|
|
|
// 씬 뷰에서 해당 오브젝트에 포커스 맞추기
|
|
//SceneView.lastActiveSceneView.FrameSelected();
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/UI/Text Only &t")] // &t는 Alt + T를 의미
|
|
static void CreateUITextMeshPro()
|
|
{
|
|
GameObject textObject = new GameObject("New TMP", typeof(TextMeshProUGUI));
|
|
|
|
// 생성된 오브젝트에 대한 Undo 기록 추가
|
|
Undo.RegisterCreatedObjectUndo(textObject, "New TMP");
|
|
|
|
var tm = textObject.GetComponent<TextMeshProUGUI>();
|
|
tm.alignment = TextAlignmentOptions.Midline;
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
textObject.transform.SetParent(Selection.activeGameObject.transform, false);
|
|
SetLayerRecursively(textObject);
|
|
|
|
// 새로 생성된 오브젝트를 선택
|
|
Selection.activeGameObject = textObject;
|
|
|
|
// 씬 뷰에서 해당 오브젝트에 포커스 맞추기
|
|
//SceneView.lastActiveSceneView.FrameSelected();
|
|
}
|
|
}
|
|
[MenuItem("GameObject/UI/Text - Local &y")]
|
|
static void CreateUITextMeshProWithLocal()
|
|
{
|
|
GameObject textObject = new GameObject("Local TMP", typeof(TextMeshProUGUI));
|
|
|
|
// 생성된 오브젝트에 대한 Undo 기록 추가
|
|
Undo.RegisterCreatedObjectUndo(textObject, "Local TMP");
|
|
|
|
textObject.AddComponent<SetLocalText>();
|
|
var tm = textObject.GetComponent<TextMeshProUGUI>();
|
|
tm.alignment = TextAlignmentOptions.Midline;
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
textObject.transform.SetParent(Selection.activeGameObject.transform, false);
|
|
SetLayerRecursively(textObject);
|
|
|
|
// 새로 생성된 오브젝트를 선택
|
|
Selection.activeGameObject = textObject;
|
|
|
|
// 씬 뷰에서 해당 오브젝트에 포커스 맞추기
|
|
//SceneView.lastActiveSceneView.FrameSelected();
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/UI/Button &b")] // Alt + B: Button 생성 (Image, Button, PlayClickSound_Only 추가)
|
|
static void CreateUIButton()
|
|
{
|
|
// 버튼 오브젝트 생성 (Image, Button 컴포넌트 포함)
|
|
GameObject buttonObject = new GameObject("btn_");
|
|
|
|
// 생성된 오브젝트에 대한 Undo 기록 추가
|
|
Undo.RegisterCreatedObjectUndo(buttonObject, "btn_");
|
|
|
|
buttonObject.AddComponent<Image>().sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/ResWork/UI/NewRes/bg/whitebg.png");
|
|
buttonObject.AddComponent<Button>();
|
|
buttonObject.AddComponent<PlayClickSound_Only>();
|
|
|
|
// TextMeshPro-UGUI 생성 및 설정
|
|
GameObject textObject = new GameObject("btnName", typeof(TextMeshProUGUI));
|
|
textObject.AddComponent<SetLocalText>();
|
|
TextMeshProUGUI tmp = textObject.GetComponent<TextMeshProUGUI>();
|
|
tmp.text = "Button";
|
|
tmp.alignment = TextAlignmentOptions.Midline;
|
|
|
|
// Text 객체를 Button의 자식으로 설정
|
|
textObject.transform.SetParent(buttonObject.transform, false);
|
|
RectTransform textRect = textObject.GetComponent<RectTransform>();
|
|
textRect.anchorMin = Vector2.zero;
|
|
textRect.anchorMax = Vector2.one;
|
|
textRect.offsetMin = Vector2.zero;
|
|
textRect.offsetMax = Vector2.zero;
|
|
|
|
// 버튼 오브젝트의 부모 설정
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
buttonObject.transform.SetParent(Selection.activeGameObject.transform, false);
|
|
SetLayerRecursively(buttonObject);
|
|
|
|
// 새로 생성된 오브젝트를 선택
|
|
Selection.activeGameObject = buttonObject;
|
|
|
|
// 씬 뷰에서 해당 오브젝트에 포커스 맞추기
|
|
//SceneView.lastActiveSceneView.FrameSelected();
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/UI/My Slider &%#s")] // Alt + Shift + S: Slider 생성
|
|
static void CreateUISlider()
|
|
{
|
|
GameObject sliderObject = new GameObject("Slider_", typeof(Slider));
|
|
|
|
// 생성된 오브젝트에 대한 Undo 기록 추가
|
|
Undo.RegisterCreatedObjectUndo(sliderObject, "Slider_");
|
|
|
|
sliderObject.GetComponent<RectTransform>().sizeDelta = new Vector2(200f, 20f);
|
|
Slider slider = sliderObject.GetComponent<Slider>();
|
|
slider.value = 0.5f;
|
|
|
|
// Slider의 자식 오브젝트로 Background 이미지 추가
|
|
GameObject backgroundObject = new GameObject("Background", typeof(Image));
|
|
backgroundObject.transform.SetParent(sliderObject.transform, false);
|
|
var img = backgroundObject.GetComponent<Image>();
|
|
img.raycastTarget = false;
|
|
img.sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/ResWork/UI/NewRes/bg/whitebg.png");
|
|
RectTransform bgRect = backgroundObject.GetComponent<RectTransform>();
|
|
bgRect.anchorMin = new Vector2(0, 0);
|
|
bgRect.anchorMax = new Vector2(1, 1);
|
|
bgRect.offsetMin = new Vector2(0, 0); // Custom Stretch 적용
|
|
bgRect.offsetMax = new Vector2(0, 0); // Custom Stretch 적용
|
|
|
|
// Fill Area 오브젝트 추가
|
|
GameObject fillAreaObject = new GameObject("Fill Area", typeof(RectTransform));
|
|
fillAreaObject.transform.SetParent(sliderObject.transform, false);
|
|
RectTransform fillAreaRect = fillAreaObject.GetComponent<RectTransform>();
|
|
fillAreaRect.anchorMin = new Vector2(0, 0);
|
|
fillAreaRect.anchorMax = new Vector2(1, 1);
|
|
fillAreaRect.offsetMin = new Vector2(0, 0); // Custom Stretch 적용
|
|
fillAreaRect.offsetMax = new Vector2(0, 0); // Custom Stretch 적용
|
|
|
|
// Fill Area 자식으로 Fill 이미지 추가
|
|
GameObject fillObject = new GameObject("Fill", typeof(Image));
|
|
fillObject.transform.SetParent(fillAreaObject.transform, false);
|
|
slider.targetGraphic = fillObject.GetComponent<Image>();
|
|
slider.targetGraphic.color = Color.yellow;
|
|
slider.targetGraphic.raycastTarget = false;
|
|
(slider.targetGraphic as Image).sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/ResWork/UI/NewRes/bg/whitebg.png");
|
|
RectTransform fillRect = fillObject.GetComponent<RectTransform>();
|
|
fillRect.anchorMin = new Vector2(0, 0);
|
|
fillRect.anchorMax = new Vector2(1, 1);
|
|
fillRect.offsetMin = new Vector2(0, 0);
|
|
fillRect.offsetMax = new Vector2(0, 0); // Stretch left 적용
|
|
|
|
// Fill 이미지 설정
|
|
slider.fillRect = fillRect;
|
|
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
sliderObject.transform.SetParent(Selection.activeGameObject.transform, false);
|
|
SetLayerRecursively(sliderObject);
|
|
|
|
// 새로 생성된 오브젝트를 선택
|
|
Selection.activeGameObject = sliderObject;
|
|
|
|
// 씬 뷰에서 해당 오브젝트에 포커스 맞추기
|
|
//SceneView.lastActiveSceneView.FrameSelected();
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/UI/My CheckUI &%#c")]
|
|
static void CreateUICheck()
|
|
{
|
|
// 0. "check_" GameObject 생성
|
|
GameObject gocheck = new GameObject("check_");
|
|
|
|
// 생성된 오브젝트에 대한 Undo 기록 추가
|
|
Undo.RegisterCreatedObjectUndo(gocheck, "check_");
|
|
|
|
gocheck.AddComponent<RectTransform>();
|
|
|
|
// 1. 자식으로 크기 27x27 Image 추가
|
|
GameObject imageObject1 = new GameObject("checkbg", typeof(Image));
|
|
imageObject1.transform.SetParent(gocheck.transform, false); // gocheck의 자식으로 설정
|
|
RectTransform image1Rect = imageObject1.GetComponent<RectTransform>();
|
|
image1Rect.sizeDelta = new Vector2(27, 27); // 크기 설정
|
|
// 버튼 및 버튼음 추가
|
|
imageObject1.AddComponent<Button>();
|
|
imageObject1.AddComponent<PlayClickSound_Only>();
|
|
|
|
// 2. 1 의 자식으로 크기 39x30 Image 추가
|
|
GameObject imageObject2 = new GameObject("check", typeof(Image));
|
|
imageObject2.transform.SetParent(imageObject1.transform, false); // imageObject1의 자식으로 설정
|
|
RectTransform image2Rect = imageObject2.GetComponent<RectTransform>();
|
|
image2Rect.sizeDelta = new Vector2(39, 30); // 크기 설정
|
|
|
|
// 3. 1의 오른쪽에 1과 같은 깊이로 TMP 추가
|
|
GameObject textObject = new GameObject("checkName", typeof(TextMeshProUGUI));
|
|
textObject.AddComponent<SetLocalText>();
|
|
textObject.transform.SetParent(gocheck.transform, false); // gocheck의 자식으로 설정
|
|
RectTransform textRect = textObject.GetComponent<RectTransform>();
|
|
textRect.sizeDelta = new Vector2(100, 30); // TMP의 기본 크기 설정
|
|
textRect.anchoredPosition = new Vector2(image1Rect.sizeDelta.x + 50, 0); // Image1의 오른쪽으로 배치
|
|
|
|
TextMeshProUGUI tmp = textObject.GetComponent<TextMeshProUGUI>();
|
|
tmp.alignment = TextAlignmentOptions.MidlineLeft;
|
|
tmp.text = "체크 UI";
|
|
|
|
// 현재 선택된 오브젝트를 부모로 설정 (선택된 오브젝트가 있을 때만)
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
gocheck.transform.SetParent(Selection.activeGameObject.transform, false);
|
|
|
|
// 새로 생성된 오브젝트를 선택
|
|
Selection.activeGameObject = gocheck;
|
|
|
|
// 씬 뷰에서 해당 오브젝트에 포커스 맞추기
|
|
//SceneView.lastActiveSceneView.FrameSelected();
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/UI/My Scroll &#v")] // Alt + Shift + V 단축키
|
|
static void CreateUIScrollview()
|
|
{
|
|
// 0. "scrollview_" GameObject 생성
|
|
GameObject go_sv = new GameObject("scrollview_");
|
|
|
|
// 생성된 오브젝트에 대한 Undo 기록 추가
|
|
Undo.RegisterCreatedObjectUndo(go_sv, "scrollview_");
|
|
|
|
var img = go_sv.AddComponent<Image>();
|
|
img.sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/ResWork/UI/NewRes/bg/whitebg.png");
|
|
var sr = go_sv.AddComponent<ScrollRect>();
|
|
sr.horizontal = false;
|
|
|
|
// 1. 자식으로 Viewport 추가
|
|
GameObject go_vp = new GameObject("Viewport", typeof(Image));
|
|
go_vp.AddComponent<Mask>().showMaskGraphic = false;
|
|
go_vp.transform.SetParent(go_sv.transform, false); // 자식으로 설정
|
|
var rt_vp = go_vp.GetComponent<RectTransform>(); // 이미 추가된 RectTransform 가져오기
|
|
rt_vp.anchorMin = Vector2.zero;
|
|
rt_vp.anchorMax = Vector2.one;
|
|
rt_vp.pivot = Vector2.up;
|
|
rt_vp.offsetMin = Vector2.zero; // Left와 Bottom을 0으로 설정
|
|
rt_vp.offsetMax = Vector2.zero; // Right와 Top을 0으로 설정
|
|
var img_vp = go_vp.GetComponent<Image>();
|
|
img_vp.sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/ResWork/UI/NewRes/bg/whitebg.png");
|
|
|
|
// ScrollRect의 Viewport를 설정
|
|
sr.viewport = rt_vp;
|
|
|
|
// 2. 1의 자식으로 Content 추가
|
|
GameObject go_ct = new GameObject("Content");
|
|
go_ct.transform.SetParent(go_vp.transform, false); // Content를 Viewport의 자식으로 설정
|
|
go_ct.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; // ContentSizeFitter 설정
|
|
var rt_ct = go_ct.GetComponent<RectTransform>();
|
|
rt_ct.anchorMin = Vector2.up;
|
|
rt_ct.anchorMax = Vector2.one;
|
|
rt_ct.pivot = Vector2.up;
|
|
rt_ct.offsetMin = Vector2.zero; // Left와 Bottom을 0으로 설정
|
|
rt_ct.offsetMax = Vector2.zero; // Right와 Top을 0으로 설정
|
|
|
|
// ScrollRect의 content 설정
|
|
sr.content = rt_ct;
|
|
|
|
// 현재 선택된 오브젝트를 부모로 설정 (선택된 오브젝트가 있을 때만)
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
go_sv.transform.SetParent(Selection.activeGameObject.transform, false);
|
|
SetLayerRecursively(go_sv);
|
|
|
|
// 새로 생성된 오브젝트를 선택
|
|
Selection.activeGameObject = go_sv;
|
|
|
|
// 씬 뷰에서 해당 오브젝트에 포커스 맞추기
|
|
//SceneView.lastActiveSceneView.FrameSelected();
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/UI/TMP InputField &%#i")] // Alt + Ctrl + Shift + i 단축키
|
|
static void CreateTMPInputField()
|
|
{
|
|
// 0. GameObject 생성
|
|
GameObject go_if = new GameObject("inputfield_");
|
|
|
|
// 생성된 오브젝트에 대한 Undo 기록 추가
|
|
Undo.RegisterCreatedObjectUndo(go_if, "inputfield_");
|
|
|
|
var img = go_if.AddComponent<Image>();
|
|
img.sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/ResWork/UI/NewRes/bg/whitebg.png");
|
|
var tmp_if = go_if.AddComponent<TMP_InputField>();
|
|
var rt_if = go_if.GetComponent<RectTransform>();
|
|
rt_if.sizeDelta = new Vector2(160, 30);
|
|
|
|
// 1. 자식으로 Text Area 추가
|
|
GameObject go_vp = new GameObject("Text Area", typeof(RectMask2D));
|
|
go_vp.GetComponent<RectMask2D>().padding = new Vector4(-8, -5, -8, -5);
|
|
go_vp.transform.SetParent(go_if.transform, false); // 자식으로 설정
|
|
var rt_vp = go_vp.GetComponent<RectTransform>();
|
|
rt_vp.anchorMin = Vector2.zero;
|
|
rt_vp.anchorMax = Vector2.one;
|
|
rt_vp.pivot = Vector2.one * 0.5f;
|
|
rt_vp.offsetMin = Vector2.right * 10f; //
|
|
rt_vp.offsetMax = Vector2.zero; // Right와 Top을 0으로 설정
|
|
tmp_if.textViewport = rt_vp;
|
|
|
|
// 2. 1의 자식으로 Placeholder 추가
|
|
GameObject go_ph = new GameObject("Placeholder");
|
|
go_ph.transform.SetParent(go_vp.transform, false); // 자식으로 설정
|
|
var text_ph = go_ph.AddComponent<TextMeshProUGUI>();
|
|
text_ph.alignment = TextAlignmentOptions.MidlineLeft;
|
|
text_ph.text = "Enter text.";
|
|
text_ph.color = Color.black;
|
|
tmp_if.placeholder = text_ph;
|
|
go_ph.AddComponent<LayoutElement>().ignoreLayout = true;
|
|
var rt_ph = go_ph.GetComponent<RectTransform>();
|
|
rt_ph.anchorMin = Vector2.zero;
|
|
rt_ph.anchorMax = Vector2.one;
|
|
rt_vp.pivot = Vector2.one * 0.5f;
|
|
rt_ph.offsetMin = Vector2.zero; // Left와 Bottom을 0으로 설정
|
|
rt_ph.offsetMax = Vector2.one; // Right와 Top을 0으로 설정
|
|
|
|
// 3. 1의 자식으로 Text 추가
|
|
GameObject go_txt = new GameObject("Text");
|
|
go_txt.transform.SetParent(go_vp.transform, false); // 자식으로 설정
|
|
var text_txt = go_txt.AddComponent<TextMeshProUGUI>();
|
|
text_txt.alignment = TextAlignmentOptions.MidlineLeft;
|
|
text_txt.color = Color.black;
|
|
tmp_if.textComponent = text_txt;
|
|
tmp_if.pointSize = 20;
|
|
tmp_if.fontAsset = AssetDatabase.LoadAssetAtPath<TMP_FontAsset>("Assets/ThirdParty/TextMesh Pro/Addressables/Fonts & Materials/Font SDF.asset");
|
|
var rt_txt = go_txt.GetComponent<RectTransform>();
|
|
rt_txt.anchorMin = Vector2.zero;
|
|
rt_txt.anchorMax = Vector2.one;
|
|
rt_txt.pivot = Vector2.one * 0.5f;
|
|
rt_txt.offsetMin = Vector2.zero; // Left와 Bottom을 0으로 설정
|
|
rt_txt.offsetMax = Vector2.one; // Right와 Top을 0으로 설정
|
|
|
|
// 현재 선택된 오브젝트를 부모로 설정 (선택된 오브젝트가 있을 때만)
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
go_if.transform.SetParent(Selection.activeGameObject.transform, false);
|
|
SetLayerRecursively(go_if);
|
|
|
|
// 새로 생성된 오브젝트를 선택
|
|
Selection.activeGameObject = go_if;
|
|
|
|
// 씬 뷰에서 해당 오브젝트에 포커스 맞추기
|
|
//SceneView.lastActiveSceneView.FrameSelected();
|
|
}
|
|
}
|
|
} |