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(); animator = this.GetComponent(); 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=""; } /// /// 输入答案确定存储 /// public void AddAnswer() { InputField[] myinput = GetComponentsInChildren(); 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); } }