【发布时间】:2020-01-16 14:33:37
【问题描述】:
MonoBehaviour 脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class PickupObjects : MonoBehaviour
{
[SerializeField]
public List<GameObject> pickUpObjects = new List<GameObject>();
}
还有编辑器脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(PickupObjects))]
public class PickupObjectsEditor : Editor
{
[MenuItem("GameObject/Generate as Pickup Item", false, 30)]
public static void GeneratePickupItems()
{
if (Selection.gameObjects.Length > 0)
{
for (int i = 0; i < Selection.gameObjects.Length; i++)
{
if (Selection.gameObjects[i].GetComponent<TestScript>() == null)
{
Selection.gameObjects[i].AddComponent<BoxCollider>();
Selection.gameObjects[i].AddComponent<TestScript>();
}
Selection.gameObjects[i].layer = 9;
}
}
}
}
我想在循环之后的编辑器脚本中将对象添加到 MonoBehaviour 中的列表中,这样我就可以在 MonoBehaviour 脚本的列表中看到现在被拾取的对象。
【问题讨论】: