主要展示剧情部分
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class TextViewer : PlotTexts
{
public GameObject PlotShower,PlotChooser;
public Image CG;
public Text Name, Talk;
private void Awake()
{
}
private void Update()
{
if (Plots.Count>0)
{
PlotShower.SetActive(true);
Ploting();
}
else
{
PlotShower.SetActive(false);
}
}
public void Ploting()
{
Debug.Log(Plots.Count);
CG.sprite = Plots[0].TalkCg;
Name.text = Plots[0].Name;
Talk.text = Plots[0].Say;
if (Plots.Count>0&&Plots[0].PlotEvent==0)
{
PlotChooser.SetActive(false);
if (Input.GetMouseButtonDown(0))
{
Plots.RemoveAt(0);
}
}
else if (Plots[0].PlotEvent!=0)
{
PlotEvents(Plots[0].PlotEvent);
}
}
public void PlotEvents(int index)
{
Choose('A').onClick.RemoveAllListeners();
Choose('B').onClick.RemoveAllListeners();
switch (index)
{
case 1:
PlotChooser.SetActive(true);
Choose('A').onClick.AddListener(() =>
{
Plots.RemoveAt(0);
SceneManager.LoadScene("Battle");
});
Choose('B').onClick.AddListener(() =>
{
Plots.RemoveAt(0);
Plots.Add(new Plot(){PlotEvent = 0,Say = "测试剧情选项B",Name = "测试人"});
Plots.Add(new Plot(){PlotEvent = 0,Say = "测试剧情选项B第二句",Name = "测试人"});
});
break;
case -1:
{
if (Input.GetMouseButtonDown(0))
{
Plots.RemoveAt(0);
SceneManager.LoadScene("Main");
}
}
break;
case -2:
{
if (Input.GetMouseButtonDown(0))
{ Plots.RemoveAt(0);
SceneManager.LoadScene("Main");
}
}
break;
}
Button Choose(char finder)
{
if (finder=='A')
{
return PlotChooser.transform.Find("A").GetComponent<Button>();
}
else
{
return PlotChooser.transform.Find("B").GetComponent<Button>();
}
}
}
}
剧本存储部分
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlotTexts : MonoBehaviour
{
public struct Plot
{
public int PlotEvent;
public string Say;
public string Name;
public Sprite TalkCg;
}
public static List<Plot> Plots=new List<Plot>();
public static void PlotAdder(int index)
{
switch (index)
{
case 1: Plots.Add(new Plot(){PlotEvent = 0,Say