- Home /
How can I get the SerializedObject and FineProperty also the node tree childs of conversations ?
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
public class ConversationsEditorWindow : EditorWindow
{
const int TOP_PADDING = 2;
const string HELP_TEXT = "Can not find 'Conversation' component on any GameObject in the Scene.";
static Vector2 s_WindowsMinSize = Vector2.one * 300.0f;
static Rect s_HelpRect = new Rect(0.0f, 0.0f, 300.0f, 100.0f);
static Rect s_ListRect = new Rect(Vector2.zero, s_WindowsMinSize);
[MenuItem("Conversations/Editor")]
private static void ConversationsSystem()
{
const int width = 800;
const int height = 800;
var x = (Screen.currentResolution.width - width) / 2;
var y = (Screen.currentResolution.height - height) / 2;
GetWindow<ConversationsEditorWindow>().position = new Rect(x, y, width, height);
}
SerializedObject m_Conversations = null;
ReorderableList m_ReorderableList = null;
private void OnEnable()
{
ConversationTrigger conversationtrigger = FindObjectOfType<ConversationTrigger>();
if (conversationtrigger)
{
m_Conversations = new SerializedObject(conversationtrigger);
m_ReorderableList = new ReorderableList(m_Conversations, m_Conversations.FindProperty("conversations"), true, true, true, true);
m_ReorderableList.drawHeaderCallback = (rect) => EditorGUI.LabelField(rect, "Conversation Names");
m_ReorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
rect.y += TOP_PADDING;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index));
};
}
}
private void OnInspectorUpdate()
{
Repaint();
}
private void OnGUI()
{
if (m_Conversations != null)
{
m_Conversations.Update();
m_ReorderableList.DoList(s_ListRect);
m_Conversations.ApplyModifiedProperties();
}
else
{
EditorGUI.HelpBox(s_HelpRect, HELP_TEXT, MessageType.Warning);
}
}
}
This is how the Inspector looks like with the editor window :
The first problem is that I can add/remove items in the editor window on any GameObject in the Hierarchy. But I want to be able to do it only on the GameObject that the conversation is on. In this case it should be the DialogueTrigger but I can add/remove items also if I'm selecting the Terrain for example.
The second problem is that it's not showing in the Editor Window the node tree childs of each Conversation. Fore example the Opening have Name and Dialogues and so on but it's not showing it when I click the collapse arrow in the Editor Window.
And last when adding new item in the Editor Window I want it to add a new empty Conversation like in the Inspector else if I selected one of the already existing conversation then it should add the same Conversation as the selected one.
(It's adding now only the last conversation each time when clicking the plus (+) in the editor window. It's adding all the time the Locked Room even if I'm selecting first the Opening.
Your answer
Follow this Question
Related Questions
How can i rotate the camera to the player facing direction ? 1 Answer
Why when using LookAt to make the turret facing the target it's facing the other direction ? 1 Answer
How can i make an object to rotate in a circle smooth around another object nonstop ? 2 Answers
How can i use a button key click to switch/toggle between enum options ? 1 Answer