源战役客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

94 linhas
3.2 KiB

#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.Collections;
public static class UIHelper{
static UISetting globalSetting = ScriptableObject.CreateInstance<UISetting>();
[MenuItem("GameObject/UI/Image")]
static void CreateImage()
{
if (Selection.activeTransform)
{
if (Selection.activeTransform.GetComponentInParent<Canvas>())
{
GameObject go = new GameObject("image", typeof(Image));
go.GetComponent<Image>().raycastTarget = false;
go.transform.SetParent(Selection.activeTransform, false);
Selection.activeGameObject = go;
}
}
}
[MenuItem("GameObject/UI/Raw Image")]
static void CreateRawImage()
{
if (Selection.activeTransform)
{
if (Selection.activeTransform.GetComponentInParent<Canvas>())
{
GameObject go = new GameObject("rawImage", typeof(RawImage));
go.GetComponent<RawImage>().raycastTarget = false;
go.transform.SetParent(Selection.activeTransform, false);
Selection.activeGameObject = go;
}
}
}
[MenuItem("GameObject/UI/Text")]
static void CreateText()
{
if (Selection.activeTransform)
{
if (Selection.activeTransform.GetComponentInParent<Canvas>())
{
GameObject go = new GameObject("text", typeof(Text));
go.GetComponent<Text>().raycastTarget = false;
go.transform.SetParent(Selection.activeTransform, false);
go.transform.localPosition = Vector3.zero;
Selection.activeGameObject = go;
}
}
}
[MenuItem("GameObject/UI/CustomText")]
static void CreateCustomText() {
if (Selection.activeTransform)
{
if (Selection.activeTransform.GetComponentInParent<Canvas>())
{
GameObject go = new GameObject("text", typeof(Text));
Text txt = go.GetComponent<Text>();
txt.raycastTarget = false;
txt.alignment = TextAnchor.MiddleCenter;
txt.fontSize = 20;
txt.horizontalOverflow = HorizontalWrapMode.Overflow;
if (globalSetting.defaultFont != null) txt.font = globalSetting.defaultFont;
go.transform.SetParent(Selection.activeTransform, false);
Selection.activeGameObject = go;
}
}
}
[MenuItem("GameObject/UI/Text - TextMeshPro")]
static void CreateTextMeshProUGUI() {
if (Selection.activeTransform)
{
if (Selection.activeTransform.GetComponentInParent<Canvas>())
{
GameObject go = new GameObject("tmptext", typeof(TMPro.TextMeshProUGUI));
TMPro.TextMeshProUGUI tmp = go.GetComponent<TMPro.TextMeshProUGUI>();
tmp.raycastTarget = false;
tmp.enableKerning = false;
tmp.enableWordWrapping = false;
go.transform.SetParent(Selection.activeTransform, false);
Selection.activeGameObject = go;
}
}
}
}
#endif