0

我创建了一个统一编辑器类,我想在其中选择我的“图块”并添加“墙”。它适用于单选,但我无法解决多选。我发现

[可以编辑多个对象]

但仅此无济于事。这是编辑器脚本:

#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
4

1 回答 1

0

解决了。targets是关键。

for(int i = 0; i < targets.Length; i++) {
    (target as SomeClass).gameObject.GetComponent<TileControl> ().addWall();
}
于 2015-10-13T20:14:09.080 回答