Exemplo n.º 1
0
        public static void DrawOutputs(XNode.Node target, SerializedObject serializedObject)
        {
            NodePort outputPort = target.GetOutputPort("output");

            serializedObject.FindProperty("outputFoldout").boolValue = EditorGUILayout.Foldout(serializedObject.FindProperty("outputFoldout").boolValue, "Outputs [" + outputPort.ConnectionCount + "]", true);
            bool outputFoldout = serializedObject.FindProperty("outputFoldout").boolValue;

            GUIStyle labelStyle  = new GUIStyle(EditorStyles.label);
            GUIStyle buttonStyle = new GUIStyle(EditorStyles.miniButton);

            labelStyle.wordWrap = true;

            if (outputFoldout)
            {
                for (int i = 0; i < outputPort.ConnectionCount; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    NodePort outputConnectionPort = outputPort.GetConnection(i);
                    Node     outputConnectionNode = outputPort.GetConnection(i).node;

                    if (outputConnectionNode is State)
                    {
                        string label = outputConnectionNode.name;
                        label = label.Replace("\n", "");
                        label = label.Substring(0, Mathf.Min(32, label.Length));
                        EditorGUILayout.LabelField(string.Format("[{0}] {1}", "Answer", label, labelStyle));
                    }

                    if (GUILayout.Button("^", GUILayout.MaxHeight(20), GUILayout.MaxWidth(20)))
                    {
                        if (i <= 0)
                        {
                            return;
                        }

                        outputPort.SwitchConnections(i, i - 1);
                    }

                    if (GUILayout.Button("v", GUILayout.MaxHeight(20), GUILayout.MaxWidth(20)))
                    {
                        if (i >= outputPort.ConnectionCount - 1)
                        {
                            return;
                        }

                        outputPort.SwitchConnections(i, i + 1);
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
        }