com.alicizax.unity.ui.exten.../Editor/MenuExtension/MenuExtension.cs

38 lines
1.7 KiB
C#
Raw Normal View History

2025-04-02 21:03:59 +08:00
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
namespace AlicizaX.UI.Extension.Editor
{
internal static class MenuExtension
{
2025-05-30 10:32:08 +08:00
[MenuItem("GameObject/UX/UXTextMeshPro", false, -1)]
private static void CreateUxTextMeshProUx()
2025-04-02 21:03:59 +08:00
{
GameObject selectionObject = Selection.activeGameObject;
var gameObject = new GameObject("UXTextMeshPro", typeof(UXTextMeshPro));
gameObject.transform.SetParent(selectionObject.transform);
2025-04-02 21:25:09 +08:00
var rectTransform = gameObject.GetComponent<RectTransform>();
var uxTextMeshPro = gameObject.GetComponent<UXTextMeshPro>();
2025-05-30 10:32:08 +08:00
uxTextMeshPro.text = "UXTextMeshPro";
2025-04-02 21:25:09 +08:00
rectTransform.anchoredPosition = Vector2.zero;
rectTransform.localPosition = Vector3.zero;
rectTransform.pivot = new Vector2(0.5f, 0.5f);
rectTransform.localScale = Vector3.one;
Selection.activeGameObject = gameObject;
2025-04-02 21:03:59 +08:00
}
2025-05-30 10:32:08 +08:00
[MenuItem("GameObject/UX/RecyclerView", false, -1)]
private static void CreateUxRecyclerView()
{
GameObject selectionObject = Selection.activeGameObject;
if (selectionObject == null) return;
const string prefabPath = "Packages/com.alicizax.unity.ui.extension/Editor/RecyclerView/Res/ScrollView.prefab";
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
GameObject instance = (GameObject)PrefabUtility.InstantiatePrefab(prefab, selectionObject.transform);
PrefabUtility.UnpackPrefabInstance(instance, PrefabUnpackMode.Completely, InteractionMode.UserAction);
Selection.activeGameObject = instance;
}
2025-04-02 21:03:59 +08:00
}
}