0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Photon×WebGL(7)日本語チャットの実装(構文改造からの設定とバグとり)

Last updated at Posted at 2021-01-09

やりたいこと

・日本語でのチャット機能の実装の続き

--

スクリーンショット 2021-01-09 1910581.jpg

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

キャプチャ2.JPG

各種設定など
  ・テキスト表示エリアとか作成
   ・Input内にShowText作成
   ・Input内にSendButton作成

  ・InRoomChatオブジェクトへの登録
   ・showTextの登録
   ・inputFieldの登録

  ・SendButton
   ・ボタンのOnClickイベント一覧に自作関数が表示されない問題は下画像で対処

キャプチャ.JPG

バグを治す
 ・現在の状況
  ・Buld後のWebGLデータでは、、、
   ・日本語が入力時にInputField箇所(赤線部分)に表示されない
   ・Placeholderも表示されていない
    ★PlaceholderとTextとは?
     ☆Placeholder
      =>InputFieldにテキストが入力されていない場合に表示されるテキスト
     ☆Text
      =>フィールドに表示されるテキストの編集前の初期値。
       テキストが編集されると、入力されたテキストを保持します。
   ・でもSendすると表示される。。

スクリーンショット 2021-01-09 191058.jpg

結論
  ・テキストでかかった =>InputFieldのTextオブジェクト、、FontSize: 10 で解決。。
  ・あと、textの設定
   収まらなかったときに折り返しを行うか行わないかを選択。
   ☆Horizontal Overflow: Overflowで設定
      Warp:折り返す
      Overflow:折り返さずTextエレメントの横幅からはみ出して表示させる
   ☆Vertical Overflow: Truncateで設定
      Truncate:縦幅からはみ出した行を削除(非表示)にする
      Overflow:縦幅からはみ出しても表示する
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?