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.
55 lines
1.6 KiB
55 lines
1.6 KiB
// --------------------------------------------------------------------------------------------------------------------
|
|
// <copyright company="Exit Games GmbH"/>
|
|
// <summary>Demo code for Photon Chat in Unity.</summary>
|
|
// <author>developer@exitgames.com</author>
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
namespace Photon.Chat.Demo
|
|
{
|
|
[RequireComponent(typeof(ChatGui))]
|
|
public class NamePickGui : MonoBehaviour
|
|
{
|
|
private const string UserNamePlayerPref = "NamePickUserName";
|
|
|
|
public ChatGui chatNewComponent;
|
|
|
|
public InputField idInput;
|
|
|
|
public void Start()
|
|
{
|
|
this.chatNewComponent = FindObjectOfType<ChatGui>();
|
|
|
|
|
|
string prefsName = PlayerPrefs.GetString(UserNamePlayerPref);
|
|
if (!string.IsNullOrEmpty(prefsName))
|
|
{
|
|
this.idInput.text = prefsName;
|
|
}
|
|
}
|
|
|
|
|
|
// new UI will fire "EndEdit" event also when loosing focus. So check "enter" key and only then StartChat.
|
|
public void EndEditOnEnter()
|
|
{
|
|
if (Input.GetKey(KeyCode.Return) || Input.GetKey(KeyCode.KeypadEnter))
|
|
{
|
|
this.StartChat();
|
|
}
|
|
}
|
|
|
|
public void StartChat()
|
|
{
|
|
ChatGui chatNewComponent = FindObjectOfType<ChatGui>();
|
|
chatNewComponent.UserName = this.idInput.text.Trim();
|
|
chatNewComponent.Connect();
|
|
this.enabled = false;
|
|
|
|
PlayerPrefs.SetString(UserNamePlayerPref, chatNewComponent.UserName);
|
|
}
|
|
}
|
|
} |