113 lines
2.8 KiB
C#
113 lines
2.8 KiB
C#
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
public class UIAutoBindRuleHelper
|
|
{
|
|
//如果新类型的插件/新的类型简称在此添加 生成注入代码
|
|
public enum AutoBindType
|
|
{
|
|
None = 0,
|
|
GameObject = 1,
|
|
Transform = 2,
|
|
Image = 3,
|
|
Button = 4,
|
|
RectTransform = 5,
|
|
Toggle = 6,
|
|
Text = 7,
|
|
Slider = 8,
|
|
Animation = 9,
|
|
Animator = 10,
|
|
RawImage = 11,
|
|
ScrollRect = 12,
|
|
Input = 13
|
|
}
|
|
|
|
public static readonly Dictionary<AutoBindType, Type> TypeDict = new()
|
|
{
|
|
{AutoBindType.None, typeof(GameObject)},
|
|
{AutoBindType.GameObject, typeof(GameObject)},
|
|
{AutoBindType.Transform, typeof(Transform)},
|
|
{AutoBindType.Image, typeof(Image)},
|
|
{AutoBindType.Button, typeof(Button)},
|
|
{AutoBindType.RectTransform, typeof(RectTransform)},
|
|
{AutoBindType.Toggle, typeof(Toggle)},
|
|
{AutoBindType.Text, typeof(Text)},
|
|
{AutoBindType.Slider, typeof(Slider)},
|
|
{AutoBindType.Animation, typeof(Animation)},
|
|
{AutoBindType.Animator, typeof(Animator)},
|
|
{AutoBindType.RawImage, typeof(RawImage)},
|
|
{AutoBindType.ScrollRect, typeof(ScrollRect)},
|
|
{AutoBindType.Input, typeof(InputField)}
|
|
};
|
|
|
|
public static readonly Dictionary<AutoBindType, string> TypeToName = new()
|
|
{
|
|
{AutoBindType.None, "none"},
|
|
{AutoBindType.GameObject, "go"},
|
|
{AutoBindType.Transform, "tran"},
|
|
{AutoBindType.Image, "img"},
|
|
{AutoBindType.Button, "btn"},
|
|
{AutoBindType.RectTransform, "rect"},
|
|
{AutoBindType.Toggle, "tog"},
|
|
{AutoBindType.Text, "text"},
|
|
{AutoBindType.Slider, "sli"},
|
|
{AutoBindType.Animation, "ani"},
|
|
{AutoBindType.Animator, "anr"},
|
|
{AutoBindType.RawImage, "raw"},
|
|
{AutoBindType.ScrollRect, "scr"},
|
|
{AutoBindType.Input, "input"}
|
|
};
|
|
|
|
/*private static string GetOptionName(AutoBindType type)
|
|
{
|
|
switch(type)
|
|
{
|
|
case AutoBindType.None:
|
|
return "None";
|
|
case AutoBindType.GameObject:
|
|
return "GameObject";
|
|
case AutoBindType.Transform:
|
|
return "Transform";
|
|
case AutoBindType.Image:
|
|
return "Image";
|
|
case AutoBindType.Button:
|
|
return "Button";
|
|
default:
|
|
return "Unknown";
|
|
}
|
|
}*/
|
|
|
|
// 动态生成下拉菜单选项
|
|
public static string[] GeneratePopupOptions()
|
|
{
|
|
string[] options = new string[Enum.GetValues(typeof(AutoBindType)).Length];
|
|
int index = 0;
|
|
foreach (AutoBindType type in Enum.GetValues(typeof(AutoBindType)))
|
|
{
|
|
// options[index++] = GetOptionName(type);
|
|
options[index++] = type.ToString();
|
|
}
|
|
|
|
return options;
|
|
}
|
|
|
|
public static string GetRuleTips()
|
|
{
|
|
StringBuilder content = new StringBuilder();
|
|
foreach (AutoBindType type in Enum.GetValues(typeof(AutoBindType)))
|
|
{
|
|
if (type.ToString() == "None")
|
|
{
|
|
continue;
|
|
}
|
|
content.Append(type.ToString());
|
|
content.Append(" => ");
|
|
content.Append(TypeToName[type]);
|
|
content.Append("\n");
|
|
}
|
|
return content.ToString();
|
|
}
|
|
} |