zoukankan      html  css  js  c++  java
  • unity用PUN进行信息交互模块


     

    using UnityEngine;
    using System.Collections.Generic;
    
    public class MessageChat : Photon.MonoBehaviour
    {
    	public string mess ="Is Done";//用来发送的信息
        	public static MessageChat MC;//静态对象,方便全局调用
    	
        	void Awake()
       	{
    		MC = this; //初始实例化
       	}
    
    	void Update()
    	{
    		if (Input.GetKeyDown (KeyCode.F1)) 
    		{
    			//给全部发送信息,其他发送方式参照PhotonTargets
    			SendChat(PhotonTargets.All);
    		}
    		if (Input.GetKeyDown (KeyCode.F2)) 
    		{
    			foreach(PhotonPlayer palyer in PhotonNetwork.playerList)
    			{
    				SendChat(player);//给指定的用户发送信息
    			}
    
    		}
    	}
    	//定义信息发送函数, --重载
        	void SendChat(PhotonTargets target)
        	{
    		photonView.RPC("SendChatMessage", target, mess);
        	}
    
        	void SendChat(PhotonPlayer target)
        	{
            	chatInput = "[PM] " + chatInput;
    		photonView.RPC("SendChatMessage", target, mess);
        	}
    	//RPC函数,在信息交互时,所有客户端都会执行这个函数
    	[RPC]
    	//第一个参数必须为基本类型,如string,int等,第二个参数可不加
    	void SendChatMessage(string str, PhotonMessageInfo info)
    	{
    		Debug.Log (""+info.sender+str);
    	}
    
       
    }
    


     

     

  • 相关阅读:
    Python实战:网络爬虫都能干什么?
    写了个脚本将json换成md
    RAC +MVVM
    Python 基础指令以及库管理工具pipenv
    CocoaPods创建自己的公开库、私有库
    python脚本解析json文件
    iOS 面试题
    路由器 大杂烩
    大数据挖掘基本概念
    Node.js实践
  • 原文地址:https://www.cnblogs.com/liang123/p/6325924.html
Copyright © 2011-2022 走看看