PixiTest.Common.Game DLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PixiTest.Common.Game
{
    public enum GameMessageClasses : byte
    {
        GameSimulation,
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PixiTest.Common.Game
{
	/// <summary>
	/// Enumeration of types for the game.
	/// </summary>
	public enum GameMessageType : short
	{
		CharacterListRequest,
        CharacterListResponse,
        ZoneLoadRequest,
        ZoneLoadFailed,
        ZoneLoadResponse,
        EnterZoneRequest,
        EnterZoneResponse,
        StateObjectMoveReport,
        SpawnGameObject,
        DespawnGameObject,
        GameMessage,
        Chat,
	}
}

PixiTest.Client.Network DLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Pixi.PC.Client;
using Pixi.Client.Network;
using PixiTest.Common.Game;
using Pixi.Logging;

namespace PixiTest.Client.Network
{
    public class GameNetwork : ClientNetwork
    {
        private int _characterId;

        public GameNetwork(IClientTransceiverFactory clientTransceiverFactory, 
             ILogger logger)
            : base(clientTransceiverFactory, logger)
        {
        }

        public void SendCharacterListRequest()
        {
            base.SendTCP(true, (short)GameMessageType.CharacterListRequest, null);
        }
    }
}

Unity 3D Script

using UnityEngine;
using System.Collections;

using Pixi.PC.Client;
using Pixi.Network;
using Pixi.Client.Network;
using Pixi.Logging;
using PixiTest.Client.Network;
using PixiTest.Common.Game;

public class PixiTester : MonoBehaviour {
   GameNetwork _gameNetwork;
	
   IClientTransceiverFactory clientTransceiverFactory =  new ClientTransceiverFactory();
   ILogger logger = new ClientLogger();
	
   bool _loggedIn = false;
	
   // Use this for initialization
   void Start () {
      _gameNetwork = new GameNetwork(clientTransceiverFactory, logger);
		
      // Connect to Server
      _gameNetwork.Start("IP ADDRESS HERE", 11000, 11001, 0, 0);	
   }

   // Update is called once per frame
   void Update () {
		
   }
	
   void OnGUI () {
      try {
         // Login Button
         if (_loggedIn == false) {
            if (GUI.Button(new Rect(10, 10, 50, 30), "Login")) {
               _gameNetwork.Login("username", "password");
               _loggedIn = true;
            }
         } else {
            // Disconnect Button
            if (GUI.Button(new Rect(10, 70, 100, 30), "Disconnect")) {
               _gameNetwork.Stop();
               _loggedIn = false;
            }

         _gameNetwork.Update();

         ClientNetMessage msg = _gameNetwork.ReadMessage();
	
         if (msg != null) {
            switch (msg.MessageType) {
               case (short)SystemMessageType.LoginError:
                  DisplayMessage(msg.Data.ToString(), "Login Error");
                  break;
               case (short)SystemMessageType.LoginSuccess:
                  DisplayMessage(msg.Data.ToString(), "Login Succeeded");
                  _gameNetwork.SendApplicationDomainListRequest();
                  break;
               case (short)SystemMessageType.Exception:
                  DisplayMessage(msg.Data.ToString(), "Exception");
                  break;
               case (short)SystemMessageType.ClientDisconnected:
                  DisplayMessage(msg.Data.ToString(), "Disconnected");
                  break;
               case (short)SystemMessageType.LinkDead:
                  DisplayMessage(msg.Data.ToString(), "Linkdead");
                  break;
               case (short)SystemMessageType.ApplicationDomainAccept:
                  _gameNetwork.SendCharacterListRequest();
                  break;
               case(short)SystemMessageType.ApplicationDomainDenied:
                  DisplayMessage("Change of worlds denied.", "Change World");
                  break;
               default:
                  break;
               }
            }
         }
      } catch {
         print("error - stopping network");
         _gameNetwork.Stop();
      }
   }
	
   private void DisplayMessage(string message, string title)
   {
      print(message);
   }
}

Last edited Feb 17, 2012 at 5:55 PM by Stolistic, version 10

Comments

No comments yet.