question with multiple choise system
This commit is contained in:
+3043
-25
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6848174909d126243953a63d07976ac8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using Assets.Scripts.Actions;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[System.Serializable]
|
||||
public class ConversationChangeEvent : UnityEvent<BaseAction> { }
|
||||
|
||||
public class ChoiceController : MonoBehaviour
|
||||
{
|
||||
public KeyValuePair<string, BaseAction> _option;
|
||||
public ConversationChangeEvent conversationChangeEvent;
|
||||
// Update is called once per frame
|
||||
public static ChoiceController AddChoiceButton(Button choiceButtonTemplate, KeyValuePair<string, BaseAction> option, int index)
|
||||
{
|
||||
int buttonSpacing = -44;
|
||||
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.name = option.Key;
|
||||
button.gameObject.SetActive(true);
|
||||
|
||||
ChoiceController choiceController = button.GetComponent<ChoiceController>();
|
||||
choiceController._option = option;
|
||||
return choiceController;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (conversationChangeEvent == null)
|
||||
conversationChangeEvent = new ConversationChangeEvent();
|
||||
var btn = GetComponent<Button>();
|
||||
|
||||
var txt = btn.GetComponentInChildren<TextMeshProUGUI>();
|
||||
txt.text = _option.Key;
|
||||
}
|
||||
|
||||
public void MakeChoice()
|
||||
{
|
||||
conversationChangeEvent.Invoke(_option.Value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae1d8251da8585f4099dc5bdcf6d14d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
using Assets.Scripts.Actions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ConversationController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public TextMeshProUGUI _title;
|
||||
[SerializeField]
|
||||
public Button _choiceButton;
|
||||
|
||||
private List<ChoiceController> choiceControllers = new();
|
||||
public static ConversationController Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Change(string title, Dictionary<string, BaseAction> options)
|
||||
{
|
||||
RemoveChoices();
|
||||
_title.text = title;
|
||||
gameObject.SetActive(true);
|
||||
|
||||
for (var count = 0; count < options.Count; count++)
|
||||
{
|
||||
ChoiceController c = ChoiceController.AddChoiceButton(_choiceButton, options.ElementAt(count), count);
|
||||
choiceControllers.Add(c);
|
||||
}
|
||||
|
||||
_choiceButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void RemoveChoices()
|
||||
{
|
||||
foreach (ChoiceController c in choiceControllers)
|
||||
Destroy(c.gameObject);
|
||||
|
||||
choiceControllers.Clear();
|
||||
}
|
||||
public void Hide()
|
||||
{
|
||||
RemoveChoices();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 745fe52b243d8e947842f8f284e49aad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using Assets.Scripts.Actions;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class TestingQuestionDialog : MonoBehaviour
|
||||
{
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
YesNoDialogUI.Instance.ShowQuestion("To be or not to be ?",
|
||||
() =>
|
||||
{
|
||||
Application.Quit();
|
||||
EditorApplication.ExitPlaymode();
|
||||
},
|
||||
() =>
|
||||
{
|
||||
//do nothing
|
||||
});
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
Dictionary<string, BaseAction> optionsList = new Dictionary<string, BaseAction>
|
||||
{
|
||||
{ "Hamburgers - 83$", new Eat(null, 6, 1, 83) },
|
||||
{ "Cheesburger - 94$", new Eat(null, 6, 1, 94) },
|
||||
{ "Astro chicken - 131$", new Eat(null, 6, 1, 131) },
|
||||
{ "Fries - 68$", new Eat(null, 6, 1, 68) },
|
||||
{ "Shakes - 108$", new Eat(null, 6, 1, 108) },
|
||||
{ "Colas - 73$", new Eat(null, 6, 1, 73) }
|
||||
};
|
||||
ConversationController.Instance.Change("Monolith burger", optionsList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
|
||||
using System;
|
||||
using TMPro;
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class QuestionDialogUI : MonoBehaviour
|
||||
public class YesNoDialogUI : MonoBehaviour
|
||||
{
|
||||
public static QuestionDialogUI Instance { get; private set; }
|
||||
public static YesNoDialogUI Instance { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _textMeshPro;
|
||||
@@ -1,23 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class TestingQuestionDialog : MonoBehaviour
|
||||
{
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
QuestionDialogUI.Instance.ShowQuestion("To be or not to be ?",
|
||||
() =>
|
||||
{
|
||||
Application.Quit();
|
||||
EditorApplication.ExitPlaymode();
|
||||
},
|
||||
() =>
|
||||
{
|
||||
//do nothing
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user