Roman 8fc1bff703 1.添加了新场景序章-回忆
2.添加了电话线框架
3.添加了电话线进度条框架
4.完成了电报机线路检查系统
2021-07-04 01:00:01 +08:00

90 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Machine : Interactive
{
// Start is called before the first frame update
private Text codeTextView;
private IndexRecoder indexRecoder;
private AllLinesInfo linesChecker;
void Start()
{
//m_interface = GameObject.Find("MachinePanel");
codeTextView = m_interface.GetComponentInChildren<Text>();
indexRecoder = FindObjectOfType<IndexRecoder>();
linesChecker = FindObjectOfType<AllLinesInfo>();
}
// Update is called once per frame
void Update()
{
}
public override void OnCall()
{
if(LinesCheck())//如果线路全通
{
m_interface.SetActive(true);
}
else
{
Debug.Log("还有线路没通");
}
}
private bool LinesCheck()
{
if(linesChecker.needCount == linesChecker.OKCount) return true;
else return false;
}
//从Player类发消息来调用这个函数temp为接受到的字符可能是. || -。
public override void Coding(string temp)
{
codeTextView.text += temp;//给当前输入总体加上刚输入的字符
if(codeTextView.text.Length >= 8) ClearChecker(codeTextView.text);//当长度超过8位每打一位就检查一下是否有连续的八个点
if(codeTextView.text.Length % 4 == 0) Translate(codeTextView.text);//每输入四位就翻译一下
}
//译者函数。输入一串字符串在这里会对照数值记录者中的codeBook翻译没有的code会被翻译成X
//每当输入总体的长度是四的倍数的时候才会调用这个翻译函数因为每个汉字单元都是4位
private void Translate(string code)
{
string result = "";
for(int i = 0; i < code.Length/4; i++)
{
string temp = code.Substring(i*4,4);
try{
result += indexRecoder.codeBook[temp];
}
catch
{
//Debug.Log("字典里没找到这个字,我得给翻译结果里加个叉叉");
result += "X";
}
}
Debug.Log("翻译的结果是:"+result);
}
//清除检查者函数。从自身Codeing函数调用每次有新字符输入的时候就调用。
//检查输入总体中是否存在连续的八个点,有则清空当前输入的所有东西
private void ClearChecker(string code)
{
int hasClearer = code.IndexOf("........");
if(hasClearer != -1)
{
codeTextView.text = "";
Debug.Log("检查到连续的八个点,清除所有输入内容");
}
}
}