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");
|
}
|
|
|
}
|