1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| [CustomNodeEditor(typeof(DialogueNode))] public class DialogueNodeEditor : NodeEditor { DialogueNode node; DialogueGraph dialogGraph; NodePort before, after;
public override void OnCreate() { base.OnCreate(); node = serializedObject.targetObject as DialogueNode; }
public override void OnBodyGUI() { NodeEditorGUILayout.DynamicPortList("dialogueList", typeof(DialogueInfo), serializedObject, IO.Output, ConnectionType.Override, TypeConstraint.Inherited, InitList); }
void InitList(ReorderableList list) { int reorderableListIndex = -1; SerializedProperty arrayData = serializedObject.FindProperty("dialogueList"); if (dialogGraph == null) dialogGraph = window.graph as DialogueGraph;
list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { SerializedProperty itemData = arrayData.GetArrayElementAtIndex(index), sprite = itemData.FindPropertyRelative("sprite"), person = itemData.FindPropertyRelative("person"), type = itemData.FindPropertyRelative("type"), context = itemData.FindPropertyRelative("context");
float padding = 5f, labelWidth = 50f, enumWidth = 60f, imageX = rect.x + padding; float imageWidth = 50f, y = rect.y + padding, fieldHeight = EditorGUIUtility.singleLineHeight;
Rect imageRect = new Rect(imageX, y, imageWidth, imageWidth); sprite.objectReferenceValue = EditorGUI.ObjectField(imageRect, sprite.objectReferenceValue, typeof(Sprite), false);
float contentStartX = imageX + imageWidth + padding;
Rect personLabelRect = new Rect(contentStartX, y, labelWidth, fieldHeight); EditorGUI.LabelField(personLabelRect, "Person");
Rect personFieldRect = new Rect(contentStartX + labelWidth, y, enumWidth, fieldHeight); person.intValue = EditorGUI.Popup(personFieldRect, person.intValue, dialogGraph.names.ToArray());
Rect typeLabelRect = new Rect(contentStartX + labelWidth + enumWidth + padding, y, labelWidth, fieldHeight); EditorGUI.LabelField(typeLabelRect, "Type");
Rect typeFieldRect = new Rect(contentStartX + labelWidth + enumWidth + padding + labelWidth, y, enumWidth, fieldHeight); type.enumValueIndex = (int)(PortType)EditorGUI.EnumPopup(typeFieldRect, (PortType)type.enumValueIndex);
y += fieldHeight + padding; Rect contextLabelRect = new Rect(contentStartX, y, labelWidth, fieldHeight); EditorGUI.LabelField(contextLabelRect, "Context");
Rect contextFieldRect = new Rect(contentStartX + labelWidth, y, rect.width - labelWidth - 2 * padding - imageWidth, 1.5f * fieldHeight); context.stringValue = EditorGUI.TextArea(contextFieldRect, context.stringValue, EditorStyles.wordWrappedLabel);
NodePort port = node.GetPort("inList " + index); if (port != null && (type.enumValueIndex & (int)DialogueNode.PortType.Input) != 0) { Vector2 portPosition = rect.position + new Vector2(-35, EditorGUIUtility.singleLineHeight * 1.2f); NodeEditorGUILayout.PortField(portPosition, port); } port = node.GetPort("dialogueList " + index);
if (port != null && (type.enumValueIndex & (int)DialogueNode.PortType.Output) != 0) { Vector2 portPosition = rect.position + new Vector2(rect.width + 6, EditorGUIUtility.singleLineHeight * 1.2f); NodeEditorGUILayout.PortField(portPosition, port); }
serializedObject.ApplyModifiedProperties(); serializedObject.Update(); }; } }
|