美文网首页
实用面板

实用面板

作者: 混世小码农 | 来源:发表于2022-11-16 11:44 被阅读0次

    using UnityEngine;

    using System.Collections;

    using UnityEngine.UI;

    //自动添加组件

    [RequireComponent(typeof(PlayerSave))]

    //在 Add Component 按钮中增加一个菜单项

    [AddComponentMenu("Transform/Follow Transform")]

    //在 Create 菜单中,增加一个菜单项,前提条件是:该脚本继承自ScriptableObject

    [CreateAssetMenu(fileName = "New AttributeTest File", menuName = "AttributeTest", order =1)]

    //限制同一个GameObject只能有一个该组件(脚本)

    [DisallowMultipleComponent]

    //编辑器的编辑模式下,在Update、OnGUI、 OnRenderObject时会执行

    [ExecuteInEditMode]

    //自定义组件右上角?图标的链接

    [HelpURL("http://fengyu.name/")]

    //如果该组件继承自 MonoBehaviour,则必须有一个 BoxCollider 组件同时存在

    [RequireComponent(typeof(BoxCollider))]

    //没发现任何改变

    [SelectionBase]

    //只有在该组件继承自 StateMachineBehaviour 时有效,具体作用未知

    [SharedBetweenAnimators]

    public class AttributeTest : MonoBehaviour

    {

    //将一个字段变为颜色原则

    [ColorUsage(true)]

    public Color color;

    //脚本管理的地方增加一个菜单

    [ContextMenu("Do Something")]

    void DoSomething()

    {

    Debug.Log("Perform operation");

    }

    //字段名称处,增加一个右键菜单。第一个参数为菜单名称,第二个参数为功能的函数名

    [ContextMenuItem("Reset", "ResetBiography")]

    [Multiline(2)]

    public string playerBiography = "";

    void ResetBiography()

    {

    playerBiography = "";

    }

    //该值,只有在点击Enter键、丢失焦点时才会被返回

    [Delayed]

    public float delay;

    //没有发现产生的影响

    [GUITarget(0, 1)]

    void OnGUI()

    {

    GUI.Label(new Rect(10, 10, 300, 100), "Visible on TV and Wii U GamePad only");

    }

    //用于增加一个标题头

    [Header("Header之后的部分")]

    public string header;

    //会在 Inspector 中隐藏字段

    [HideInInspector]

    public string hide;

    //创建一个显示3行的文本框

    [Multiline(3)]

    public string multiline;

    //使值变成滑动条的方式,并限制大小

    [Range(0, 10)]

    public float range;

    //加载时初始化运行函数

    [RuntimeInitializeOnLoadMethod]

    static void OnRuntimeMethodLoad()

    {

    Debug.Log("After scene is loaded and game is running");

    }

    //可以序列化私有字段,让 private 也在 Inspector 中显示

    [SerializeField]

    private string serializeField;

    //创造一个高度为10的空白区域,可以用做分割线,高度单位估计是像素

    [Space(10)]

    public string space;

    //创建一个文本区域,文本区域会单独一行存在

    [TextArea]

    public string textArea;

    //当字段获得焦点后,鼠标指向字段,会获得的提示信息

    [TooltipAttribute("这是这个字段的提示信息")]

    public string toolTip;

    }

    相关文章

      网友评论

          本文标题:实用面板

          本文链接:https://www.haomeiwen.com/subject/mjtqgktx.html