2016-11-02 4 views
0

Ich hatte keine Probleme beim Erstellen von benutzerdefinierten Editoren, aber mit diesem scheint es mich zu informieren "Multi-Objekt-Bearbeitung nicht unterstützt" der Code für mein Skript ist unten sowie das Skript für meinen benutzerdefinierten Editor. Gibt es etwas, das ich vermisse?Benutzerdefinierte Editor - Multi-Objekt-Bearbeitung wird nicht unterstützt

using UnityEngine; 
using UnityEngine.UI; 
using System.Collections; 
using System.Collections.Generic; 

[AddComponentMenu("Biophase Games/UI/Togglr")] 
[System.Serializable] 
public class Togglr : MonoBehaviour { 

    public List<Toggler> toggles; 

    public ColorBlock onColors; 
    public ColorBlock offColors; 

    public string value; 

    void Update() { 

     foreach(Toggler t in toggles) { 

      if (t.toggle.isOn == true) { 

       value = t.text; 

       t.toggle.colors = onColors; 

      } else { 

       t.toggle.colors = offColors; 

      } 

     } 

    } 

} 

[System.Serializable] 
public class Toggler { 

    public Toggle toggle; 
    public string text; 

} 

und das Custom Skript

using UnityEngine; 
using UnityEngine.UI; 
using UnityEditor; 
using System.Collections; 
using System.Collections.Generic; 

[CustomEditor(typeof(Togglr))] 
[CanEditMultipleObjects] 
public class TogglrEditor : Editor { 

    SerializedProperty onColors; 
    SerializedProperty offColors; 
    SerializedProperty toggles; 

    void OnEnable() { 

     onColors = serializedObject.FindProperty ("onColors"); 
     offColors = serializedObject.FindProperty ("offColors"); 
     toggles = serializedObject.FindProperty ("toggles"); 

    } 

    public override void OnInspectorGUI() { 

     serializedObject.Update(); 

     EditorGUILayout.PropertyField (toggles, true); 
     EditorGUILayout.PropertyField (onColors); 
     EditorGUILayout.PropertyField (offColors); 

     serializedObject.ApplyModifiedProperties(); 

    } 

} 

Antwort

0

Auf dem Versuch, mein Problem zu lösen, zog ich die Klasse Toggler in seiner eigenen Datei, die anschließend das Problem gelöst ich hatte.

Verwandte Themen