代码如下
public class OpenInspector : MonoBehaviour
{
[MenuItem("GameObject/AutoSelect")]
//必须是静态方法
public static void Start()
{
GameObject go = GameObject.Find("Cube");
//将要选中的物体标示一下
EditorGUIUtility.PingObject(go);
//显示物体的inspector面板
Selection.activeGameObject = go;
}
}