wangguan
2020-12-28 e439d913a7094082f9618731bed68fe6634dfed0
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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("GiveUpBtn").GetComponent<Button>().onClick.AddListener(OnClickGiveUpBtn);
    }
 
    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 OnClickGiveUpBtn()
    {
        if (callBack != null)
        {
            string randomName = GetRandomName();
            callBack(randomName);
        }
        Destroy(gameObject);
    }
 
    private string GetRandomName()
    {
        // TimeSpan timeStamp = new TimeSpan(DateTime.Now.Ticks);
        // string s = timeStamp.TotalMilliseconds.ToString();
        // //s = "游客"+s.Replace()
        // DateTime dt = DateTime.Now;
        // Debug.Log(dt.ToString("fffff"));
        // s = DateTime.Now.ToString("fffff");
        return "游客" + DateTime.Now.ToString("fffff");
    }
 
 
}