1

たとえば、次のMonoBehaviour派生クラスがありFooます。

class Foo : MonoBehaviour {
   public Button lastButton; 
   public Image []images;
}

[CustomEditor(typeof(Foo))]
class FooEditor : Editor {

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        Foo foo = (Foo)target;
        if(GUILayout.Button("Bind last Button and all Images")) {
           /* how to bind programatically last foo.GetComponentsInChildren<Button>(); 
              to foo.gameObject.scene's 
                 foo.gameObject.GetComponent<Foo>().lastButton 
              in edit mode's property window 
                 (without have to drag on the editor)?
           */
           /* and how to bind programatically all foo.GetComponentsInChildren<Image>(); 
              to foo.gameObject.scene's 
                 foo.gameObject.GetComponent<Foo>().images 
              in edit mode's property window 
                 (without have to drag all one by one)?
           */
        }
    }
}

バインディングを 1 つずつドラッグしたり、実行時に実行したりせずに自動化したいのですが、プログラムで行うにはどうすればよいですか?

私が考えることができる唯一の回避策 (そのような API がない場合) は、シーンを保存し、シーンのyamlを解析してから、yaml ファイルのバインディングを更新し、UnityEditor に強制的に yaml をリロードさせることですが、それが機能するかどうかはわかりません。yaml を読み込んで書き換えても等しい値が得られない

4

1 に答える 1