2016-11-02 177 views
0

我以前沒有創建自定義編輯器的問題,但是在使用此編輯器時,它似乎在通知我「我的腳本的代碼不支持多對象編輯」,以及我的自定義編輯器的腳本。有什麼我失蹤了嗎?自定義編輯器 - 不支持多對象編輯

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; 

} 

和CustomEditor腳本

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(); 

    } 

} 

回答

0

在試圖解決我的問題,我搬到類Toggler到它自己的文件,該文件隨後解決我遇到的問題。