我之前没有创建自定义编辑器的问题,但是有了这个,它似乎通知我"不支持多对象编辑"我的脚本的代码如下,以及我的自定义编辑器的脚本。我有什么遗失的东西吗?
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 :(得分:1)
在尝试解决我的问题时,我将Toggler类移到了自己的文件中,随后解决了我遇到的问题。