浏览代码

Add a StepToDialogue function to the StepSO. Fix preview display in the Quest tool

/main
uChema 3 年前
当前提交
e132a119
共有 18 个文件被更改,包括 313 次插入68 次删除
  1. 12
      UOP1_Project/Assets/Scripts/Dialogues/DialogueDataSO.cs
  2. 37
      UOP1_Project/Assets/Scripts/Quests/Editor/DialogueLine.uxml
  3. 112
      UOP1_Project/Assets/Scripts/Quests/Editor/QuestEditorWindow.cs
  4. 4
      UOP1_Project/Assets/Scripts/Quests/Editor/StepDetail.uxml
  5. 12
      UOP1_Project/Assets/Scripts/Quests/Resources/QuestEditorWindow.uss
  6. 6
      UOP1_Project/Assets/Scripts/Quests/Resources/QuestEditorWindow.uxml
  7. 35
      UOP1_Project/Assets/Scripts/Quests/ScriptableObjects/StepSO.cs
  8. 4
      .DS_Store
  9. 59
      UOP1_Project/Assets/DialogueUSS.uss
  10. 11
      UOP1_Project/Assets/DialogueUSS.uss.meta
  11. 8
      UOP1_Project/Assets/ScriptableObjects/Quests/Questline1/Quest3/Step3.meta
  12. 8
      UOP1_Project/Assets/ScriptableObjects/Quests/Questline3.meta
  13. 1
      UOP1_Project/Assets/Scripts/Quests/.DS_Store
  14. 36
      UOP1_Project/Assets/Scripts/Quests/Editor/DialoguePreview.cs
  15. 11
      UOP1_Project/Assets/Scripts/Quests/Editor/DialoguePreview.cs.meta
  16. 17
      UOP1_Project/Assets/ScriptableObjects/Quests/Questline3/QL3.asset
  17. 8
      UOP1_Project/Assets/ScriptableObjects/Quests/Questline3/QL3.asset.meta

12
UOP1_Project/Assets/Scripts/Dialogues/DialogueDataSO.cs


public List<Choice> Choices => _choices;
public DialogueType DialogueType => _dialogueType;
public void SetActor(ActorSO newActor)
{
_actor = newActor;
}
#if UNITY_EDITOR
//TODO: Add support for branching conversations

{
SetDialogueLines();
//SetDialogueLines();
}
void SetDialogueLines()
{

}
}
#endif
}

public LocalizedString Response => _response;
public DialogueDataSO NextDialogue => _nextDialogue;
public ChoiceActionType ActionType => _actionType;
public void SetNextDialogue(DialogueDataSO dialogue)
{
_nextDialogue = dialogue;
}
}

37
UOP1_Project/Assets/Scripts/Quests/Editor/DialogueLine.uxml


<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<ui:VisualElement name="line-box" style="flex-direction: column; padding-left: 2px; padding-right: 2px; padding-top: 2px; padding-bottom: 2px;">
<ui:VisualElement name="lines" style="flex-direction: row; width: 100%;">
<ui:VisualElement name="left-line" style="margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; width: 50%; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;">
<ui:Label text="This is line 1." display-tooltip-when-elided="true" name="left-line-label" style="background-color: rgb(158, 222, 115); white-space: normal; color: rgba(73, 94, 0, 255);" />
</ui:VisualElement>
<ui:VisualElement name="right-line" style="width: 50%; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px;">
<ui:Label text="This is line 2." display-tooltip-when-elided="true" name="right-line-label" style="background-color: rgb(243, 145, 137); white-space: normal; color: rgb(106, 9, 0);" />
<Style src="/Assets/DialogueUSS.uss" />
<ui:VisualElement name="DialogueWithBranches">
<ui:VisualElement name="Dialogue" style="align-items: stretch; min-width: 50%;">
<ui:Label text="This is line 1." display-tooltip-when-elided="true" name="Line" class="DefaultLine" />
<ui:Label text="This is line 1." display-tooltip-when-elided="true" name="Line" class="DefaultLine" />
<ui:VisualElement name="Choices" class="Choices">
<ui:VisualElement name="Dialogue" class="Choice">
<ui:Button text="Yes" name="Button" class="ChoiceButton" />
<ui:VisualElement name="Default" style="align-items: stretch; min-width: 50%;">
<ui:Label text="This is line 1." display-tooltip-when-elided="true" name="winDialogue" class="CompletionLine" />
<ui:VisualElement name="Choices" class="Choices">
<ui:VisualElement name="Choice" class="Choice">
<ui:Button text="Yes" name="Button" class="ChoiceButton" />
<ui:VisualElement name="Dialogue" style="align-items: stretch; min-width: 50%;">
<ui:Label text="This is line 1." display-tooltip-when-elided="true" name="Line" class="CompletionLine" />
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="Choice" style="align-items: stretch; min-width: 50%;">
<ui:Button text="Yes" name="Button" class="ChoiceButton" />
<ui:VisualElement name="Dialogue" style="align-items: stretch; min-width: 50%;">
<ui:Label text="This is line 1." display-tooltip-when-elided="true" name="Line" class="IncompletionLine" />
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="buttons" style="flex-direction: row; justify-content: space-around;">
<ui:Button text="Yes" name="btn-0" style="width: 45%; background-color: rgb(115, 115, 115);" />
<ui:Button text="No" name="btn-1" style="width: 45%; background-color: rgb(115, 115, 115);" />
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>

112
UOP1_Project/Assets/Scripts/Quests/Editor/QuestEditorWindow.cs


}
public class QuestEditorWindow : EditorWindow
{
private Image actorPreview;
private QuestSO currentSeletedQuest;
QuestlineSO selectedQuestLine;
int idQuestlineSelected;

// Import UXML
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");

if (quest == null)
return;
if (quest.Steps == null)
return;
if (quest.Steps.Count > 0 && quest.Steps[0].Actor != null)
LoadActorImage(quest.Steps[0].Actor.name);
return;
//Clear actor conversations area
rootVisualElement.Q<VisualElement>("actor-conversations").Clear();
foreach (StepSO step in quest.Steps)

private void LoadAndInitStepUXML(StepSO step)
{
//Clear actor conversations area
VisualElement actorConversationsVE = rootVisualElement.Q<VisualElement>("actor-conversations");
ScrollView actorConversationsVE = rootVisualElement.Q<ScrollView>("actor-conversations");
// Import UXML
var stepVisualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/Quests/Editor/StepDetail.uxml");
VisualElement stepVE = stepVisualTree.CloneTree();

isDoneToggle.value = step.IsDone;
isDoneToggle.SetEnabled(false);
//SD
if (step.DialogueBeforeStep != null)
LoadAndInitStartDialogueLineUXML(step.DialogueBeforeStep, dialogueAreaVE);
DialogueDataSO dialogueToPreview = new DialogueDataSO();
dialogueToPreview = step.StepToDialogue();
if (dialogueToPreview != null)
{
//setPreview Actor for each step
Image actorPreview = LoadActorImage(step.Actor.name);
//Add Image
VisualElement preview = stepVE.Q<VisualElement>("actor-preview");
preview.Add(actorPreview);
//CD ID if any
if (step.CompleteDialogue != null)
LoadAndInitOptionsDialogueLineUXML(step.CompleteDialogue, step.IncompleteDialogue, dialogueAreaVE);
VisualElement VE = CreateDialoguePreviewWithBranching(dialogueToPreview);
dialogueAreaVE.Add(VE);
}
//Type (Check Item etc)
if (step.Type == StepType.Dialogue)

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)

// 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)

}
private void LoadActorImage(string actorName)
private Image LoadActorImage(string actorName)
Image actorPreview = new Image();
return actorPreview;
}
private void DisplayAllProperties(Object data, string visualElementName)

{
}
}
private VisualElement CreateDialoguePreviewWithBranching(DialogueDataSO dialogueDataSO)
{
VisualElement dialoguePreviewVE = new VisualElement();
dialoguePreviewVE.name = "Dialogue";
foreach (LocalizedString localizedString in dialogueDataSO.DialogueLines)
{
Label dialogueLine = new Label();
dialogueLine.name = dialogueDataSO.DialogueType.ToString();
dialogueLine.text = localizedString.GetLocalizedStringImmediateSafe();
dialoguePreviewVE.Add(dialogueLine);
}
if (dialogueDataSO.Choices != null)
{
VisualElement choicesVE = new VisualElement();
choicesVE.name = "Choices";
for (int i = 0; i < dialogueDataSO.Choices.Count; i++)
{
VisualElement choiceVE = new VisualElement();
Choice choice = dialogueDataSO.Choices[i];
Button dialogueButton = new Button();
dialogueButton.name = "Button" + idQuestlineSelected;
dialogueButton.text = choice.Response.GetLocalizedStringImmediateSafe();
choiceVE.Add(dialogueButton);
if (choice.NextDialogue != null)
choiceVE.Add(CreateDialoguePreviewWithBranching(choice.NextDialogue));
choiceVE.name = "Choice";
choicesVE.Add(choiceVE);
}
dialoguePreviewVE.Add(choicesVE);
}
return dialoguePreviewVE;
}
}
class Lines
{
public string line;
public bool isText;//or is Button
}

4
UOP1_Project/Assets/Scripts/Quests/Editor/StepDetail.uxml


<ui:Label text="Step1" display-tooltip-when-elided="true" name="step-title-label" style="-unity-font-style: bold;" />
<ui:Toggle name="step-done-toggle" text="IsDone" value="false" style="-unity-font-style: normal;" />
</ui:VisualElement>
<ui:VisualElement name="dialogue-area" />
<ui:VisualElement name="dialogue-area">
<ui:VisualElement name="actor-preview" />
</ui:VisualElement>
<ui:VisualElement name="item-validate" style="flex-direction: row; justify-content: space-around;">
<ui:Label text="Check Item:" display-tooltip-when-elided="true" name="step-type" style="-unity-font-style: bold;" />
<ui:Label text="Apple" display-tooltip-when-elided="true" name="item-to-validate" />

12
UOP1_Project/Assets/Scripts/Quests/Resources/QuestEditorWindow.uss


width: 20px;
height: 20px;
}
#actor-preview {
width: 100px;
height: 100px;
margin-left: auto;
margin-right: auto;
}
.3rdColumn {
width: 40%;
background-color: rgb(185, 185, 185);
}

6
UOP1_Project/Assets/Scripts/Quests/Resources/QuestEditorWindow.uxml


<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="QuestEditorWindow.uss" />
<Style src="/Assets/DialogueUSS.uss" />
<ui:VisualElement name="quest-editor-window" style="flex-direction: row; height: 100%; width: 100%; min-height: 700px;">
<ui:VisualElement name="1st-column" style="width: 30%;">
<ui:VisualElement name="questlines" class="padding5 ColorStyling1" style="width: auto; height: 150px;">

<ui:VisualElement name="dialogue-info-scroll" style="height: 100%;" />
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="3rd-column" style="width: 40%; background-color: rgb(185, 185, 185);">
<ui:VisualElement name="3rd-column" class="3rdColumn">
<ui:VisualElement name="actor-preview" style="width: 100px; height: 100px; margin-left: auto; margin-right: auto;" />
<ui:VisualElement name="actor-conversations" style="padding-left: 5px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px;" />
<ui:ScrollView name="actor-conversations" show-vertical-scroller="true" style="height: 100%;" />
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>

35
UOP1_Project/Assets/Scripts/Quests/ScriptableObjects/StepSO.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Serialization;
public enum StepType
{

_isDone = true;
}
public DialogueDataSO StepToDialogue()
{
DialogueDataSO dialogueData = new DialogueDataSO();
dialogueData.SetActor(Actor);
if (DialogueBeforeStep != null)
{
dialogueData = DialogueBeforeStep;
if (DialogueBeforeStep.Choices != null)
{
if (CompleteDialogue != null)
{
if (dialogueData.Choices.Count > 0)
{
if (dialogueData.Choices[0].NextDialogue == null)
dialogueData.Choices[0].SetNextDialogue(CompleteDialogue);
}
}
if (IncompleteDialogue != null)
{
if (dialogueData.Choices.Count > 1)
{
if (dialogueData.Choices[1].NextDialogue == null)
dialogueData.Choices[1].SetNextDialogue(IncompleteDialogue);
}
}
}
}
return dialogueData;
}
}

4
.DS_Store
文件差异内容过多而无法显示
查看文件

59
UOP1_Project/Assets/DialogueUSS.uss


Label#winDialogue {
margin-left: 5px;
margin-right: 5px;
margin-top: 5px;
margin-bottom: 5px;
background-color: rgb(158, 222, 115);
white-space: normal;
color: rgb(73, 94, 0);
}
Label#loseDialogue {
margin-left: 5px;
margin-right: 5px;
margin-top: 5px;
margin-bottom: 5px;
background-color: rgb(222, 115, 143);
white-space: normal;
color: rgb(89, 0, 9);
}
#Choices Button {
background-color: rgb(115, 115, 115);
}
Label#defaultDialogue {
margin-left: 5px;
margin-right: 5px;
margin-top: 5px;
margin-bottom: 5px;
background-color: rgb(209, 209, 209);
white-space: normal;
color: rgb(101, 101, 101);
}
Label#startDialogue {
margin-left: 5px;
margin-right: 5px;
margin-top: 5px;
margin-bottom: 5px;
background-color: rgb(209, 209, 209);
white-space: normal;
color: rgb(101, 101, 101);
}
#Dialogue {
align-items: stretch;
min-width: 50%;
}
#Choices {
align-items: stretch;
flex-direction: row;
justify-content: center;
}
#Choice {
align-items: stretch;
min-width: 50%;
}

11
UOP1_Project/Assets/DialogueUSS.uss.meta


fileFormatVersion: 2
guid: 33f1afe432a6d49bf91bda9df012a949
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0

8
UOP1_Project/Assets/ScriptableObjects/Quests/Questline1/Quest3/Step3.meta


fileFormatVersion: 2
guid: 7705ad9018dc044ae915f6d9a1a8c3e5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/ScriptableObjects/Quests/Questline3.meta


fileFormatVersion: 2
guid: cc0d7169fb8564bec9db9943e8075cb4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1
UOP1_Project/Assets/Scripts/Quests/.DS_Store
文件差异内容过多而无法显示
查看文件

36
UOP1_Project/Assets/Scripts/Quests/Editor/DialoguePreview.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.UIElements;
public class DialoguePreview : MonoBehaviour
{
private VisualElement CreateDialoguePreviewWithBranching(DialogueDataSO dialogueDataSO)
{
VisualElement dialoguePreviewVE = new VisualElement();
DialogueDataSO currentDialogue = dialogueDataSO;
foreach (LocalizedString localizedString in currentDialogue.DialogueLines)
{
Label dialogueLine = new Label();
dialogueLine.text = localizedString.GetLocalizedStringImmediateSafe();
dialoguePreviewVE.Add(dialogueLine);
}
if (currentDialogue.Choices != null)
{
foreach (Choice choice in currentDialogue.Choices)
{
Button dialogueButton = new Button();
dialogueButton.text = choice.Response.GetLocalizedStringImmediateSafe();
dialoguePreviewVE.Add(dialogueButton);
dialoguePreviewVE.Add(CreateDialoguePreviewWithBranching(choice.NextDialogue));
}
}
return dialoguePreviewVE;
}
}

11
UOP1_Project/Assets/Scripts/Quests/Editor/DialoguePreview.cs.meta


fileFormatVersion: 2
guid: 293d889c6c87c4f579c4dbc768dffba0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

17
UOP1_Project/Assets/ScriptableObjects/Quests/Questline3/QL3.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 05c700bba7d21604586cb89ec5afdee0, type: 3}
m_Name: QL3
m_EditorClassIdentifier:
_idQuestLine: 3
_quests: []
_isDone: 0

8
UOP1_Project/Assets/ScriptableObjects/Quests/Questline3/QL3.asset.meta


fileFormatVersion: 2
guid: b04857eeebf9c4cc28e25c95399ed0b4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存