wangguan
2020-12-04 06facfa32a388f74c6eba139e1a8fe4700307a6e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class InputNamePanel : MonoBehaviour
{
    private InputField input;
 
    private Action<string> callBack;
 
    // Start is called before the first frame update
    void Start()
    {
        input = transform.Find("InputFieldName").GetComponent<InputField>();
        transform.Find("OKBtn").GetComponent<Button>().onClick.AddListener(OnClickOKBtn);
        transform.Find("ResetNameBtn").GetComponent<Button>().onClick.AddListener(OnClickResetBtn);
    }
 
    public void Init(Action<string> ac)
    {
        callBack = ac;
    }
 
    private void OnClickOKBtn()
    {
        if (input.text != "")
        {
            if (callBack != null)
            {
                callBack(input.text);
            }
            Destroy(gameObject);
        }
        else
        {
            Debug.Log("没有输入名字");
        }
 
    }
 
    private void OnClickResetBtn()
    {
        input.text = "";
    }
 
 
}