|
|
|
|
|
|
Questline, |
|
|
|
Quest, |
|
|
|
Step, |
|
|
|
Dialogue, |
|
|
|
Dialogue, |
|
|
|
|
|
|
|
} |
|
|
|
public class QuestEditorWindow : EditorWindow |
|
|
|
|
|
|
int idQuestlineSelected; |
|
|
|
int idQuestSelected; |
|
|
|
[MenuItem("ChopChop/QuestEditorWindow")] |
|
|
|
public static void ShowWindow() |
|
|
|
public static void ShowWindow() |
|
|
|
wnd.titleContent = new GUIContent("QuestEditorWindow"); |
|
|
|
wnd.titleContent = new GUIContent("QuestEditorWindow"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void ShowArtistToolWindow() |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
//window.SetTool();
|
|
|
|
} |
|
|
|
public void CreateGUI() |
|
|
|
{ |
|
|
|
VisualElement root = rootVisualElement; |
|
|
|
public void CreateGUI() |
|
|
|
{ |
|
|
|
VisualElement root = rootVisualElement; |
|
|
|
var visualTree =Resources.Load<VisualTreeAsset>("QuestEditorWindow"); |
|
|
|
root.Add(visualTree.CloneTree()); |
|
|
|
|
|
|
|
//Add Image
|
|
|
|
VisualElement preview = root.Q<VisualElement>("actor-preview"); |
|
|
|
actorPreview = new Image(); |
|
|
|
preview.Add(actorPreview); |
|
|
|
|
|
|
|
//Import USS
|
|
|
|
var styleSheet = Resources.Load< StyleSheet>("QuestEditorWindow"); |
|
|
|
root.styleSheets.Add(styleSheet); |
|
|
|
|
|
|
|
//Register button event
|
|
|
|
Button refreshQuestPreviewBtn = root.Q<Button>("refresh-preview-btn"); |
|
|
|
refreshQuestPreviewBtn.RegisterCallback<ClickEvent>((evt) => SetUpQuestPreview(currentSeletedQuest)); |
|
|
|
var visualTree = Resources.Load<VisualTreeAsset>("QuestEditorWindow"); |
|
|
|
root.Add(visualTree.CloneTree()); |
|
|
|
|
|
|
|
//Add Image
|
|
|
|
VisualElement preview = root.Q<VisualElement>("actor-preview"); |
|
|
|
actorPreview = new Image(); |
|
|
|
preview.Add(actorPreview); |
|
|
|
|
|
|
|
//Import USS
|
|
|
|
var styleSheet = Resources.Load<StyleSheet>("QuestEditorWindow"); |
|
|
|
root.styleSheets.Add(styleSheet); |
|
|
|
|
|
|
|
//Register button event
|
|
|
|
Button refreshQuestPreviewBtn = root.Q<Button>("refresh-preview-btn"); |
|
|
|
refreshQuestPreviewBtn.RegisterCallback<ClickEvent>((evt) => SetUpQuestPreview(currentSeletedQuest)); |
|
|
|
createQuestline.SetEnabled (true); |
|
|
|
createQuestline.SetEnabled(true); |
|
|
|
Button createQuest = rootVisualElement.Q<Button>("CreateQ"); |
|
|
|
Button createQuest = rootVisualElement.Q<Button>("CreateQ"); |
|
|
|
Button createStep = rootVisualElement.Q<Button>("CreateS"); |
|
|
|
Button createStep = rootVisualElement.Q<Button>("CreateS"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
private void ClearElements(selectionType type) |
|
|
|
{ |
|
|
|
|
|
|
listElements.Add("step-info-scroll"); |
|
|
|
listElements.Add("dialogue-info-scroll"); |
|
|
|
if (createQuest != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
createQuest.SetEnabled(true); |
|
|
|
} |
|
|
|
if (createStep != null) |
|
|
|
|
|
|
case selectionType.Step: |
|
|
|
|
|
|
|
listElements.Add("dialogue-info-scroll"); |
|
|
|
|
|
|
|
|
|
|
|
foreach(string elementName in listElements) |
|
|
|
foreach (string elementName in listElements) |
|
|
|
{ |
|
|
|
VisualElement element = rootVisualElement.Q<VisualElement>(elementName); |
|
|
|
element.Clear(); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void LoadAllQuestsData() |
|
|
|
{ |
|
|
|
private void LoadAllQuestsData() |
|
|
|
{ |
|
|
|
FindAllSOByType(out QuestlineSO[] questLineSOs); |
|
|
|
RefreshListView(out ListView allQuestlinesListView, "questlines-list", questLineSOs); |
|
|
|
FindAllSOByType(out QuestlineSO[] questLineSOs); |
|
|
|
RefreshListView(out ListView allQuestlinesListView, "questlines-list", questLineSOs); |
|
|
|
allQuestlinesListView.onSelectionChange += (questlineEnumerable) => |
|
|
|
{ |
|
|
|
selectedQuestLine = GetDataFromListViewItem<QuestlineSO>(questlineEnumerable); |
|
|
|
allQuestlinesListView.onSelectionChange += (questlineEnumerable) => |
|
|
|
{ |
|
|
|
selectedQuestLine = GetDataFromListViewItem<QuestlineSO>(questlineEnumerable); |
|
|
|
if (selectedQuestLine.Quests != null ) |
|
|
|
if (selectedQuestLine.Quests != null) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allQuestsListView.onSelectionChange += (questEnumerable) => |
|
|
|
|
|
|
currentSeletedQuest = GetDataFromListViewItem<QuestSO>(questEnumerable); |
|
|
|
ClearElements(selectionType.Quest); |
|
|
|
if (currentSeletedQuest != null && currentSeletedQuest.Steps != null ) |
|
|
|
if (currentSeletedQuest != null && currentSeletedQuest.Steps != null) |
|
|
|
{ |
|
|
|
RefreshListView(out ListView allStepsListView, "steps-list", currentSeletedQuest.Steps.ToArray()); |
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
RefreshListView(out ListView dialoguesListView, "dialogues-list", dialogueDataSOs); |
|
|
|
|
|
|
|
|
|
|
|
dialoguesListView.onSelectionChange += (dialogueEnumerable) => |
|
|
|
{ |
|
|
|
DialogueDataSO dialogueData = GetDataFromListViewItem<DialogueDataSO>(dialogueEnumerable); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private T GetDataFromListViewItem<T>(IEnumerable<object> enumberable) where T : ScriptableObject |
|
|
|
{ |
|
|
|
T data = default; |
|
|
|
foreach (var item in enumberable) |
|
|
|
{ |
|
|
|
data = item as T; |
|
|
|
} |
|
|
|
return data; |
|
|
|
} |
|
|
|
private void FindAllDialogueInStep(StepSO step, out DialogueDataSO[] AllDialogue) |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private T GetDataFromListViewItem<T>(IEnumerable<object> enumberable) where T : ScriptableObject |
|
|
|
{ |
|
|
|
T data = default; |
|
|
|
foreach (var item in enumberable) |
|
|
|
{ |
|
|
|
data = item as T; |
|
|
|
} |
|
|
|
return data; |
|
|
|
} |
|
|
|
private void FindAllDialogueInStep(StepSO step, out DialogueDataSO[] AllDialogue) |
|
|
|
List<DialogueDataSO> AllDialogueList = new List<DialogueDataSO>(); |
|
|
|
if (step!=null) |
|
|
|
List<DialogueDataSO> AllDialogueList = new List<DialogueDataSO>(); |
|
|
|
if (step != null) |
|
|
|
|
|
|
|
AllDialogueList.Add(step.DialogueBeforeStep); |
|
|
|
|
|
|
|
AllDialogueList.Add(step.DialogueBeforeStep); |
|
|
|
if(step.CompleteDialogue!=null) |
|
|
|
if (step.CompleteDialogue != null) |
|
|
|
if (step.IncompleteDialogue!=null) |
|
|
|
if (step.IncompleteDialogue != null) |
|
|
|
{ |
|
|
|
|
|
|
|
AllDialogueList.Add(step.IncompleteDialogue); |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
Debug.Log("AllDialogueList" + AllDialogueList.ToArray()); |
|
|
|
if(AllDialogueList!=null) |
|
|
|
AllDialogue = AllDialogueList.ToArray(); |
|
|
|
Debug.Log("AllDialogueList" + AllDialogueList.ToArray()); |
|
|
|
if (AllDialogueList != null) |
|
|
|
AllDialogue = AllDialogueList.ToArray(); |
|
|
|
} |
|
|
|
private void SetUpQuestPreview(QuestSO quest) |
|
|
|
{ |
|
|
|
if (quest == null) |
|
|
|
return; |
|
|
|
} |
|
|
|
private void SetUpQuestPreview(QuestSO quest) |
|
|
|
{ |
|
|
|
if (quest == null) |
|
|
|
return; |
|
|
|
if (quest.Steps.Count>0&& quest.Steps[0].Actor!=null) |
|
|
|
LoadActorImage(quest.Steps[0].Actor.name); |
|
|
|
|
|
|
|
//Clear actor conversations area
|
|
|
|
rootVisualElement.Q<VisualElement>("actor-conversations").Clear(); |
|
|
|
|
|
|
|
foreach (StepSO step in quest.Steps) |
|
|
|
LoadAndInitStepUXML(step); |
|
|
|
} |
|
|
|
|
|
|
|
private void LoadAndInitStepUXML(StepSO step) |
|
|
|
{ |
|
|
|
//Clear actor conversations area
|
|
|
|
VisualElement actorConversationsVE = rootVisualElement.Q<VisualElement>("actor-conversations"); |
|
|
|
|
|
|
|
// Import UXML
|
|
|
|
var stepVisualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/Quests/Editor/StepDetail.uxml"); |
|
|
|
VisualElement stepVE = stepVisualTree.CloneTree(); |
|
|
|
VisualElement dialogueAreaVE = stepVE.Q<VisualElement>("dialogue-area"); |
|
|
|
|
|
|
|
//Title
|
|
|
|
stepVE.Q<Label>("step-title-label").text = "Step" + step.name[1]; |
|
|
|
|
|
|
|
//IsDone
|
|
|
|
if (quest.Steps.Count > 0 && quest.Steps[0].Actor != null) |
|
|
|
LoadActorImage(quest.Steps[0].Actor.name); |
|
|
|
|
|
|
|
//Clear actor conversations area
|
|
|
|
rootVisualElement.Q<VisualElement>("actor-conversations").Clear(); |
|
|
|
|
|
|
|
foreach (StepSO step in quest.Steps) |
|
|
|
LoadAndInitStepUXML(step); |
|
|
|
} |
|
|
|
|
|
|
|
private void LoadAndInitStepUXML(StepSO step) |
|
|
|
{ |
|
|
|
//Clear actor conversations area
|
|
|
|
VisualElement actorConversationsVE = rootVisualElement.Q<VisualElement>("actor-conversations"); |
|
|
|
|
|
|
|
// Import UXML
|
|
|
|
var stepVisualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/Quests/Editor/StepDetail.uxml"); |
|
|
|
VisualElement stepVE = stepVisualTree.CloneTree(); |
|
|
|
VisualElement dialogueAreaVE = stepVE.Q<VisualElement>("dialogue-area"); |
|
|
|
|
|
|
|
//Title
|
|
|
|
stepVE.Q<Label>("step-title-label").text = "Step" + step.name[1]; |
|
|
|
|
|
|
|
//IsDone
|
|
|
|
isDoneToggle.SetEnabled(false); |
|
|
|
|
|
|
|
//SD
|
|
|
|
if(step.DialogueBeforeStep!=null) |
|
|
|
LoadAndInitStartDialogueLineUXML(step.DialogueBeforeStep, dialogueAreaVE); |
|
|
|
|
|
|
|
//CD ID if any
|
|
|
|
isDoneToggle.SetEnabled(false); |
|
|
|
|
|
|
|
//SD
|
|
|
|
if (step.DialogueBeforeStep != null) |
|
|
|
LoadAndInitStartDialogueLineUXML(step.DialogueBeforeStep, dialogueAreaVE); |
|
|
|
|
|
|
|
//CD ID if any
|
|
|
|
LoadAndInitOptionsDialogueLineUXML(step.CompleteDialogue, step.IncompleteDialogue, dialogueAreaVE); |
|
|
|
|
|
|
|
//Type (Check Item etc)
|
|
|
|
LoadAndInitOptionsDialogueLineUXML(step.CompleteDialogue, step.IncompleteDialogue, dialogueAreaVE); |
|
|
|
|
|
|
|
//Type (Check Item etc)
|
|
|
|
if (step.Type == stepType.dialogue) |
|
|
|
{ |
|
|
|
VisualElement itemValidateVE = stepVE.Q<VisualElement>("item-validate"); |
|
|
|
|
|
|
stepVE.Q<Label>("item-to-validate").text = step.Item.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
actorConversationsVE.Add(stepVE); |
|
|
|
} |
|
|
|
|
|
|
|
private void LoadAndInitStartDialogueLineUXML(DialogueDataSO startDialogue, VisualElement parent) |
|
|
|
{ |
|
|
|
// Import UXML
|
|
|
|
var dialogueVisualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/Quests/Editor/DialogueLine.uxml"); |
|
|
|
|
|
|
|
// Set line
|
|
|
|
foreach (LocalizedString line in startDialogue.DialogueLines) |
|
|
|
{ |
|
|
|
VisualElement dialogueVE = dialogueVisualTree.CloneTree(); |
|
|
|
|
|
|
|
Label leftLineLabel = dialogueVE.Q<Label>("left-line-label"); |
|
|
|
leftLineLabel.text = line.GetLocalizedStringImmediateSafe(); |
|
|
|
|
|
|
|
Label rightLineLabel = dialogueVE.Q<Label>("right-line-label"); |
|
|
|
rightLineLabel.style.display = DisplayStyle.None; |
|
|
|
|
|
|
|
// Set options
|
|
|
|
VisualElement buttonArea = dialogueVE.Q<VisualElement>("buttons"); |
|
|
|
if (startDialogue.Choices.Count==0) |
|
|
|
{ |
|
|
|
buttonArea.style.display = DisplayStyle.None; |
|
|
|
} |
|
|
|
else if (startDialogue.Choices.Count <= 2) |
|
|
|
{ |
|
|
|
for (int i = 0; i < 2; i++) |
|
|
|
{ |
|
|
|
Button btn = buttonArea.Q<Button>($"btn-{i}"); |
|
|
|
if (i < startDialogue.Choices.Count) |
|
|
|
btn.text = startDialogue.Choices[i].Response.GetLocalizedStringImmediateSafe(); |
|
|
|
else |
|
|
|
btn.style.display = DisplayStyle.None; |
|
|
|
} |
|
|
|
} |
|
|
|
parent.Add(dialogueVE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void LoadAndInitOptionsDialogueLineUXML(DialogueDataSO completeDialogue, DialogueDataSO incompleteDialogue, VisualElement parent) |
|
|
|
{ |
|
|
|
// Import UXML
|
|
|
|
var dialogueVisualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/Quests/Editor/DialogueLine.uxml"); |
|
|
|
VisualElement dialogueVE = dialogueVisualTree.CloneTree(); |
|
|
|
|
|
|
|
// Set line
|
|
|
|
Label leftLineLabel = dialogueVE.Q<Label>("left-line-label"); |
|
|
|
Label rightLineLabel = dialogueVE.Q<Label>("right-line-label"); |
|
|
|
|
|
|
|
leftLineLabel.text = completeDialogue.DialogueLines[0].GetLocalizedStringImmediateSafe(); |
|
|
|
if (incompleteDialogue != null) |
|
|
|
rightLineLabel.text = incompleteDialogue.DialogueLines[0].GetLocalizedStringImmediateSafe(); |
|
|
|
|
|
|
|
// hide options
|
|
|
|
VisualElement buttonArea = dialogueVE.Q<VisualElement>("buttons"); |
|
|
|
buttonArea.style.display = DisplayStyle.None; |
|
|
|
|
|
|
|
parent.Add(dialogueVE); |
|
|
|
} |
|
|
|
|
|
|
|
private void FindAllSOsInTargetFolder<T>(Object target, out T[] foundSOs) where T : ScriptableObject |
|
|
|
{ |
|
|
|
var guids = AssetDatabase.FindAssets($"t:{typeof(T)}", new[] {Path.GetDirectoryName(AssetDatabase.GetAssetPath(target))}); |
|
|
|
|
|
|
|
foundSOs = new T[guids.Length]; |
|
|
|
for (int i = 0; i < guids.Length; i++) |
|
|
|
{ |
|
|
|
var path = AssetDatabase.GUIDToAssetPath(guids[i]); |
|
|
|
foundSOs[i] = AssetDatabase.LoadAssetAtPath<T>(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void FindAllSOByType<T>(out T[] foundSOs) where T : ScriptableObject |
|
|
|
{ |
|
|
|
var guids = AssetDatabase.FindAssets($"t:{typeof(T)}"); |
|
|
|
|
|
|
|
foundSOs = new T[guids.Length]; |
|
|
|
for (int i = 0; i < guids.Length; i++) |
|
|
|
{ |
|
|
|
var path = AssetDatabase.GUIDToAssetPath(guids[i]); |
|
|
|
foundSOs[i] = AssetDatabase.LoadAssetAtPath<T>(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void InitListView<T>(ListView listview, T[] itemsSource) |
|
|
|
{ |
|
|
|
listview.makeItem = () => new Label(); |
|
|
|
listview.bindItem = (element, i) => |
|
|
|
{ |
|
|
|
var nameProperty = itemsSource[i].GetType().GetProperty("name"); |
|
|
|
if (nameProperty != null) |
|
|
|
{ |
|
|
|
(element as Label).text = nameProperty.GetValue(itemsSource[i]) as string; |
|
|
|
} |
|
|
|
}; |
|
|
|
listview.itemsSource = itemsSource; |
|
|
|
listview.itemHeight = 16; |
|
|
|
listview.selectionType = SelectionType.Single; |
|
|
|
listview.style.flexGrow = 1.0f; |
|
|
|
|
|
|
|
listview.Refresh(); |
|
|
|
if(itemsSource.Length>0) |
|
|
|
listview.selectedIndex = 0; |
|
|
|
} |
|
|
|
|
|
|
|
private void RefreshListView<T>(out ListView listview, string visualElementName, T[] itemsSource) |
|
|
|
{ |
|
|
|
listview = new ListView(); |
|
|
|
VisualElement parentVE = rootVisualElement.Q<VisualElement>(visualElementName); |
|
|
|
parentVE.Clear(); |
|
|
|
InitListView(listview, itemsSource); |
|
|
|
parentVE.Add(listview); |
|
|
|
actorConversationsVE.Add(stepVE); |
|
|
|
} |
|
|
|
|
|
|
|
private void LoadAndInitStartDialogueLineUXML(DialogueDataSO startDialogue, VisualElement parent) |
|
|
|
{ |
|
|
|
// Import UXML
|
|
|
|
var dialogueVisualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/Quests/Editor/DialogueLine.uxml"); |
|
|
|
|
|
|
|
// Set line
|
|
|
|
foreach (LocalizedString line in startDialogue.DialogueLines) |
|
|
|
{ |
|
|
|
VisualElement dialogueVE = dialogueVisualTree.CloneTree(); |
|
|
|
|
|
|
|
Label leftLineLabel = dialogueVE.Q<Label>("left-line-label"); |
|
|
|
leftLineLabel.text = line.GetLocalizedStringImmediateSafe(); |
|
|
|
Label rightLineLabel = dialogueVE.Q<Label>("right-line-label"); |
|
|
|
rightLineLabel.style.display = DisplayStyle.None; |
|
|
|
// Set options
|
|
|
|
VisualElement buttonArea = dialogueVE.Q<VisualElement>("buttons"); |
|
|
|
if (startDialogue.Choices.Count == 0) |
|
|
|
{ |
|
|
|
buttonArea.style.display = DisplayStyle.None; |
|
|
|
} |
|
|
|
else if (startDialogue.Choices.Count <= 2) |
|
|
|
{ |
|
|
|
for (int i = 0; i < 2; i++) |
|
|
|
{ |
|
|
|
Button btn = buttonArea.Q<Button>($"btn-{i}"); |
|
|
|
if (i < startDialogue.Choices.Count) |
|
|
|
btn.text = startDialogue.Choices[i].Response.GetLocalizedStringImmediateSafe(); |
|
|
|
else |
|
|
|
btn.style.display = DisplayStyle.None; |
|
|
|
} |
|
|
|
} |
|
|
|
parent.Add(dialogueVE); |
|
|
|
} |
|
|
|
private void LoadActorImage(string actorName) |
|
|
|
{ |
|
|
|
Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath($"Assets/Scripts/Quests/Editor/ActorImages/{actorName}.png", typeof(Texture2D)); |
|
|
|
actorPreview.image = texture; |
|
|
|
} |
|
|
|
|
|
|
|
private void DisplayAllProperties(Object data, string visualElementName) |
|
|
|
{ |
|
|
|
//Clear panel
|
|
|
|
VisualElement parentVE = rootVisualElement.Q<VisualElement>(visualElementName); |
|
|
|
parentVE.Clear(); |
|
|
|
|
|
|
|
//Add new scrollview
|
|
|
|
ScrollView scrollView= new ScrollView(); |
|
|
|
|
|
|
|
SerializedObject dataObject = new SerializedObject(data); |
|
|
|
SerializedProperty dataProperty = dataObject.GetIterator(); |
|
|
|
dataProperty.Next(true); |
|
|
|
|
|
|
|
while (dataProperty.NextVisible(false)) |
|
|
|
{ |
|
|
|
PropertyField prop=new PropertyField(dataProperty); |
|
|
|
prop.SetEnabled(dataProperty.name != "m_Script"); |
|
|
|
prop.Bind(dataObject); |
|
|
|
scrollView.Add(prop); |
|
|
|
} |
|
|
|
parentVE.Add(scrollView); |
|
|
|
} |
|
|
|
private void LoadAndInitOptionsDialogueLineUXML(DialogueDataSO completeDialogue, DialogueDataSO incompleteDialogue, VisualElement parent) |
|
|
|
{ |
|
|
|
// Import UXML
|
|
|
|
var dialogueVisualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/Quests/Editor/DialogueLine.uxml"); |
|
|
|
VisualElement dialogueVE = dialogueVisualTree.CloneTree(); |
|
|
|
|
|
|
|
// Set line
|
|
|
|
Label leftLineLabel = dialogueVE.Q<Label>("left-line-label"); |
|
|
|
Label rightLineLabel = dialogueVE.Q<Label>("right-line-label"); |
|
|
|
|
|
|
|
leftLineLabel.text = completeDialogue.DialogueLines[0].GetLocalizedStringImmediateSafe(); |
|
|
|
if (incompleteDialogue != null) |
|
|
|
rightLineLabel.text = incompleteDialogue.DialogueLines[0].GetLocalizedStringImmediateSafe(); |
|
|
|
|
|
|
|
// hide options
|
|
|
|
VisualElement buttonArea = dialogueVE.Q<VisualElement>("buttons"); |
|
|
|
buttonArea.style.display = DisplayStyle.None; |
|
|
|
|
|
|
|
parent.Add(dialogueVE); |
|
|
|
} |
|
|
|
|
|
|
|
private void FindAllSOsInTargetFolder<T>(Object target, out T[] foundSOs) where T : ScriptableObject |
|
|
|
{ |
|
|
|
var guids = AssetDatabase.FindAssets($"t:{typeof(T)}", new[] { Path.GetDirectoryName(AssetDatabase.GetAssetPath(target)) }); |
|
|
|
|
|
|
|
foundSOs = new T[guids.Length]; |
|
|
|
for (int i = 0; i < guids.Length; i++) |
|
|
|
{ |
|
|
|
var path = AssetDatabase.GUIDToAssetPath(guids[i]); |
|
|
|
foundSOs[i] = AssetDatabase.LoadAssetAtPath<T>(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void FindAllSOByType<T>(out T[] foundSOs) where T : ScriptableObject |
|
|
|
{ |
|
|
|
var guids = AssetDatabase.FindAssets($"t:{typeof(T)}"); |
|
|
|
|
|
|
|
foundSOs = new T[guids.Length]; |
|
|
|
for (int i = 0; i < guids.Length; i++) |
|
|
|
{ |
|
|
|
var path = AssetDatabase.GUIDToAssetPath(guids[i]); |
|
|
|
foundSOs[i] = AssetDatabase.LoadAssetAtPath<T>(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void InitListView<T>(ListView listview, T[] itemsSource) |
|
|
|
{ |
|
|
|
listview.makeItem = () => new Label(); |
|
|
|
listview.bindItem = (element, i) => |
|
|
|
{ |
|
|
|
var nameProperty = itemsSource[i].GetType().GetProperty("name"); |
|
|
|
if (nameProperty != null) |
|
|
|
{ |
|
|
|
(element as Label).text = nameProperty.GetValue(itemsSource[i]) as string; |
|
|
|
} |
|
|
|
}; |
|
|
|
listview.itemsSource = itemsSource; |
|
|
|
listview.itemHeight = 16; |
|
|
|
listview.selectionType = SelectionType.Single; |
|
|
|
listview.style.flexGrow = 1.0f; |
|
|
|
|
|
|
|
listview.Refresh(); |
|
|
|
if (itemsSource.Length > 0) |
|
|
|
listview.selectedIndex = 0; |
|
|
|
} |
|
|
|
|
|
|
|
private void RefreshListView<T>(out ListView listview, string visualElementName, T[] itemsSource) |
|
|
|
{ |
|
|
|
listview = new ListView(); |
|
|
|
VisualElement parentVE = rootVisualElement.Q<VisualElement>(visualElementName); |
|
|
|
parentVE.Clear(); |
|
|
|
InitListView(listview, itemsSource); |
|
|
|
parentVE.Add(listview); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void LoadActorImage(string actorName) |
|
|
|
{ |
|
|
|
Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath($"Assets/Scripts/Quests/Editor/ActorImages/{actorName}.png", typeof(Texture2D)); |
|
|
|
actorPreview.image = texture; |
|
|
|
} |
|
|
|
|
|
|
|
private void DisplayAllProperties(Object data, string visualElementName) |
|
|
|
{ |
|
|
|
//Clear panel
|
|
|
|
VisualElement parentVE = rootVisualElement.Q<VisualElement>(visualElementName); |
|
|
|
parentVE.Clear(); |
|
|
|
|
|
|
|
//Add new scrollview
|
|
|
|
ScrollView scrollView = new ScrollView(); |
|
|
|
|
|
|
|
SerializedObject dataObject = new SerializedObject(data); |
|
|
|
SerializedProperty dataProperty = dataObject.GetIterator(); |
|
|
|
dataProperty.Next(true); |
|
|
|
|
|
|
|
while (dataProperty.NextVisible(false)) |
|
|
|
{ |
|
|
|
PropertyField prop = new PropertyField(dataProperty); |
|
|
|
prop.SetEnabled(dataProperty.name != "m_Script"); |
|
|
|
prop.Bind(dataObject); |
|
|
|
scrollView.Add(prop); |
|
|
|
} |
|
|
|
parentVE.Add(scrollView); |
|
|
|
} |
|
|
|
id++; |
|
|
|
id++; |
|
|
|
asset.SetQuestlineId (id); |
|
|
|
AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests","Questline" + id); |
|
|
|
AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline"+id+"/QL"+id+".asset"); |
|
|
|
asset.SetQuestlineId(id); |
|
|
|
AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests", "Questline" + id); |
|
|
|
AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + id + "/QL" + id + ".asset"); |
|
|
|
LoadAllQuestsData(); |
|
|
|
LoadAllQuestsData(); |
|
|
|
} |
|
|
|
void RemoveQuestline() |
|
|
|
{ |
|
|
|
|
|
|
void AddQuest() |
|
|
|
{ |
|
|
|
QuestSO asset = ScriptableObject.CreateInstance<QuestSO>(); |
|
|
|
QuestSO asset = ScriptableObject.CreateInstance<QuestSO>(); |
|
|
|
questId = selectedQuestLine.Quests.Count +1 ; |
|
|
|
AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId, "Quest" + questId); |
|
|
|
AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline"+ questlineId + "/Quest"+questId+"/Q" + questId+"-QL"+ questlineId + ".asset"); |
|
|
|
questId = selectedQuestLine.Quests.Count + 1; |
|
|
|
AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId, "Quest" + questId); |
|
|
|
AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Q" + questId + "-QL" + questlineId + ".asset"); |
|
|
|
asset.SetQuestId(questId); |
|
|
|
asset.SetQuestId(questId); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
void RemoveQuest() |
|
|
|
{ |
|
|
|
|
|
|
int questlineId = 0; |
|
|
|
questlineId = selectedQuestLine.IdQuestline; |
|
|
|
int questId = 0; |
|
|
|
questId =currentSeletedQuest.IdQuest; |
|
|
|
questId = currentSeletedQuest.IdQuest; |
|
|
|
AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId , "Step" + stepId); |
|
|
|
AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Step" + stepId +"/S"+ stepId + "-Q" + questId + "-QL" + questlineId + ".asset"); |
|
|
|
AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId, "Step" + stepId); |
|
|
|
AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Step" + stepId + "/S" + stepId + "-Q" + questId + "-QL" + questlineId + ".asset"); |
|
|
|
AssetDatabase.SaveAssets(); |
|
|
|
currentSeletedQuest.Steps.Add(asset); |
|
|
|
//refresh
|
|
|
|