Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class MyServer:MonoBehaviour {
- int MAX_CONNECTION = 4;
- string hostId="127.0.0.1";
- int port = 5708;
- private GameObject infoDisplayText;
- // Use this for initialization
- void Start () {
- NetworkManager.singleton.networkAddress = hostId;
- NetworkManager.singleton.networkPort = port;
- NetworkManager.singleton.StartHost ();
- NetworkServer.RegisterHandler(AnimalDataMsgType.animalData, OnTextureReceive);
- infoDisplayText = GameObject.Find("InfoDisplay");
- }
- // Update is called once per frame
- void Update () {
- }
- //Called when texture is received
- public void OnTextureReceive(NetworkMessage netMsg)
- {
- AnimalData animalData = netMsg.ReadMessage<AnimalData>();
- string type = animalData.Type;
- Debug.Log("Type : " + type);
- string id = animalData.Id;
- Debug.Log("ID : " + id);
- int strength = animalData.Strength;
- Debug.Log("Strength : " + strength);
- int hitpoints = animalData.Hitpoints;
- Debug.Log("Hit Points : " + hitpoints);
- //Your Received Texture2D
- Texture2D receivedtexture = new Texture2D(64, 64, TextureFormat.DXT5, false);
- receivedtexture.LoadRawTextureData(animalData.Tex);
- receivedtexture.Apply();
- Debug.Log(type + " data received!");
- infoDisplayText.GetComponent<Text>().text += type + " data received!\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement