常用一个Attribute脚本汇总,试一试就知道是什么意思。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//不可重复添加
[DisallowMultipleComponent]
//需要添加额外脚本
[RequireComponent(typeof(Animator))]
[AddComponentMenu("MyScript/GoodScript")]
//CreateAssetMenuAttribute 改属性用于ScriptableObject类。
public class GoodScript : MonoBehaviour
{
[HideInInspector]
public bool b;
[SerializeField]
private bool showPrivateBool;
[Space]
[Header("part1")]
[TextArea]
public string AreaText;
[MultilineAttribute]
public string MultilineText;
[Space(2)]
[Header("part2")]
[Range(0, 1)]
public float rangeFlaot;
[Range(0, 10)]
public int rangeInt;
[Space]
[Header("part3")]
[Tooltip("TestFloat")]
public float tooltipFloat;
[ColorUsageAttribute(true, true)]
public Color color;
//此Attribute作用于函数,组件处右键可以在Inspector中调用函数
[ContextMenu("GetIt")]
public void GetIt()
{
Debug.Log("HelloWorld");
}
[ContextMenuItem("Reset", "ResetName")]
public string name = "Default";
void ResetName()
{
name = "Default";
}
}
Attributes更多参考这个大佬