【问题标题】:editing multiple objects in gui with [CanEditMultipleObjects]使用 [CanEditMultipleObjects] 在 gui 中编辑多个对象
【发布时间】:2015-10-12 21:18:58
【问题描述】:

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

[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

【问题讨论】:

    标签: unity3d unity3d-gui


    【解决方案1】:

    解决了。 targets 是关键。

    for(int i = 0; i < targets.Length; i++) {
        (target as SomeClass).gameObject.GetComponent<TileControl> ().addWall();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多