706 lines
28 KiB
C#
706 lines
28 KiB
C#
using System.Collections.Generic;
|
||
using System.IO;
|
||
using TMPro;
|
||
using UnityEditor;
|
||
using UnityEditor.AddressableAssets.Settings;
|
||
using UnityEngine;
|
||
using UnityEngine.AI;
|
||
using UnityEngine.UI;
|
||
|
||
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()
|
||
{ // ì„¤ì •ë<E280A2>œ 몹 프리팹ì<C2B9>„ ì§€ìš°ê³ ëª¹ ë<>°ì<C2B0>´í„°ë§Œ 남긴다. 해당 ë<>°ì<C2B0>´í„°ë¡œ 게임 ë‚´ì—<C3AC>서 몹ì<C2B9>„ ë<>™ì <C3AC> 로딩한다.
|
||
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()
|
||
{ // 메쉬 ë Œë<C592>”러를 찾아서 최ì <C3AC>í™” 한다.
|
||
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("메시 최ì <C3AC>í™”", "완료", "알았다");
|
||
}
|
||
}
|
||
|
||
[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>();
|
||
|
||
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);
|
||
}
|
||
}
|
||
|
||
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;
|
||
|
||
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;
|
||
|
||
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;
|
||
}
|
||
|
||
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("ë<><C3AB>");
|
||
//}
|
||
|
||
//[MenuItem("Ino/Bip001 to Bip002")]
|
||
//static void ChangeBip01Bip02()
|
||
//{
|
||
// var tf = Selection.activeGameObject.transform;
|
||
// ChangeName(tf);
|
||
//}
|
||
|
||
// ìž<C3AC>ì‹<C3AC>까지 í<>¬í•¨í•´ì„œ ë ˆì<CB86>´ì–´ë¥¼ 재귀ì <C3AC>으로 ì„¤ì •í•˜ëŠ” 함수
|
||
static void SetLayerRecursively(GameObject obj, string newLayer = "UI")
|
||
{
|
||
obj.layer = LayerMask.NameToLayer(newLayer);
|
||
|
||
foreach (Transform child in obj.transform)
|
||
SetLayerRecursively(child.gameObject, newLayer); // 재귀 호출로 ìž<C3AC>ì‹<C3AC>까지 처리
|
||
}
|
||
|
||
[MenuItem("GameObject/UI/New Image &i")] // &i는 Alt + I를 ì<>˜ë¯¸
|
||
static void CreateUIImage()
|
||
{
|
||
GameObject imageObject = new GameObject("New Image", typeof(Image));
|
||
|
||
// ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트ì—<C3AC> 대한 Undo 기ë¡<C3AB> 추가
|
||
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);
|
||
|
||
// 새로 ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트를 ì„ íƒ<C3AD>
|
||
Selection.activeGameObject = imageObject;
|
||
|
||
// 씬 ë·°ì—<C3AC>서 해당 오브ì <C3AC>트ì—<C3AC> í<>¬ì»¤ìФ 맞추기
|
||
//SceneView.lastActiveSceneView.FrameSelected();
|
||
}
|
||
}
|
||
|
||
[MenuItem("GameObject/UI/Text Only &t")] // &t는 Alt + T를 ì<>˜ë¯¸
|
||
static void CreateUITextMeshPro()
|
||
{
|
||
GameObject textObject = new GameObject("New TMP", typeof(TextMeshProUGUI));
|
||
|
||
// ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트ì—<C3AC> 대한 Undo 기ë¡<C3AB> 추가
|
||
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);
|
||
|
||
// 새로 ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트를 ì„ íƒ<C3AD>
|
||
Selection.activeGameObject = textObject;
|
||
|
||
// 씬 ë·°ì—<C3AC>서 해당 오브ì <C3AC>트ì—<C3AC> í<>¬ì»¤ìФ 맞추기
|
||
//SceneView.lastActiveSceneView.FrameSelected();
|
||
}
|
||
}
|
||
[MenuItem("GameObject/UI/Text - Local &y")]
|
||
static void CreateUITextMeshProWithLocal()
|
||
{
|
||
GameObject textObject = new GameObject("Local TMP", typeof(TextMeshProUGUI));
|
||
|
||
// ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트ì—<C3AC> 대한 Undo 기ë¡<C3AB> 추가
|
||
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);
|
||
|
||
// 새로 ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트를 ì„ íƒ<C3AD>
|
||
Selection.activeGameObject = textObject;
|
||
|
||
// 씬 ë·°ì—<C3AC>서 해당 오브ì <C3AC>트ì—<C3AC> í<>¬ì»¤ìФ 맞추기
|
||
//SceneView.lastActiveSceneView.FrameSelected();
|
||
}
|
||
}
|
||
|
||
[MenuItem("GameObject/UI/Button &b")] // Alt + B: Button ìƒ<C3AC>성 (Image, Button, PlayClickSound_Only 추가)
|
||
static void CreateUIButton()
|
||
{
|
||
// 버튼 오브ì <C3AC>트 ìƒ<C3AC>성 (Image, Button ì»´í<C2B4>¬ë„ŒíЏ í<>¬í•¨)
|
||
GameObject buttonObject = new GameObject("btn_");
|
||
|
||
// ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트ì—<C3AC> 대한 Undo 기ë¡<C3AB> 추가
|
||
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 ìƒ<C3AC>성 ë°<C3AB> ì„¤ì •
|
||
GameObject textObject = new GameObject("btnName", typeof(TextMeshProUGUI));
|
||
textObject.AddComponent<SetLocalText>();
|
||
TextMeshProUGUI tmp = textObject.GetComponent<TextMeshProUGUI>();
|
||
tmp.text = "Button";
|
||
tmp.alignment = TextAlignmentOptions.Midline;
|
||
|
||
// Text ê°<C3AA>체를 Buttonì<6E>˜ ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
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;
|
||
|
||
// 버튼 오브ì <C3AC>트ì<C2B8>˜ 부모 ì„¤ì •
|
||
if (Selection.activeGameObject != null)
|
||
{
|
||
buttonObject.transform.SetParent(Selection.activeGameObject.transform, false);
|
||
SetLayerRecursively(buttonObject);
|
||
|
||
// 새로 ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트를 ì„ íƒ<C3AD>
|
||
Selection.activeGameObject = buttonObject;
|
||
|
||
// 씬 ë·°ì—<C3AC>서 해당 오브ì <C3AC>트ì—<C3AC> í<>¬ì»¤ìФ 맞추기
|
||
//SceneView.lastActiveSceneView.FrameSelected();
|
||
}
|
||
}
|
||
|
||
[MenuItem("GameObject/UI/My Slider &%#s")] // Alt + Shift + S: Slider ìƒ<C3AC>성
|
||
static void CreateUISlider()
|
||
{
|
||
GameObject sliderObject = new GameObject("Slider_", typeof(Slider));
|
||
|
||
// ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트ì—<C3AC> 대한 Undo 기ë¡<C3AB> 추가
|
||
Undo.RegisterCreatedObjectUndo(sliderObject, "Slider_");
|
||
|
||
sliderObject.GetComponent<RectTransform>().sizeDelta = new Vector2(200f, 20f);
|
||
Slider slider = sliderObject.GetComponent<Slider>();
|
||
slider.value = 0.5f;
|
||
|
||
// Sliderì<72>˜ ìž<C3AC>ì‹<C3AC> 오브ì <C3AC>트로 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 ì <C3AC>ìš©
|
||
bgRect.offsetMax = new Vector2(0, 0); // Custom Stretch ì <C3AC>ìš©
|
||
|
||
// Fill Area 오브ì <C3AC>트 추가
|
||
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 ì <C3AC>ìš©
|
||
fillAreaRect.offsetMax = new Vector2(0, 0); // Custom Stretch ì <C3AC>ìš©
|
||
|
||
// Fill Area ìž<C3AC>ì‹<C3AC>으로 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 ì <C3AC>ìš©
|
||
|
||
// Fill ì<>´ë¯¸ì§€ ì„¤ì •
|
||
slider.fillRect = fillRect;
|
||
|
||
if (Selection.activeGameObject != null)
|
||
{
|
||
sliderObject.transform.SetParent(Selection.activeGameObject.transform, false);
|
||
SetLayerRecursively(sliderObject);
|
||
|
||
// 새로 ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트를 ì„ íƒ<C3AD>
|
||
Selection.activeGameObject = sliderObject;
|
||
|
||
// 씬 ë·°ì—<C3AC>서 해당 오브ì <C3AC>트ì—<C3AC> í<>¬ì»¤ìФ 맞추기
|
||
//SceneView.lastActiveSceneView.FrameSelected();
|
||
}
|
||
}
|
||
|
||
[MenuItem("GameObject/UI/My CheckUI &%#c")]
|
||
static void CreateUICheck()
|
||
{
|
||
// 0. "check_" GameObject ìƒ<C3AC>성
|
||
GameObject gocheck = new GameObject("check_");
|
||
|
||
// ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트ì—<C3AC> 대한 Undo 기ë¡<C3AB> 추가
|
||
Undo.RegisterCreatedObjectUndo(gocheck, "check_");
|
||
|
||
gocheck.AddComponent<RectTransform>();
|
||
|
||
// 1. ìž<C3AC>ì‹<C3AC>으로 í<>¬ê¸° 27x27 Image 추가
|
||
GameObject imageObject1 = new GameObject("checkbg", typeof(Image));
|
||
imageObject1.transform.SetParent(gocheck.transform, false); // gocheckì<6B>˜ ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
RectTransform image1Rect = imageObject1.GetComponent<RectTransform>();
|
||
image1Rect.sizeDelta = new Vector2(27, 27); // í<>¬ê¸° ì„¤ì •
|
||
// 버튼 ë°<C3AB> 버튼ì<C2BC>Œ 추가
|
||
imageObject1.AddComponent<Button>();
|
||
imageObject1.AddComponent<PlayClickSound_Only>();
|
||
|
||
// 2. 1 ì<>˜ ìž<C3AC>ì‹<C3AC>으로 í<>¬ê¸° 39x30 Image 추가
|
||
GameObject imageObject2 = new GameObject("check", typeof(Image));
|
||
imageObject2.transform.SetParent(imageObject1.transform, false); // imageObject1ì<31>˜ ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
RectTransform image2Rect = imageObject2.GetComponent<RectTransform>();
|
||
image2Rect.sizeDelta = new Vector2(39, 30); // í<>¬ê¸° ì„¤ì •
|
||
|
||
// 3. 1ì<31>˜ 오른쪽ì—<C3AC> 1ê³¼ ê°™ì<E284A2>€ 깊ì<C5A0>´ë¡œ TMP 추가
|
||
GameObject textObject = new GameObject("checkName", typeof(TextMeshProUGUI));
|
||
textObject.AddComponent<SetLocalText>();
|
||
textObject.transform.SetParent(gocheck.transform, false); // gocheckì<6B>˜ ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
RectTransform textRect = textObject.GetComponent<RectTransform>();
|
||
textRect.sizeDelta = new Vector2(100, 30); // TMPì<50>˜ 기본 í<>¬ê¸° ì„¤ì •
|
||
textRect.anchoredPosition = new Vector2(image1Rect.sizeDelta.x + 50, 0); // Image1ì<31>˜ 오른쪽으로 배치
|
||
|
||
TextMeshProUGUI tmp = textObject.GetComponent<TextMeshProUGUI>();
|
||
tmp.alignment = TextAlignmentOptions.MidlineLeft;
|
||
tmp.text = "ì²´í<C2B4>¬ UI";
|
||
|
||
// 현재 ì„ íƒ<C3AD>ë<EFBFBD>œ 오브ì <C3AC>트를 부모로 ì„¤ì • (ì„ íƒ<C3AD>ë<EFBFBD>œ 오브ì <C3AC>트가 있ì<CB86>„ 때만)
|
||
if (Selection.activeGameObject != null)
|
||
{
|
||
gocheck.transform.SetParent(Selection.activeGameObject.transform, false);
|
||
|
||
// 새로 ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트를 ì„ íƒ<C3AD>
|
||
Selection.activeGameObject = gocheck;
|
||
|
||
// 씬 ë·°ì—<C3AC>서 해당 오브ì <C3AC>트ì—<C3AC> í<>¬ì»¤ìФ 맞추기
|
||
//SceneView.lastActiveSceneView.FrameSelected();
|
||
}
|
||
}
|
||
|
||
[MenuItem("GameObject/UI/My Scroll &#v")] // Alt + Shift + V 단축키
|
||
static void CreateUIScrollview()
|
||
{
|
||
// 0. "scrollview_" GameObject ìƒ<C3AC>성
|
||
GameObject go_sv = new GameObject("scrollview_");
|
||
|
||
// ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트ì—<C3AC> 대한 Undo 기ë¡<C3AB> 추가
|
||
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. ìž<C3AC>ì‹<C3AC>으로 Viewport 추가
|
||
GameObject go_vp = new GameObject("Viewport", typeof(Image));
|
||
go_vp.AddComponent<Mask>().showMaskGraphic = false;
|
||
go_vp.transform.SetParent(go_sv.transform, false); // ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
var rt_vp = go_vp.GetComponent<RectTransform>(); // ì<>´ë¯¸ 추가ë<E282AC>œ RectTransform ê°€ì ¸ì˜¤ê¸°
|
||
rt_vp.anchorMin = Vector2.zero;
|
||
rt_vp.anchorMax = Vector2.one;
|
||
rt_vp.pivot = Vector2.up;
|
||
rt_vp.offsetMin = Vector2.zero; // Left와 Bottomì<6D>„ 0으로 ì„¤ì •
|
||
rt_vp.offsetMax = Vector2.zero; // Right와 Topì<70>„ 0으로 ì„¤ì •
|
||
var img_vp = go_vp.GetComponent<Image>();
|
||
img_vp.sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/ResWork/UI/NewRes/bg/whitebg.png");
|
||
|
||
// ScrollRectì<74>˜ Viewport를 ì„¤ì •
|
||
sr.viewport = rt_vp;
|
||
|
||
// 2. 1ì<31>˜ ìž<C3AC>ì‹<C3AC>으로 Content 추가
|
||
GameObject go_ct = new GameObject("Content");
|
||
go_ct.transform.SetParent(go_vp.transform, false); // Content를 Viewportì<74>˜ ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
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ì<6D>„ 0으로 ì„¤ì •
|
||
rt_ct.offsetMax = Vector2.zero; // Right와 Topì<70>„ 0으로 ì„¤ì •
|
||
|
||
// ScrollRectì<74>˜ content ì„¤ì •
|
||
sr.content = rt_ct;
|
||
|
||
// 현재 ì„ íƒ<C3AD>ë<EFBFBD>œ 오브ì <C3AC>트를 부모로 ì„¤ì • (ì„ íƒ<C3AD>ë<EFBFBD>œ 오브ì <C3AC>트가 있ì<CB86>„ 때만)
|
||
if (Selection.activeGameObject != null)
|
||
{
|
||
go_sv.transform.SetParent(Selection.activeGameObject.transform, false);
|
||
SetLayerRecursively(go_sv);
|
||
|
||
// 새로 ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트를 ì„ íƒ<C3AD>
|
||
Selection.activeGameObject = go_sv;
|
||
|
||
// 씬 ë·°ì—<C3AC>서 해당 오브ì <C3AC>트ì—<C3AC> í<>¬ì»¤ìФ 맞추기
|
||
//SceneView.lastActiveSceneView.FrameSelected();
|
||
}
|
||
}
|
||
|
||
[MenuItem("GameObject/UI/TMP InputField &%#i")] // Alt + Ctrl + Shift + i 단축키
|
||
static void CreateTMPInputField()
|
||
{
|
||
// 0. GameObject ìƒ<C3AC>성
|
||
GameObject go_if = new GameObject("inputfield_");
|
||
|
||
// ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트ì—<C3AC> 대한 Undo 기ë¡<C3AB> 추가
|
||
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. ìž<C3AC>ì‹<C3AC>으로 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); // ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
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ì<70>„ 0으로 ì„¤ì •
|
||
tmp_if.textViewport = rt_vp;
|
||
|
||
// 2. 1ì<31>˜ ìž<C3AC>ì‹<C3AC>으로 Placeholder 추가
|
||
GameObject go_ph = new GameObject("Placeholder");
|
||
go_ph.transform.SetParent(go_vp.transform, false); // ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
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ì<6D>„ 0으로 ì„¤ì •
|
||
rt_ph.offsetMax = Vector2.one; // Right와 Topì<70>„ 0으로 ì„¤ì •
|
||
|
||
// 3. 1ì<31>˜ ìž<C3AC>ì‹<C3AC>으로 Text 추가
|
||
GameObject go_txt = new GameObject("Text");
|
||
go_txt.transform.SetParent(go_vp.transform, false); // ìž<C3AC>ì‹<C3AC>으로 ì„¤ì •
|
||
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ì<6D>„ 0으로 ì„¤ì •
|
||
rt_txt.offsetMax = Vector2.one; // Right와 Topì<70>„ 0으로 ì„¤ì •
|
||
|
||
// 현재 ì„ íƒ<C3AD>ë<EFBFBD>œ 오브ì <C3AC>트를 부모로 ì„¤ì • (ì„ íƒ<C3AD>ë<EFBFBD>œ 오브ì <C3AC>트가 있ì<CB86>„ 때만)
|
||
if (Selection.activeGameObject != null)
|
||
{
|
||
go_if.transform.SetParent(Selection.activeGameObject.transform, false);
|
||
SetLayerRecursively(go_if);
|
||
|
||
// 새로 ìƒ<C3AC>성ë<C2B1>œ 오브ì <C3AC>트를 ì„ íƒ<C3AD>
|
||
Selection.activeGameObject = go_if;
|
||
|
||
// 씬 ë·°ì—<C3AC>서 해당 오브ì <C3AC>트ì—<C3AC> í<>¬ì»¤ìФ 맞추기
|
||
//SceneView.lastActiveSceneView.FrameSelected();
|
||
}
|
||
}
|
||
} |