온라인 구현
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat
|
||||
{
|
||||
public class ChannelSelector : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
public string Channel;
|
||||
|
||||
public void SetChannel(string channel)
|
||||
{
|
||||
this.Channel = channel;
|
||||
Text t = GetComponentInChildren<Text>();
|
||||
t.text = this.Channel;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
ChatNewGui handler = GameObject.FindFirstObjectByType<ChatNewGui>();
|
||||
#else
|
||||
ChatNewGui handler = FindObjectOfType<ChatNewGui>();
|
||||
#endif
|
||||
handler.ShowChannel(this.Channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48caa72710147fc4f9389b0b5ec6137d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/ChannelSelector.cs
|
||||
uploadId: 817708
|
||||
651
Assets/Photon/PhotonChat/Demos/Demo Chat/Code/ChatNewGui.cs
Normal file
651
Assets/Photon/PhotonChat/Demos/Demo Chat/Code/ChatNewGui.cs
Normal file
@@ -0,0 +1,651 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat
|
||||
{
|
||||
/// <summary>
|
||||
/// This simple Chat UI demonstrate basics usages of the Chat Api
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The ChatClient basically lets you create any number of channels.
|
||||
///
|
||||
/// some friends are already set in the Chat demo "DemoChat-Scene", 'Joe', 'Jane' and 'Bob', simply log with them so that you can see the status changes in the Interface
|
||||
///
|
||||
/// Workflow:
|
||||
/// Create ChatClient, Connect to a server with your AppID, Authenticate the user (apply a unique name,)
|
||||
/// and subscribe to some channels.
|
||||
/// Subscribe a channel before you publish to that channel!
|
||||
///
|
||||
///
|
||||
/// Note:
|
||||
/// Don't forget to call ChatClient.Service() on Update to keep the Chatclient operational.
|
||||
/// </remarks>
|
||||
public class ChatNewGui : MonoBehaviour, IChatClientListener
|
||||
{
|
||||
public string[] ChannelsToJoinOnConnect; // set in inspector. Demo channels to join automatically.
|
||||
|
||||
public string[] FriendsList; // this is a hidden inspector field! use debug mode to see and edit it
|
||||
|
||||
public int HistoryLengthToFetch; // set in inspector. Up to a certain degree, previously sent messages can be fetched for context
|
||||
|
||||
public string UserName { get; set; }
|
||||
|
||||
private string selectedChannelName; // mainly used for GUI/input
|
||||
|
||||
public ChatClient chatClient;
|
||||
|
||||
public GameObject ConnectingLabel;
|
||||
|
||||
public RectTransform ChatPanel; // set in inspector (to enable/disable panel)
|
||||
public GameObject UserIdFormPanel;
|
||||
public InputField InputFieldChat; // set in inspector
|
||||
public Text CurrentChannelText; // set in inspector
|
||||
public Toggle ChannelToggleToInstantiate; // set in inspector
|
||||
|
||||
|
||||
public GameObject FriendListUiItemtoInstantiate;
|
||||
|
||||
private readonly Dictionary<string, Toggle> channelToggles = new Dictionary<string, Toggle>();
|
||||
|
||||
private readonly Dictionary<string, FriendItem> friendListItemLUT = new Dictionary<string, FriendItem>();
|
||||
|
||||
public bool ShowState = true;
|
||||
public GameObject Title;
|
||||
public Text StateText; // set in inspector
|
||||
public Text UserIdText; // set in inspector
|
||||
|
||||
// private static string WelcomeText = "Welcome to chat. Type \\help to list commands.";
|
||||
private static string HelpText = "\n -- HELP --\n" +
|
||||
"To subscribe to channel(s):\n" +
|
||||
"\t<color=#E07B00>\\subscribe</color> <color=green><list of channelnames></color>\n" +
|
||||
"\tor\n" +
|
||||
"\t<color=#E07B00>\\s</color> <color=green><list of channelnames></color>\n" +
|
||||
"\n" +
|
||||
"To leave channel(s):\n" +
|
||||
"\t<color=#E07B00>\\unsubscribe</color> <color=green><list of channelnames></color>\n" +
|
||||
"\tor\n" +
|
||||
"\t<color=#E07B00>\\u</color> <color=green><list of channelnames></color>\n" +
|
||||
"\n" +
|
||||
"To switch the active channel\n" +
|
||||
"\t<color=#E07B00>\\join</color> <color=green><channelname></color>\n" +
|
||||
"\tor\n" +
|
||||
"\t<color=#E07B00>\\j</color> <color=green><channelname></color>\n" +
|
||||
"\n" +
|
||||
"To send a private message:\n" +
|
||||
"\t\\<color=#E07B00>msg</color> <color=green><username></color> <color=green><message></color>\n" +
|
||||
"\n" +
|
||||
"To add friend(s):\n" +
|
||||
"\t\\<color=#E07B00>friend</color> <color=green><username></color> [<color=green><username></color>]\n" +
|
||||
"\n" +
|
||||
"To remove friend(s):\n" +
|
||||
"\t\\<color=#E07B00>unfriend</color> <color=green><username></color> [<color=green><username></color>]\n" +
|
||||
"\n" +
|
||||
"To change status:\n" +
|
||||
"\t\\<color=#E07B00>state</color> <color=green><stateIndex></color> <color=green><message></color>\n" +
|
||||
"<color=green>0</color> = Offline " +
|
||||
"<color=green>1</color> = Invisible " +
|
||||
"<color=green>2</color> = Online " +
|
||||
"<color=green>3</color> = Away \n" +
|
||||
"<color=green>4</color> = Do not disturb " +
|
||||
"<color=green>5</color> = Looking For Group " +
|
||||
"<color=green>6</color> = Playing" +
|
||||
"\n\n" +
|
||||
"To clear the current chat tab (private chats get closed):\n" +
|
||||
"\t<color=#E07B00>\\clear</color>";
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
|
||||
UserIdText.text = "";
|
||||
StateText.text = "";
|
||||
StateText.gameObject.SetActive(true);
|
||||
UserIdText.gameObject.SetActive(true);
|
||||
Title.SetActive(true);
|
||||
ChatPanel.gameObject.SetActive(false);
|
||||
ConnectingLabel.SetActive(false);
|
||||
|
||||
if (string.IsNullOrEmpty(UserName))
|
||||
{
|
||||
UserName = "user" + Environment.TickCount % 99; //made-up username
|
||||
}
|
||||
|
||||
this.UserIdFormPanel.gameObject.SetActive(true);
|
||||
|
||||
if (string.IsNullOrEmpty(ChatSettings.Instance.AppId))
|
||||
{
|
||||
Debug.LogError("You need to set the chat app ID in the PhotonServerSettings file in order to continue.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
this.UserIdFormPanel.gameObject.SetActive(false);
|
||||
|
||||
this.chatClient = new ChatClient(this);
|
||||
|
||||
#if UNITY_WEBGL
|
||||
this.chatClient.UseBackgroundWorkerForSending = false;
|
||||
#else
|
||||
this.chatClient.UseBackgroundWorkerForSending = true;
|
||||
#endif
|
||||
|
||||
this.chatClient.Connect(ChatSettings.Instance.AppId, "1.0", new AuthenticationValues(UserName));
|
||||
|
||||
this.ChannelToggleToInstantiate.gameObject.SetActive(false);
|
||||
Debug.Log("Connecting as: " + UserName);
|
||||
|
||||
ConnectingLabel.SetActive(true);
|
||||
}
|
||||
|
||||
/// <summary>To avoid that the Editor becomes unresponsive, disconnect all Photon connections in OnDestroy.</summary>
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (this.chatClient != null)
|
||||
{
|
||||
this.chatClient.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>To avoid that the Editor becomes unresponsive, disconnect all Photon connections in OnApplicationQuit.</summary>
|
||||
public void OnApplicationQuit()
|
||||
{
|
||||
if (this.chatClient != null)
|
||||
{
|
||||
this.chatClient.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (this.chatClient != null)
|
||||
{
|
||||
this.chatClient.Service(); // make sure to call this regularly! it limits effort internally, so calling often is ok!
|
||||
}
|
||||
|
||||
// check if we are missing context, which means we got kicked out to get back to the Photon Demo hub.
|
||||
if (this.StateText == null)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
this.StateText.gameObject.SetActive(ShowState); // this could be handled more elegantly, but for the demo it's ok.
|
||||
}
|
||||
|
||||
|
||||
public void OnEnterSend()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Return) || Input.GetKey(KeyCode.KeypadEnter))
|
||||
{
|
||||
SendChatMessage(this.InputFieldChat.text);
|
||||
this.InputFieldChat.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClickSend()
|
||||
{
|
||||
if (this.InputFieldChat != null)
|
||||
{
|
||||
SendChatMessage(this.InputFieldChat.text);
|
||||
this.InputFieldChat.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int TestLength = 2048;
|
||||
private byte[] testBytes = new byte[2048];
|
||||
|
||||
private void SendChatMessage(string inputLine)
|
||||
{
|
||||
if (string.IsNullOrEmpty(inputLine))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ("test".Equals(inputLine))
|
||||
{
|
||||
if (this.TestLength != this.testBytes.Length)
|
||||
{
|
||||
this.testBytes = new byte[this.TestLength];
|
||||
}
|
||||
|
||||
this.chatClient.SendPrivateMessage(this.chatClient.AuthValues.UserId, testBytes, true);
|
||||
}
|
||||
|
||||
|
||||
bool doingPrivateChat = this.chatClient.PrivateChannels.ContainsKey(this.selectedChannelName);
|
||||
string privateChatTarget = string.Empty;
|
||||
if (doingPrivateChat)
|
||||
{
|
||||
// the channel name for a private conversation is (on the client!!) always composed of both user's IDs: "this:remote"
|
||||
// so the remote ID is simple to figure out
|
||||
|
||||
string[] splitNames = this.selectedChannelName.Split(new char[] { ':' });
|
||||
privateChatTarget = splitNames[1];
|
||||
}
|
||||
//UnityEngine.Debug.Log("selectedChannelName: " + selectedChannelName + " doingPrivateChat: " + doingPrivateChat + " privateChatTarget: " + privateChatTarget);
|
||||
|
||||
|
||||
if (inputLine[0].Equals('\\'))
|
||||
{
|
||||
string[] tokens = inputLine.Split(new char[] { ' ' }, 2);
|
||||
if (tokens[0].Equals("\\help"))
|
||||
{
|
||||
PostHelpToCurrentChannel();
|
||||
}
|
||||
|
||||
if (tokens[0].Equals("\\state"))
|
||||
{
|
||||
int newState = 0;
|
||||
|
||||
|
||||
List<string> messages = new List<string>();
|
||||
messages.Add("i am state " + newState);
|
||||
string[] subtokens = tokens[1].Split(new char[] { ' ', ',' });
|
||||
|
||||
if (subtokens.Length > 0)
|
||||
{
|
||||
newState = int.Parse(subtokens[0]);
|
||||
}
|
||||
|
||||
if (subtokens.Length > 1)
|
||||
{
|
||||
messages.Add(subtokens[1]);
|
||||
}
|
||||
|
||||
this.chatClient.SetOnlineStatus(newState, messages.ToArray()); // this is how you set your own state and (any) message
|
||||
}
|
||||
else if ((tokens[0].Equals("\\subscribe") || tokens[0].Equals("\\s")) && !string.IsNullOrEmpty(tokens[1]))
|
||||
{
|
||||
this.chatClient.Subscribe(tokens[1].Split(new char[] { ' ', ',' }));
|
||||
}
|
||||
else if ((tokens[0].Equals("\\unsubscribe") || tokens[0].Equals("\\u")) && !string.IsNullOrEmpty(tokens[1]))
|
||||
{
|
||||
this.chatClient.Unsubscribe(tokens[1].Split(new char[] { ' ', ',' }));
|
||||
}
|
||||
else if (tokens[0].Equals("\\clear"))
|
||||
{
|
||||
if (doingPrivateChat)
|
||||
{
|
||||
this.chatClient.PrivateChannels.Remove(this.selectedChannelName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatChannel channel;
|
||||
if (this.chatClient.TryGetChannel(this.selectedChannelName, doingPrivateChat, out channel))
|
||||
{
|
||||
channel.ClearMessages();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tokens[0].Equals("\\msg") && !string.IsNullOrEmpty(tokens[1]))
|
||||
{
|
||||
string[] subtokens = tokens[1].Split(new char[] { ' ', ',' }, 2);
|
||||
if (subtokens.Length < 2)
|
||||
return;
|
||||
|
||||
string targetUser = subtokens[0];
|
||||
string message = subtokens[1];
|
||||
this.chatClient.SendPrivateMessage(targetUser, message);
|
||||
}
|
||||
else if ((tokens[0].Equals("\\join") || tokens[0].Equals("\\j")) && !string.IsNullOrEmpty(tokens[1]))
|
||||
{
|
||||
string[] subtokens = tokens[1].Split(new char[] { ' ', ',' }, 2);
|
||||
|
||||
// If we are already subscribed to the channel we directly switch to it, otherwise we subscribe to it first and then switch to it implicitly
|
||||
if (channelToggles.ContainsKey(subtokens[0]))
|
||||
{
|
||||
ShowChannel(subtokens[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.chatClient.Subscribe(new string[] { subtokens[0] });
|
||||
}
|
||||
}
|
||||
else if (tokens[0].Equals("\\friend") && !string.IsNullOrEmpty(tokens[1]))
|
||||
{
|
||||
string[] friends = tokens[1].Split(new char[] { ' ', ',' });
|
||||
|
||||
Debug.Log("Adding friends (" + friends.Length + "): " + string.Join(",", friends));
|
||||
this.chatClient.AddFriends(friends);
|
||||
foreach (string _friend in friends)
|
||||
{
|
||||
if (this.FriendListUiItemtoInstantiate != null && _friend != this.UserName)
|
||||
{
|
||||
this.InstantiateFriendButton(_friend);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tokens[0].Equals("\\unfriend") && !string.IsNullOrEmpty(tokens[1]))
|
||||
{
|
||||
string[] friends = tokens[1].Split(new char[] { ' ', ',' });
|
||||
|
||||
Debug.Log("Removing friends (" + friends.Length + "): " + string.Join(",", friends));
|
||||
this.chatClient.RemoveFriends(friends);
|
||||
foreach (string _friend in friends)
|
||||
{
|
||||
if (this.FriendListUiItemtoInstantiate != null && _friend != this.UserName)
|
||||
{
|
||||
this.DestroyFriendButton(_friend);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("The command '" + tokens[0] + "' is invalid.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (doingPrivateChat)
|
||||
{
|
||||
this.chatClient.SendPrivateMessage(privateChatTarget, inputLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.chatClient.PublishMessage(this.selectedChannelName, inputLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PostHelpToCurrentChannel()
|
||||
{
|
||||
this.CurrentChannelText.text += HelpText;
|
||||
}
|
||||
|
||||
public void DebugReturn(ExitGames.Client.Photon.DebugLevel level, string message)
|
||||
{
|
||||
if (level == ExitGames.Client.Photon.DebugLevel.ERROR)
|
||||
{
|
||||
UnityEngine.Debug.LogError(message);
|
||||
}
|
||||
else if (level == ExitGames.Client.Photon.DebugLevel.WARNING)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnConnected()
|
||||
{
|
||||
if (this.ChannelsToJoinOnConnect != null && this.ChannelsToJoinOnConnect.Length > 0)
|
||||
{
|
||||
this.chatClient.Subscribe(this.ChannelsToJoinOnConnect, this.HistoryLengthToFetch);
|
||||
}
|
||||
|
||||
ConnectingLabel.SetActive(false);
|
||||
|
||||
UserIdText.text = "Connected as " + this.UserName;
|
||||
|
||||
this.ChatPanel.gameObject.SetActive(true);
|
||||
|
||||
if (FriendsList != null && FriendsList.Length > 0)
|
||||
{
|
||||
this.chatClient.AddFriends(FriendsList); // Add some users to the server-list to get their status updates
|
||||
|
||||
// add to the UI as well
|
||||
foreach (string _friend in FriendsList)
|
||||
{
|
||||
if (this.FriendListUiItemtoInstantiate != null && _friend != this.UserName)
|
||||
{
|
||||
this.InstantiateFriendButton(_friend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.FriendListUiItemtoInstantiate != null)
|
||||
{
|
||||
this.FriendListUiItemtoInstantiate.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
this.chatClient.SetOnlineStatus(ChatUserStatus.Online); // You can set your online state (without a mesage).
|
||||
}
|
||||
|
||||
public void OnDisconnected()
|
||||
{
|
||||
ConnectingLabel.SetActive(false);
|
||||
}
|
||||
|
||||
public void OnChatStateChange(ChatState state)
|
||||
{
|
||||
// use OnConnected() and OnDisconnected()
|
||||
// this method might become more useful in the future, when more complex states are being used.
|
||||
|
||||
this.StateText.text = state.ToString();
|
||||
}
|
||||
|
||||
public void OnSubscribed(string[] channels, bool[] results)
|
||||
{
|
||||
// in this demo, we simply send a message into each channel. This is NOT a must have!
|
||||
foreach (string channel in channels)
|
||||
{
|
||||
this.chatClient.PublishMessage(channel, "says 'hi'."); // you don't HAVE to send a msg on join but you could.
|
||||
|
||||
if (this.ChannelToggleToInstantiate != null)
|
||||
{
|
||||
this.InstantiateChannelButton(channel);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log("OnSubscribed: " + string.Join(", ", channels));
|
||||
|
||||
/*
|
||||
// select first subscribed channel in alphabetical order
|
||||
if (this.chatClient.PublicChannels.Count > 0)
|
||||
{
|
||||
var l = new List<string>(this.chatClient.PublicChannels.Keys);
|
||||
l.Sort();
|
||||
string selected = l[0];
|
||||
if (this.channelToggles.ContainsKey(selected))
|
||||
{
|
||||
ShowChannel(selected);
|
||||
foreach (var c in this.channelToggles)
|
||||
{
|
||||
c.Value.isOn = false;
|
||||
}
|
||||
this.channelToggles[selected].isOn = true;
|
||||
AddMessageToSelectedChannel(WelcomeText);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Switch to the first newly created channel
|
||||
ShowChannel(channels[0]);
|
||||
}
|
||||
|
||||
private void InstantiateChannelButton(string channelName)
|
||||
{
|
||||
if (this.channelToggles.ContainsKey(channelName))
|
||||
{
|
||||
Debug.Log("Skipping creation for an existing channel toggle.");
|
||||
return;
|
||||
}
|
||||
|
||||
Toggle cbtn = (Toggle)GameObject.Instantiate(this.ChannelToggleToInstantiate);
|
||||
cbtn.gameObject.SetActive(true);
|
||||
cbtn.GetComponentInChildren<ChannelSelector>().SetChannel(channelName);
|
||||
cbtn.transform.SetParent(this.ChannelToggleToInstantiate.transform.parent, false);
|
||||
|
||||
this.channelToggles.Add(channelName, cbtn);
|
||||
}
|
||||
|
||||
private void InstantiateFriendButton(string friendId)
|
||||
{
|
||||
GameObject fbtn = (GameObject)GameObject.Instantiate(this.FriendListUiItemtoInstantiate);
|
||||
fbtn.gameObject.SetActive(true);
|
||||
FriendItem _friendItem = fbtn.GetComponent<FriendItem>();
|
||||
|
||||
_friendItem.FriendId = friendId;
|
||||
|
||||
fbtn.transform.SetParent(this.FriendListUiItemtoInstantiate.transform.parent, false);
|
||||
|
||||
this.friendListItemLUT[friendId] = _friendItem;
|
||||
}
|
||||
|
||||
private void DestroyFriendButton(string friendId)
|
||||
{
|
||||
if (this.friendListItemLUT.ContainsKey(friendId))
|
||||
{
|
||||
Destroy(this.friendListItemLUT[friendId].gameObject);
|
||||
this.friendListItemLUT.Remove(friendId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnUnsubscribed(string[] channels)
|
||||
{
|
||||
foreach (string channelName in channels)
|
||||
{
|
||||
if (this.channelToggles.ContainsKey(channelName))
|
||||
{
|
||||
Toggle t = this.channelToggles[channelName];
|
||||
Destroy(t.gameObject);
|
||||
|
||||
this.channelToggles.Remove(channelName);
|
||||
|
||||
Debug.Log("Unsubscribed from channel '" + channelName + "'.");
|
||||
|
||||
// Showing another channel if the active channel is the one we unsubscribed from before
|
||||
if (channelName == selectedChannelName && channelToggles.Count > 0)
|
||||
{
|
||||
IEnumerator<KeyValuePair<string, Toggle>> firstEntry = channelToggles.GetEnumerator();
|
||||
firstEntry.MoveNext();
|
||||
|
||||
ShowChannel(firstEntry.Current.Key);
|
||||
|
||||
firstEntry.Current.Value.isOn = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Can't unsubscribe from channel '" + channelName + "' because you are currently not subscribed to it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGetMessages(string channelName, string[] senders, object[] messages)
|
||||
{
|
||||
if (channelName.Equals(this.selectedChannelName))
|
||||
{
|
||||
// update text
|
||||
ShowChannel(this.selectedChannelName);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPrivateMessage(string sender, object message, string channelName)
|
||||
{
|
||||
// as the ChatClient is buffering the messages for you, this GUI doesn't need to do anything here
|
||||
// you also get messages that you sent yourself. in that case, the channelName is determinded by the target of your msg
|
||||
this.InstantiateChannelButton(channelName);
|
||||
|
||||
byte[] msgBytes = message as byte[];
|
||||
if (msgBytes != null)
|
||||
{
|
||||
Debug.Log("Message with byte[].Length: " + msgBytes.Length);
|
||||
}
|
||||
|
||||
if (this.selectedChannelName.Equals(channelName))
|
||||
{
|
||||
ShowChannel(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// New status of another user (you get updates for users set in your friends list).
|
||||
/// </summary>
|
||||
/// <param name="user">Name of the user.</param>
|
||||
/// <param name="status">New status of that user.</param>
|
||||
/// <param name="gotMessage">True if the status contains a message you should cache locally. False: This status update does not include a
|
||||
/// message (keep any you have).</param>
|
||||
/// <param name="message">Message that user set.</param>
|
||||
public void OnStatusUpdate(string user, int status, bool gotMessage, object message)
|
||||
{
|
||||
|
||||
Debug.LogWarning("status: " + string.Format("{0} is {1}. Msg:{2}", user, status, message));
|
||||
|
||||
if (friendListItemLUT.ContainsKey(user))
|
||||
{
|
||||
FriendItem _friendItem = friendListItemLUT[user];
|
||||
if (_friendItem != null)
|
||||
_friendItem.OnFriendStatusUpdate(status, gotMessage, message);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUserSubscribed(string channel, string user)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnUserUnsubscribed(string channel, string user)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnReceiveBroadcastMessage(string channel, byte[] message)
|
||||
{
|
||||
}
|
||||
|
||||
public void AddMessageToSelectedChannel(string msg, int msgId)
|
||||
{
|
||||
ChatChannel channel = null;
|
||||
bool found = this.chatClient.TryGetChannel(this.selectedChannelName, out channel);
|
||||
if (!found)
|
||||
{
|
||||
Debug.Log("AddMessageToSelectedChannel failed to find channel: " + this.selectedChannelName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel != null)
|
||||
{
|
||||
channel.Add("Bot", msg, msgId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ShowChannel(string channelName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(channelName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ChatChannel channel = null;
|
||||
bool found = this.chatClient.TryGetChannel(channelName, out channel);
|
||||
if (!found)
|
||||
{
|
||||
Debug.Log("ShowChannel failed to find channel: " + channelName);
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectedChannelName = channelName;
|
||||
this.CurrentChannelText.text = channel.ToStringMessages();
|
||||
Debug.Log("ShowChannel: " + this.selectedChannelName);
|
||||
|
||||
foreach (KeyValuePair<string, Toggle> pair in channelToggles)
|
||||
{
|
||||
pair.Value.isOn = pair.Key == channelName ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenDashboard()
|
||||
{
|
||||
Application.OpenURL("https://dashboard.photonengine.com");
|
||||
}
|
||||
|
||||
public void OpenChatDocs()
|
||||
{
|
||||
Application.OpenURL("https://doc.photonengine.com/chat");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8626678ad1db422409a1803edb7f6d72
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/ChatNewGui.cs
|
||||
uploadId: 817708
|
||||
@@ -0,0 +1,90 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility class to provide an instance with the Chat AppId to use by the demo. Can use PUN PhotonServerSettings or work as standalone.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the Instance getter for the different implementations (with and without PUN).
|
||||
/// </remarks>
|
||||
public class ChatSettings : ScriptableObject
|
||||
{
|
||||
[Tooltip("Your Chat AppId from Photon Dashboard")]
|
||||
public string AppId;
|
||||
|
||||
[HideInInspector]
|
||||
public bool WizardDone;
|
||||
|
||||
|
||||
// backing field for property
|
||||
private static ChatSettings instance;
|
||||
|
||||
// provides access to instance of ChatSettings. file gets created if not available
|
||||
public static ChatSettings Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
#if PUN_2_OR_NEWER
|
||||
if (instance == null)
|
||||
{
|
||||
instance = ScriptableObject.CreateInstance<ChatSettings>();
|
||||
}
|
||||
|
||||
instance.AppId = Photon.Pun.PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat;
|
||||
return instance;
|
||||
|
||||
#else
|
||||
|
||||
if (instance == null)
|
||||
{
|
||||
instance = Load();
|
||||
}
|
||||
|
||||
return instance;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// loads existing "ChatSettingsFile" of type ChatSettings from a Resources folder
|
||||
public static ChatSettings Load()
|
||||
{
|
||||
ChatSettings settings = (ChatSettings)Resources.Load("ChatSettingsFile", typeof(ChatSettings));
|
||||
if (settings != null)
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Create();
|
||||
}
|
||||
}
|
||||
|
||||
// creates an instance of ChatSettings and in Editor, stores it in a default path
|
||||
private static ChatSettings Create()
|
||||
{
|
||||
ChatSettings settings = (ChatSettings)ScriptableObject.CreateInstance("ChatSettings");
|
||||
#if UNITY_EDITOR
|
||||
if (!Directory.Exists("Assets/Resources"))
|
||||
{
|
||||
AssetDatabase.CreateFolder("Assets", "Resources");
|
||||
AssetDatabase.ImportAsset("Assets/Resources");
|
||||
}
|
||||
|
||||
AssetDatabase.CreateAsset(settings, "Assets/Resources/ChatSettingsFile.asset");
|
||||
EditorUtility.SetDirty(settings);
|
||||
|
||||
settings = (ChatSettings)Resources.Load("ChatSettingsFile", typeof(ChatSettings));
|
||||
#endif
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8078fb5ca219c34ea80805fec36beae
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/ChatSettings.cs
|
||||
uploadId: 817708
|
||||
79
Assets/Photon/PhotonChat/Demos/Demo Chat/Code/FriendItem.cs
Normal file
79
Assets/Photon/PhotonChat/Demos/Demo Chat/Code/FriendItem.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat
|
||||
{
|
||||
/// <summary>
|
||||
/// Friend UI item used to represent the friend status as well as message.
|
||||
/// It aims at showing how to share health for a friend that plays on a different room than you for example.
|
||||
/// But of course the message can be anything and a lot more complex.
|
||||
/// </summary>
|
||||
public class FriendItem : MonoBehaviour
|
||||
{
|
||||
[HideInInspector]
|
||||
public string FriendId
|
||||
{
|
||||
set { NameLabel.text = value; }
|
||||
get { return NameLabel.text; }
|
||||
}
|
||||
|
||||
public Text NameLabel;
|
||||
public Text StatusLabel;
|
||||
public Text Health;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
Health.text = string.Empty;
|
||||
}
|
||||
|
||||
public void OnFriendStatusUpdate(int status, bool gotMessage, object message)
|
||||
{
|
||||
string _status;
|
||||
|
||||
// status string for the remote-user status code to show in ui
|
||||
switch (status)
|
||||
{
|
||||
case 1:
|
||||
_status = "Invisible";
|
||||
break;
|
||||
case 2:
|
||||
_status = "Online";
|
||||
break;
|
||||
case 3:
|
||||
_status = "Away";
|
||||
break;
|
||||
case 4:
|
||||
_status = "Do not disturb";
|
||||
break;
|
||||
case 5:
|
||||
_status = "Looking For Game/Group";
|
||||
break;
|
||||
case 6:
|
||||
_status = "Playing";
|
||||
break;
|
||||
default:
|
||||
_status = "Offline";
|
||||
break;
|
||||
}
|
||||
|
||||
StatusLabel.text = _status;
|
||||
|
||||
|
||||
if (gotMessage)
|
||||
{
|
||||
string _health = string.Empty;
|
||||
if (message != null)
|
||||
{
|
||||
string[] _messages = message as string[];
|
||||
if (_messages != null && _messages.Length >= 2)
|
||||
{
|
||||
_health = (string)_messages[1] + "%";
|
||||
}
|
||||
}
|
||||
|
||||
Health.text = _health;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a3cc2bf2597946e3a355de2affc40b5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/FriendItem.cs
|
||||
uploadId: 817708
|
||||
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat
|
||||
{
|
||||
[RequireComponent(typeof(ChatNewGui))]
|
||||
public class NamePickNewGui : MonoBehaviour
|
||||
{
|
||||
private const string UserNamePlayerPref = "NamePickUserName";
|
||||
|
||||
public ChatNewGui chatNewComponent;
|
||||
|
||||
public InputField idInput;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
InitChatNewComponent();
|
||||
|
||||
string prefsName = PlayerPrefs.GetString(NamePickNewGui.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()
|
||||
{
|
||||
if (!InitChatNewComponent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.chatNewComponent.UserName = this.idInput.text.Trim();
|
||||
this.chatNewComponent.Connect();
|
||||
this.enabled = false;
|
||||
|
||||
PlayerPrefs.SetString(NamePickNewGui.UserNamePlayerPref, this.chatNewComponent.UserName);
|
||||
}
|
||||
|
||||
public bool InitChatNewComponent()
|
||||
{
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
this.chatNewComponent = GameObject.FindFirstObjectByType<ChatNewGui>();
|
||||
#else
|
||||
this.chatNewComponent = FindObjectOfType<ChatNewGui>();
|
||||
#endif
|
||||
|
||||
return this.chatNewComponent != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5e77b98bc3c7be4d838fbfe21004ce3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/NamePickNewGui.cs
|
||||
uploadId: 817708
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8195fd485f4b78e41a66d4ab2e62ff99
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// This is used in the Editor Splash to properly inform the developer about the chat AppId requirement.
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
public class ChatIdCheckerUI : MonoBehaviour
|
||||
{
|
||||
public GameObject VisibilityRoot; // must be set in inspector
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (this.VisibilityRoot != null)
|
||||
{
|
||||
this.VisibilityRoot.SetActive(string.IsNullOrEmpty(ChatSettings.Instance.AppId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49f8b1206d1f448aca7d730f027d8c09
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/Utilities/ChatIdCheckerUI.cs
|
||||
uploadId: 817708
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat.Utilities
|
||||
{
|
||||
/// <summary>This component will destroy the Target GameObject (or the one it is attached to).</summary>
|
||||
public class DestroyOnStart : MonoBehaviour
|
||||
{
|
||||
[Tooltip("If null, this game object gets destroyed in this Start().")]
|
||||
public GameObject Target; // set in inspector
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (this.Target == null)
|
||||
{
|
||||
this.Target = this.gameObject;
|
||||
}
|
||||
|
||||
GameObject.Destroy(this.Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2895d30d4d2c3f4cb5d2c92fcd9125f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/Utilities/DestroyOnStart.cs
|
||||
uploadId: 817708
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat.Utilities
|
||||
{
|
||||
/// <summary>This component will enable (setactive) the Target GameObject (or the one it is attached to).</summary>
|
||||
public class EnableOnStart : MonoBehaviour
|
||||
{
|
||||
[Tooltip("If null, this game object becomes active in this Start().")]
|
||||
public GameObject Target; // set in inspector
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (this.Target == null)
|
||||
{
|
||||
this.Target = this.gameObject;
|
||||
}
|
||||
|
||||
this.Target.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8555b4060b53841439f2c0c6f10db6ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/Utilities/EnableOnStart.cs
|
||||
uploadId: 817708
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat.Utilities
|
||||
{
|
||||
// small script to avoid clicks picking inactive UI elements
|
||||
public class IgnoreUiRaycastWhenInactive : MonoBehaviour, ICanvasRaycastFilter
|
||||
{
|
||||
public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
|
||||
{
|
||||
return gameObject.activeInHierarchy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ba4c747f6975ea46bcc0a55ffe3bfe8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/Utilities/IgnoreUiRaycastWhenInactive.cs
|
||||
uploadId: 817708
|
||||
@@ -0,0 +1,43 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="TextButtonTransition.cs" company="Exit Games GmbH">
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Use this on Button texts to have some color transition on the text as well without corrupting button's behaviour.
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Photon.Chat.DemoChat.Utilities
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Use this on Button texts to have some color transition on the text as well without corrupting button's behaviour.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Text))]
|
||||
public class TextButtonTransition : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
||||
|
||||
Text _text;
|
||||
|
||||
public Color NormalColor= Color.white;
|
||||
public Color HoverColor = Color.black;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
_text = GetComponent<Text>();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
_text.color = HoverColor;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
_text.color = NormalColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a2169250a70845ffa2a9d25e9cd84cd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/Utilities/TextButtonTransition.cs
|
||||
uploadId: 817708
|
||||
@@ -0,0 +1,64 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="TextToggleIsOnTransition.cs" company="Exit Games GmbH">
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Use this on Button texts to have some color transition on the text as well without corrupting button's behaviour.
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace Photon.Chat.DemoChat.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Use this on toggles texts to have some color transition on the text depending on the isOnState.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Text))]
|
||||
public class TextToggleIsOnTransition : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public Toggle toggle;
|
||||
|
||||
Text _text;
|
||||
|
||||
public Color NormalOnColor = Color.white;
|
||||
public Color NormalOffColor = Color.black;
|
||||
public Color HoverOnColor = Color.black;
|
||||
public Color HoverOffColor = Color.black;
|
||||
|
||||
bool isHover;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
_text = GetComponent<Text>();
|
||||
|
||||
toggle.onValueChanged.AddListener(OnValueChanged);
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
toggle.onValueChanged.RemoveListener(OnValueChanged);
|
||||
}
|
||||
|
||||
public void OnValueChanged(bool isOn)
|
||||
{
|
||||
_text.color = isOn ? (isHover ? HoverOnColor : HoverOffColor) : (isHover ? NormalOnColor : NormalOffColor);
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isHover = true;
|
||||
_text.color = toggle.isOn ? HoverOnColor : HoverOffColor;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
isHover = false;
|
||||
_text.color = toggle.isOn ? NormalOnColor : NormalOffColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f64fb930d3f24c5ebc31aa95dba1c0b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 119922
|
||||
packageName: PUN 2 - FREE
|
||||
packageVersion: 2.52
|
||||
assetPath: Assets/Photon/PhotonChat/Demos/Demo Chat/Code/Utilities/TextToggleIsOnTransition.cs
|
||||
uploadId: 817708
|
||||
Reference in New Issue
Block a user