最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

unity教程:galgame對話框功能

2023-07-11 14:15 作者:塵風(fēng)一枚  | 我要投稿

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

using System.IO;


public class GalgameMnagaer : MonoBehaviour

{

//對話信息

[SerializeField]

private List<string> body;


[SerializeField]

//當(dāng)前是第幾段對話

private int index = 0;


//文本組件

private Text text;


[SerializeField]

//所有人物

private Galgame_Player[] player;


//組件初始化

private void Awake()

{

text = this.transform.parent.GetChild(2).GetChild(0).GetChild(0).gameObject.GetComponent<Text>();

}

//對象初始化

private void OnEnable()

{

body = InitBody();

}

//初始化對話內(nèi)容

private List<string> InitBody()

{

string vs = File.ReadAllText("D:\\unity\\new unity\\MVC cs\\Assets\\cs\\Galgame\\body\\body.txt");


string[] vs1 = vs.Split('\n');


List<string> vs2=new List<string>();


for (int i = 0; i < vs1.Length; i++)

{

vs1[i].Trim();


if (!(vs1[i].Length <2 || (vs1[i][0] + vs1[i][1].ToString()) == "//"))

{

vs2.Add(vs1[i]);

}

}


return vs2;

}


/// <summary>

/// 執(zhí)行下一段對話

/// </summary>

public void LoadNextBody()

{

try

{

index++;


string[] vs = body[index - 1].Split('#');


StopAllCoroutines();

StartCoroutine(ShowBody(vs[0]));


SwitchPlayer(player[int.Parse(vs[1])], vs[2], vs[3], vs[4], vs[5]);

}

catch

{

StopAllCoroutines();

StartCoroutine(ShowBody("發(fā)生錯誤"));

}

}


/// <summary>

/// 顯示內(nèi)容

/// </summary>

/// <param name="body">需要顯示的內(nèi)容</param>

private IEnumerator ShowBody(string body)

{

var time = new WaitForSecondsRealtime(0.05f);

text.text = string.Empty;

for (int i = 0; i < body.Length; i++)

{

text.text += body[i];

yield return time;

}

text.text += " ▼";

}


/// <summary>

/// 切換人物信息

/// </summary>

public void SwitchPlayer(Galgame_Player player, string acc, string hair, string body, string face)

{

if (this.player.Length == 0)

{

StopAllCoroutines();

StartCoroutine(ShowBody("發(fā)生錯誤,找不到人物"));

return;

}

try

{

Debug.Log("acc" + acc + "hair" + hair + "body" + body + "face" + face);

player.SwitchExpression(acc, hair, body, face);

}

catch

{

StopAllCoroutines();

StartCoroutine(ShowBody("發(fā)生錯誤,人物填寫錯誤"));

}

}

}


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Galgame_Player : MonoBehaviour

{

/// <summary>

/// 裝飾

/// </summary>

public SpriteRenderer Acc;

public Sprite acc1;

/// <summary>

/// 頭發(fā)

/// </summary>

public SpriteRenderer Hair;

public Sprite hair1;

public Sprite hair2;

/// <summary>

/// 衣服

/// </summary>

public SpriteRenderer Body;

public Sprite body1;

public Sprite body2;

/// <summary>

/// 表情

/// </summary>

public SpriteRenderer Face;

public Sprite face1;

public Sprite face2;

public Sprite face3;

public Sprite face4;


/// <summary>

/// 切換人物信息

/// </summary>

public void SwitchExpression(string acc,string hair,string body,string face)

{

switch (acc)

{

case "1":

Acc.sprite = acc1;

break;

default:

Acc.sprite = null;

break;

}

switch (hair)

{

case "1":

Hair.sprite = hair1;

break;

case "2":

Hair.sprite = hair2;

break;

default:

Hair.sprite = hair1;

break;

}

switch (body)

{

case "1":

Body.sprite = body1;

break;

case "2":

Body.sprite = body2;

break;

default:

Body.sprite = body1;

break;

}

switch (face)

{

case "1":

Debug.Log("cs1");

Face.sprite = face1;

break;

case "2":

Debug.Log("cs2");

Face.sprite = face2;

break;

case "3":

Debug.Log("cs3");

Face.sprite = face3;

break;

case "4":

Debug.Log("cs4");

Face.sprite = face4;

break;

default:

Debug.Log("cs0");

Face.sprite = face1;

break;

}

}

}

unity教程:galgame對話框功能的評論 (共 條)

分享到微博請遵守國家法律
手游| 松桃| 北票市| 邯郸市| 织金县| 高尔夫| 汉川市| 青海省| 兖州市| 班戈县| 连平县| 涪陵区| 宜城市| 类乌齐县| 延长县| 寻乌县| 平邑县| 金阳县| 赫章县| 南和县| 松原市| 竹北市| 东莞市| 安阳县| 吴江市| 泰来县| 阜城县| 太保市| 海口市| 萍乡市| 维西| 黎平县| 开平市| 徐水县| 墨竹工卡县| 高安市| 文山县| 班戈县| 松滋市| 哈巴河县| 巴南区|