やりたいこと
- ・日本語でのチャット機能の実装の続き
--
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;
[RequireComponent(typeof(PhotonView))]
public class InRoomChat : MonoBehaviourPunCallbacks
{
public Rect GuiRect = new Rect(0, 0, 250, 300);
public bool IsVisible = true;
public bool AlignBottom = false;
public List<string> messages = new List<string>();
private string inputLine = "";
private Vector2 scrollPos = Vector2.zero;
public Text showText;
public InputField inputField;
public static readonly string ChatRPC = "Chat";
public void OnSend()
{
Debug.Log("送信");
this.photonView.RPC("Chat", RpcTarget.All, inputField.text);
inputField.text = "";
}
// ChatRPC RPC呼出側:送信者 RPC受信g側:受信者
[PunRPC]
//Vector3 senderposition,
public void Chat(string newLine, PhotonMessageInfo mi)
{
//送信者の名前用変数
string senderName = "anonymous";
if (mi.Sender != null)
{
//送信者の名前があれば、、、IsNullOrEmptyはNullか空でTrue
if (!string.IsNullOrEmpty(mi.Sender.NickName))
{
senderName = mi.Sender.NickName;
}
else
{
senderName = "player " + mi.Sender.UserId;
}
}
//受信したチャットをログに追加
showText.text = senderName + ": " + newLine;
}
}
- 各種設定など
- ・テキスト表示エリアとか作成
- ・Input内にShowText作成
- ・Input内にSendButton作成
- ・InRoomChatオブジェクトへの登録
- ・showTextの登録
- ・inputFieldの登録
- ・SendButton
- ・ボタンのOnClickイベント一覧に自作関数が表示されない問題は下画像で対処
- バグを治す
- ・現在の状況
- ・Buld後のWebGLデータでは、、、
- ・日本語が入力時にInputField箇所(赤線部分)に表示されない
- ・Placeholderも表示されていない
- ★PlaceholderとTextとは?
- ☆Placeholder
- =>InputFieldにテキストが入力されていない場合に表示されるテキスト
- ☆Text
- =>フィールドに表示されるテキストの編集前の初期値。
- テキストが編集されると、入力されたテキストを保持します。
- ・でもSendすると表示される。。
- 結論
- ・テキストでかかった =>InputFieldのTextオブジェクト、、FontSize: 10 で解決。。
- ・あと、textの設定
- 収まらなかったときに折り返しを行うか行わないかを選択。
- ☆Horizontal Overflow: Overflowで設定
- Warp:折り返す
- Overflow:折り返さずTextエレメントの横幅からはみ出して表示させる
- ☆Vertical Overflow: Truncateで設定
- Truncate:縦幅からはみ出した行を削除(非表示)にする
- Overflow:縦幅からはみ出しても表示する