0

I've created a unity Editor class, where I want to select my "tiles" and add "wall"s to it. It works for single selection, but I can't work it out for multiple selection. I found

[CanEditMultipleObjects]

but that alone won't help. Here's the Editor script:

#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
csomakk
  • 5,369
  • 1
  • 29
  • 34

1 Answers1

0

solved it. targets is the key.

for(int i = 0; i < targets.Length; i++) {
    (target as SomeClass).gameObject.GetComponent<TileControl> ().addWall();
}
csomakk
  • 5,369
  • 1
  • 29
  • 34