剧情
This commit is contained in:
81
Assets/Scripts/Story/StoryUI/DialogUI/DialogContentFrame.cs
Normal file
81
Assets/Scripts/Story/StoryUI/DialogUI/DialogContentFrame.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using DG.Tweening.Core;
|
||||
using DG.Tweening.Plugins.Options;
|
||||
using I2.Loc;
|
||||
using Ichni.Story.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Story
|
||||
{
|
||||
public class DialogContentFrame : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
public GameObject textPrefab;
|
||||
public GameObject choiceGroupPrefab;
|
||||
|
||||
public RectTransform dialogContentContainer;
|
||||
public List<DialogTextUI> dialogTexts;
|
||||
public List<ChoiceGroupUI> choiceGroups;
|
||||
|
||||
public void PlaySentence(string speakerName, string content)
|
||||
{
|
||||
DialogTextUI dialogTextUI = Instantiate(textPrefab, dialogContentContainer).GetComponent<DialogTextUI>();
|
||||
dialogTextUI.speakerNameText.SetTerm("Characters/" + speakerName);
|
||||
dialogTextUI.contentText.SetTerm(StoryManager.instance.currentChapter +"/" +content);
|
||||
dialogTexts.Add(dialogTextUI);
|
||||
}
|
||||
|
||||
public ChoiceGroupUI PlayChoice(ChoiceGroup choiceGroup)
|
||||
{
|
||||
ChoiceGroupUI choiceGroupUI = Instantiate(choiceGroupPrefab, dialogContentContainer).GetComponent<ChoiceGroupUI>();
|
||||
choiceGroupUI.Initialize(choiceGroup);
|
||||
choiceGroups.Add(choiceGroupUI);
|
||||
|
||||
return choiceGroupUI;
|
||||
}
|
||||
|
||||
public void SelectChoice(ChoiceGroup choiceGroup, int index)
|
||||
{
|
||||
ChoiceGroupUI choiceGroupUI = PlayChoice(choiceGroup);
|
||||
for (var buttonIndex = 0; buttonIndex < choiceGroupUI.choiceButtonList.Count; buttonIndex++)
|
||||
{
|
||||
Button b = choiceGroupUI.choiceButtonList[buttonIndex];
|
||||
b.interactable = false;
|
||||
|
||||
if (buttonIndex == index)
|
||||
{
|
||||
b.image.color = Color.red;
|
||||
}
|
||||
}
|
||||
|
||||
DialogManager.instance.PlayNextDialogParagraph(choiceGroup.choices[index].nextDialogName, false);
|
||||
}
|
||||
|
||||
public void ClearAllSentences()
|
||||
{
|
||||
foreach (DialogTextUI dialogText in dialogTexts)
|
||||
{
|
||||
Destroy(dialogText.gameObject);
|
||||
}
|
||||
|
||||
foreach (ChoiceGroupUI choiceGroup in choiceGroups)
|
||||
{
|
||||
Destroy(choiceGroup.gameObject);
|
||||
}
|
||||
|
||||
dialogTexts.Clear();
|
||||
choiceGroups.Clear();
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
DialogManager.instance.PlayDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user