From 80df6bde42bf3f7264ffc884e1042b8cf437ad03 Mon Sep 17 00:00:00 2001 From: voffka81 <84612470+voffka81@users.noreply.github.com> Date: Thu, 18 Aug 2022 13:01:25 +0300 Subject: [PATCH] fix conversation dialog --- Assets/Scenes/SampleScene.unity | 93 ++++++++++--------- .../DialogueSystem/ChoiceController.cs | 6 +- .../DialogueSystem/ConversationController.cs | 11 +++ 3 files changed, 65 insertions(+), 45 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index c8987da9..0b8619f0 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -148,7 +148,7 @@ RectTransform: m_GameObject: {fileID: 26194717} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 4.8501, y: 3.7125, z: 1} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 353014638} @@ -157,9 +157,9 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 100, y: 100} - m_Pivot: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -246, y: -225} + m_SizeDelta: {x: 492, y: 420} + m_Pivot: {x: 0, y: 0} --- !u!1 &94928690 GameObject: m_ObjectHideFlags: 0 @@ -284,10 +284,10 @@ RectTransform: m_Father: {fileID: 1928618662} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -151, y: 234} - m_SizeDelta: {x: 200, y: 50} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: -25} + m_SizeDelta: {x: 0, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &107380538 MonoBehaviour: @@ -372,7 +372,7 @@ MonoBehaviour: m_VertexBufferAutoSizeReduction: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 - m_margin: {x: 0, y: 0, z: -297.24536, w: 0} + m_margin: {x: 0, y: 0, z: -1.1646118, w: 0} m_isUsingLegacyAnimationComponent: 0 m_isVolumetricText: 0 m_hasFontAssetChanged: 0 @@ -2959,7 +2959,7 @@ RectTransform: m_GameObject: {fileID: 353014637} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.5, y: 0.5, z: 1} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1496617599} @@ -2968,8 +2968,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 160, y: 30} + m_AnchoredPosition: {x: 0, y: 195} + m_SizeDelta: {x: 492, y: 30} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &353014639 MonoBehaviour: @@ -3014,7 +3014,19 @@ MonoBehaviour: m_TargetGraphic: {fileID: 353014640} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 11500000, guid: 745fe52b243d8e947842f8f284e49aad, type: 3} + m_TargetAssemblyTypeName: ChoiceController, Assembly-CSharp + m_MethodName: + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &353014640 MonoBehaviour: m_ObjectHideFlags: 0 @@ -3035,7 +3047,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Sprite: {fileID: 0} m_Type: 1 m_PreserveAspect: 0 m_FillCenter: 1 @@ -3067,7 +3079,19 @@ MonoBehaviour: m_EditorClassIdentifier: conversationChangeEvent: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 11500000, guid: 745fe52b243d8e947842f8f284e49aad, type: 3} + m_TargetAssemblyTypeName: UnityEngine.Object, UnityEngine + m_MethodName: set_name + m_Mode: 5 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: Hide(); + m_BoolArgument: 0 + m_CallState: 2 --- !u!1 &448269316 GameObject: m_ObjectHideFlags: 0 @@ -4455,7 +4479,7 @@ RectTransform: - {fileID: 1524120978} - {fileID: 1267368772} m_Father: {fileID: 2137624722} - m_RootOrder: 0 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -5870,12 +5894,12 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 24 - m_fontSizeBase: 24 + m_fontSize: 18 + m_fontSizeBase: 8 m_fontWeight: 400 - m_enableAutoSizing: 0 - m_fontSizeMin: 18 - m_fontSizeMax: 72 + m_enableAutoSizing: 1 + m_fontSizeMin: 15 + m_fontSizeMax: 18 m_fontStyle: 0 m_HorizontalAlignment: 2 m_VerticalAlignment: 512 @@ -6418,7 +6442,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2137624722} - m_RootOrder: 2 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -6762,7 +6786,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1928618662} - - component: {fileID: 1928618663} m_Layer: 5 m_Name: Conversation m_TagString: Untagged @@ -6791,23 +6814,9 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -26.218018, y: -20.2967} - m_SizeDelta: {x: 512.4757, y: 528.4197} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!114 &1928618663 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1928618661} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 745fe52b243d8e947842f8f284e49aad, type: 3} - m_Name: - m_EditorClassIdentifier: - _title: {fileID: 107380538} - _choiceButton: {fileID: 353014639} + m_AnchoredPosition: {x: -256, y: -265} + m_SizeDelta: {x: 512, y: 530} + m_Pivot: {x: 0, y: 0} --- !u!1 &2045246561 GameObject: m_ObjectHideFlags: 0 @@ -6840,7 +6849,7 @@ RectTransform: - {fileID: 1205079055} - {fileID: 530701384} m_Father: {fileID: 2137624722} - m_RootOrder: 1 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -7304,9 +7313,9 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 1682316606} - {fileID: 1024192185} - {fileID: 2045246562} - - {fileID: 1682316606} - {fileID: 2068384141} m_Father: {fileID: 329780516} m_RootOrder: 1 diff --git a/Assets/Scripts/DialogueSystem/ChoiceController.cs b/Assets/Scripts/DialogueSystem/ChoiceController.cs index 2954b35f..1ac008db 100644 --- a/Assets/Scripts/DialogueSystem/ChoiceController.cs +++ b/Assets/Scripts/DialogueSystem/ChoiceController.cs @@ -15,15 +15,15 @@ public class ChoiceController : MonoBehaviour // Update is called once per frame public static ChoiceController AddChoiceButton(Button choiceButtonTemplate, KeyValuePair option, int index) { - int buttonSpacing = -44; + int buttonSpacing = -50; + Button button = Instantiate(choiceButtonTemplate); button.transform.SetParent(choiceButtonTemplate.transform.parent); button.transform.localScale = Vector3.one; - button.transform.localPosition = new Vector3(0, index * buttonSpacing, 0); + button.transform.localPosition = choiceButtonTemplate.transform.localPosition + new Vector3(0, index * buttonSpacing, 0); button.name = option.Key; button.gameObject.SetActive(true); - ChoiceController choiceController = button.GetComponent(); choiceController._option = option; return choiceController; diff --git a/Assets/Scripts/DialogueSystem/ConversationController.cs b/Assets/Scripts/DialogueSystem/ConversationController.cs index efae9a1b..2afce40e 100644 --- a/Assets/Scripts/DialogueSystem/ConversationController.cs +++ b/Assets/Scripts/DialogueSystem/ConversationController.cs @@ -12,6 +12,9 @@ public class ConversationController : MonoBehaviour [SerializeField] public Button _choiceButton; + [SerializeField] + private Button _closeBtn; + private List choiceControllers = new(); public static ConversationController Instance { get; private set; } @@ -32,10 +35,17 @@ public class ConversationController : MonoBehaviour ChoiceController c = ChoiceController.AddChoiceButton(_choiceButton, options.ElementAt(count), count); choiceControllers.Add(c); } + _closeBtn.onClick.AddListener(() => + { + Hide(); + }); + Time.timeScale = 0; _choiceButton.gameObject.SetActive(false); } + + private void RemoveChoices() { foreach (ChoiceController c in choiceControllers) @@ -47,5 +57,6 @@ public class ConversationController : MonoBehaviour { RemoveChoices(); gameObject.SetActive(false); + Time.timeScale = 1; } }