Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using EasyJSON;
- public class EqemuConnect : MonoBehaviour {
- public GameObject EqemuConnectObject;
- public GameObject elf;
- // Use this for initialization
- IEnumerator Start () {
- WebSocket w = new WebSocket(new Uri("ws://IP:PORT"));
- yield return StartCoroutine(w.Connect());
- Auth auth1 = new Auth();
- auth1.id = "token_auth_id";
- auth1.method = "WebInterface.Authorize";
- auth1.@params = new string[1] {"TOKEN"};
- // EASYJSON Serialize the entity into a JSON string
- string authoutput = Serializer.Serialize(auth1);
- // send auth to server
- w.SendString(authoutput);
- GetInitialEntitiyPositions GetInitialEntitiyPositions1 = new GetInitialEntitiyPositions();
- GetInitialEntitiyPositions1.id = "get_initial_entity_positions";
- GetInitialEntitiyPositions1.method = "Zone.GetInitialEntityPositions";
- GetInitialEntitiyPositions1.@params = new string[2] {EqemuConnectObject.tag,"0"};
- // EASYJSON Serialize the entity into a JSON string
- string output2 = Serializer.Serialize(GetInitialEntitiyPositions1);
- // Request Entity Positions from server
- w.SendString(output2);
- int i=0;
- while (true)
- {
- string reply = w.RecvString();
- if (reply != null)
- {
- // Print responses to console
- // Debug.Log ("Received: "+reply+i++);
- Debug.Log("i =" + i++);
- //deserialize
- //eqemu json start
- if (i > 1)
- {
- string JsonArray = ("[" + reply + "]");
- MyClass[] jsonObject = Serializer.Deserialize<MyClass[]>(JsonArray);
- float fx = Single.Parse(Result.x);
- float fy = Single.Parse(Result.y);
- float fz = Single.Parse(Result.z);
- // Debug.Log("name:" + Result.name);
- // Debug.Log("X:" + Result.x);
- // Debug.Log("y:" + Result.y);
- // Debug.Log("z:" + Result.z);
- if (Result.type == "NPC")
- {
- Instantiate(elf, new Vector3(-fx, fz, fy), Quaternion.identity);
- }
- }
- }
- if (w.Error != null)
- {
- Debug.LogError ("Error: "+w.Error);
- break;
- }
- yield return 0;
- }
- w.Close();
- }
- public class Auth {
- public string id;
- public string method;
- public string[] @params;
- }
- public class GetInitialEntitiyPositions {
- public string id;
- public string method;
- public string[] @params;
- }
- public class Result {
- public static string aggro_range { get; set; }
- public static string class_id { get; set; }
- public static string ent_id { get; set; }
- public static string h { get; set; }
- public static string name { get; set; }
- public static string race_id { get; set; }
- public static string type { get; set; }
- public static string x { get; set; }
- public static string y { get; set; }
- public static string z { get; set; }
- }
- public class MyClass {
- public string id;
- public string error;
- public Result result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement