我已经创建了一个统一编辑器类,我想在其中选择我的" tiles"并添加" wall" s。它适用于单一选择,但我无法进行多项选择。我找到了
[CanEditMultipleObjects]
但仅此一点没有帮助。这是编辑脚本:
#if UNITY_EDITOR
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(TileMorpherMonoBehaviour))]
[CanEditMultipleObjects]
public class TileMorpher : Editor {
public override void OnInspectorGUI() {
TileControl tileControl = (target as TileMorpherMonoBehaviour).gameObject.GetComponent<TileControl> ();
if (GUILayout.Button("Add wall")) {
tileControl.addWall ();
}
if (GUILayout.Button("Remove wall")) {
tileControl.removeWall ();
}
}
}
#endif
答案 0 :(得分:0)
解决了它。 targets
是关键。
for(int i = 0; i < targets.Length; i++) {
(target as SomeClass).gameObject.GetComponent<TileControl> ().addWall();
}