コード例 #1
0
 private void OnClickAddNode(Vector2 pos)
 {
     if (serializedConversation != null)
     {
         serializedConversation.Update();
         // Add DialogueEntry to serialized conversation
         SerializedProperty newEntry = SerializedConversationUtility.AddEntry(serializedConversation);
         newEntry.FindPropertyRelative("position").vector2Value = pos;
         serializedConversation.ApplyModifiedProperties();
     }
 }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Starting Entry");
            NameIDListPair popupLists = SerializedConversationUtility.GetEntryNameAndID(serializedObject, true);

            startingID.intValue = EditorGUILayout.IntPopup(startingID.intValue, popupLists.Names.ToArray(), popupLists.IDs.ToArray());
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("Speakers"), true);


            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Dialogue Entries");
            // popup to select start dialogue
            entrySelectedIndex = DialogueEntryPopup(entrySelectedIndex);

            // add/remove entries buttons
            EditorGUILayout.BeginHorizontal();
            bool addEntry = false, removeEntry = false;

            addEntry = GUILayout.Button("Add Entry");
            using (new EditorGUI.DisabledScope(entrySelectedIndex >= entries.arraySize)) //disable if index out of range
            {
                removeEntry = GUILayout.Button("Remove Entry");
            }
            EditorGUILayout.EndHorizontal();
            if (addEntry)
            {
                SerializedConversationUtility.AddEntry(serializedObject);
            }
            else if (removeEntry)
            {
                if (entrySelectedIndex < entries.arraySize)
                {
                    entries.DeleteArrayElementAtIndex(entrySelectedIndex);
                    entrySelectedIndex = Mathf.Clamp(entrySelectedIndex, 0, entries.arraySize - 1);
                }
            }

            // Show selected entry
            if (entries.arraySize != 0 && entrySelectedIndex < entries.arraySize)
            {
                selectedEntry = entries.GetArrayElementAtIndex(entrySelectedIndex);
                EditorGUILayout.PropertyField(selectedEntry, GUIContent.none, true);
            }
            else
            {
                EditorGUILayout.LabelField("No Entries");
            }
            serializedObject.ApplyModifiedProperties();
        }
コード例 #3
0
        protected override void OnClickDelete(DialogueEditorWindow window)
        {
            SerializedObject conversation = window.SerializedConversation;

            if (conversation != null)
            {
                // Delete response from conversation
                conversation.Update();
                SerializedProperty entry = SerializedConversationUtility.FindEntry(conversation, entryID);
                entry.FindPropertyRelative("Responses").DeleteArrayElementAtIndex(index);
                conversation.ApplyModifiedProperties();
            }
        }
        protected void OnClickAddResponse(DialogueEditorWindow window)
        {
            SerializedObject conversation = window.SerializedConversation;

            if (conversation != null)
            {
                conversation.Update();
                // Get serialized property for this node
                SerializedProperty serialEntry = SerializedConversationUtility.FindEntry(conversation, entryID);
                if (serialEntry != null)
                {
                    SerializedDialogueEntryUtility.AddResponse(serialEntry);
                }
                conversation.ApplyModifiedProperties();
            }
        }
コード例 #5
0
        private void DrawEditPanel()
        {
            // Begins GUI layout area for edit panel
            editPanel = new Rect((position.width * nodePanelWidth) + 5, 0, position.width * (1 - nodePanelWidth) - (RESIZER_WIDTH * 0.5f), position.height);
            GUILayout.BeginArea(editPanel);
            // Begins a Scroll View area. This takes the current scroll position and returns the new position scrolled to
            editScrollPosition = GUILayout.BeginScrollView(editScrollPosition);
            // HACK display conversation selected some other way
            EditorGUILayout.ObjectField("Conversation", conversation, typeof(Conversation), false);
            if (conversation == null)
            {
                //todo maybe say something?
            }
            else
            {
                // Draws the property for the selected node
                // As with custom inspectors, the SerializedObject representing the Conversation needs to be updated and modified
                serializedConversation.Update();

                SerializedProperty startingID = serializedConversation.FindProperty("startingID");
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Starting Entry");
                NameIDListPair popupLists = SerializedConversationUtility.GetEntryNameAndID(serializedConversation, true);
                startingID.intValue = EditorGUILayout.IntPopup(startingID.intValue, popupLists.Names.ToArray(), popupLists.IDs.ToArray());
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.PropertyField(serializedConversation.FindProperty("Speakers"), true);
                EditorGUILayout.Separator();
                // Get the property from the serializedConversation corresponding to the selected node
                SerializedProperty selectedProperty = null;
                if (selectedNode != null)
                {
                    selectedProperty = selectedNode.ContentsAsProperty(serializedConversation);
                }
                if (selectedProperty != null)
                {
                    // Displays the selected property using the appropriate custom drawer
                    EditorGUILayout.PropertyField(selectedProperty);
                }
                // End by applying any modifications to the SerializedObject
                serializedConversation.ApplyModifiedProperties();
            }
            // Close ScrollView and Area
            GUILayout.EndScrollView();
            GUILayout.EndArea();
        }
コード例 #6
0
        protected internal override bool ConnectObjectToDialogueEntry(DialogueEditorWindow window, int targetID)
        {
            SerializedObject conversation = window.SerializedConversation;
            bool             success      = false;

            if (conversation != null)
            {
                conversation.Update();
                SerializedProperty serializedEntry    = SerializedConversationUtility.FindEntry(conversation, entryID);
                SerializedProperty serializedResponse = serializedEntry.FindPropertyRelative("Responses").GetArrayElementAtIndex(index);
                SerializedProperty transitions        = serializedResponse.FindPropertyRelative("transitions.transitions");
                //TODO write some SerializedTransitionListUtility with an insert new transition function
                int oldSize = transitions.arraySize;
                transitions.InsertArrayElementAtIndex(oldSize);
                SerializedProperty newTransition = transitions.GetArrayElementAtIndex(oldSize);
                newTransition.FindPropertyRelative("condition").objectReferenceValue = null;
                newTransition.FindPropertyRelative("transition.TargetID").intValue   = targetID;
                conversation.ApplyModifiedProperties();
                success = true;
            }
            return(success);
        }