You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.1 KiB
104 lines
2.1 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ConversationInput : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private InputField input;
|
|
|
|
private Animator animator;
|
|
|
|
public static ConversationInput Instance;
|
|
|
|
public string ReceptionStr; //接收 多个inputfield时的 答案
|
|
|
|
public bool k;
|
|
|
|
private void Start()
|
|
{
|
|
Instance = this;
|
|
input = this.transform.GetChild(0).GetComponent<InputField>();
|
|
animator = this.GetComponent<Animator>();
|
|
EventCenter.AddListener(EventType.ShowInput, ()=> {
|
|
Show();
|
|
|
|
});
|
|
EventCenter.AddListener(EventType.HideInput, () => {
|
|
Hide();
|
|
});
|
|
EventCenter.AddListener(EventType.ClearInput, () => {
|
|
Clear() ;
|
|
});
|
|
EventCenter.AddListener(EventType.AddAnswer, () => {
|
|
AddAnswer();
|
|
});
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void Show()
|
|
{
|
|
|
|
this.gameObject.SetActive(true);
|
|
|
|
if (animator != null)
|
|
{
|
|
|
|
animator.CrossFade("Show", 0.1f);
|
|
}
|
|
}
|
|
|
|
private void Hide()
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void Clear()
|
|
{
|
|
input.text="";
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 输入答案确定存储
|
|
/// </summary>
|
|
public void AddAnswer()
|
|
{
|
|
InputField[] myinput = GetComponentsInChildren<InputField>();
|
|
|
|
print(myinput.Length);
|
|
if (k)
|
|
{
|
|
for (int i = 0; i < myinput.Length; i++)
|
|
{
|
|
ReceptionStr += myinput[i].text;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < myinput.Length; i++)
|
|
{
|
|
ReceptionStr += myinput[i].text + "-";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// string answer = input.text;
|
|
|
|
string answer = ReceptionStr;
|
|
|
|
GameManager.Instance.AddAnswer(answer);
|
|
|
|
ReceptionStr = "";
|
|
|
|
print(this.gameObject.name);
|
|
}
|
|
|
|
|
|
}
|