using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.Events;
//写在类前的
[RequireComponent(typeof(BoxCollider))]//添加对另一个组件的依赖,如果这个GameObject不含有依赖的Component,会自动添加该Component,且Component不可被移除
[AddComponentMenu("TestMenu/TestComponnet")] //在组件选项中添加一个菜单
[DisallowMultipleComponent]//同一物体,该脚本只允许 添加一次
public class Inspectortt : MonoBehaviour {
}
[HideInInspector]//隐藏一个public,无法在属性面板显示
public string A;
[SerializeField]
private string B;//强制序列化:即强制在编辑器属性栏显示
[MultilineAttribute]//只能在string类型上使用,可以在Editor上输入多行文字
public string mText;
[TextArea]// 该属性可以把string在Inspector上的编辑区,添加滑动条。
public string Text;
[Title("标题")]
public GameObject title;
[Header("参数")]
[Tooltip("物体1")]//悬浮提示
public GameObject obj1;
[Tooltip("物体2"), SerializeField]
private GameObject obj2;
[Space]//换行
public int 变量;
[Space]
public int 变量2;
[Range(1, 100)]
public float a;
[ContextMenu("TestVoid")]//在该组件设置选项中添加一个选项
void TestVoid()
{
Debug.Log("testvoid");
}
[ContextMenuItem("000", "111")] //给变量名添加一个右键菜单选项:Cut Copy Paste
public string Str = "Default";
void TestVoid2()
{
Str = "Default";
}
public Test test;
[Range(0, 100)]
public int value;
[Serializable]
public class Test {
public GameObject A;
public Transform B;
public float C;
}
void Start()
{
Debug.Log(mText);
onUpEvent.AddListener(OnUpCallBack);
}
public Up onUpEvent;
public void OnUpCallBack(KeyCode key)
{
Debug.Log("我按下了" + key + "键");
}
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
onUpEvent?.Invoke(KeyCode.W);
//等效于
if (onUpEvent != null)
onUpEvent.Invoke(KeyCode.W);
}
}
[Serializable]
public class Up : UnityEvent<KeyCode> { }
}