// create building's mesh and name based on data from response void CreateBuilding(CymaticLabs.Unity3D.Amqp.SimpleJSON.JSONNode buildingData) { List <Vector3> point = new List <Vector3>(); List <Vector2> point2d = new List <Vector2>(); for (int i = 0; i < buildingData.Count; i++) { var tempData = buildingData[i]; if (tempData["listCoordinate"].Count == 1) { string buildingName = (string)tempData["buildingName"]; if (buildingName != null) { var coordinate = tempData["listCoordinate"][0]; this.ShowName(new Vector3((float)coordinate["latitude"], 12f, (float)coordinate["longitude"]), new Vector3(), buildingName, "MapObject", "buildingName", Color.green); } } else { for (int j = 0; j < tempData["listCoordinate"].Count - 1; j++) { var coordinate = tempData["listCoordinate"][j]; float latitude = (float)coordinate["latitude"]; float longitude = (float)coordinate["longitude"]; point.Add(new Vector3(latitude, 0.0f, longitude)); point2d.Add(new Vector2(latitude, longitude)); } //this.CreatePolygon(point2d.ToArray(), point.ToArray(), Color.green, "MapObject", "building"); point.Clear(); point2d.Clear(); } } }
void CreateBuilding(CymaticLabs.Unity3D.Amqp.SimpleJSON.JSONNode buildingData) { List <Vector3> point = new List <Vector3>(); List <Vector2> point2D = new List <Vector2>(); for (int i = 0; i < buildingData.Count; i++) { var tempData = buildingData[i]; Debug.Log("testing = " + tempData); if (tempData["listCoordinate"].Count == 1) { string buildingName = (string)tempData["buildingName"]; float buildingCode = (float)tempData["buildingCode"]; Debug.Log("nama gedung ini adalah " + buildingName); Debug.Log("building code = " + buildingCode); if (buildingName != null) { var coordinate = tempData["listCoordinate"][0]; //var properties = tempData["buildingCode"]; this.ShowName(new Vector3((float)coordinate["latitude"], 12f, (float)coordinate["longitude"]), new Vector3(), buildingName, "MapObject", "buildingName", Color.green); Debug.Log("coba1 latitude = " + latitude); Debug.Log("coba2 latitude coordinate = " + (float)coordinate["latitude"]); /* * * if (latitude >= coordinate["latitude"] && longitude <= coordinate["longitude"]) * { * Debug.Log("coba1 latitude = " + latitude); * Debug.Log("coba2 latitude coordinate = " + (float)coordinate["latitude"]); * this.ShowGhost(new Vector3((float)coordinate["latitude"], 10f, (float)coordinate["longitude"]), buildingName, "buildingName"); * } */ //Debug.Log("coba = "+ (float)coordinate["latitude"]); //petObject.transform.position = new Vector3((float)coordinate["latitude"], 12f, (float)coordinate["longitude"]); //Debug.Log("pocong = " + petObject.transform.position); } } else { for (int j = 0; j < tempData["listCoordinate"].Count - 1; j++) { var coordinate = tempData["listCoordinate"][j]; float latitude = (float)coordinate["latitude"]; float longitude = (float)coordinate["longitude"]; point.Add(new Vector3(latitude, 0.0f, longitude)); point2D.Add(new Vector2(latitude, longitude)); } this.CreatePolygon(point2D.ToArray(), point.ToArray(), Color.green, "MapObject", "building"); point.Clear(); point2D.Clear(); } } }
void CreateRoad(CymaticLabs.Unity3D.Amqp.SimpleJSON.JSONNode roadData) { List <Vector3[]> point = new List <Vector3[]>(); List <string> names = new List <string>(); for (int i = 0; i < roadData.Count; i++) { var tempData = roadData[i]; Vector3[] perPoint = new Vector3[tempData["listCoordinate"].Count]; for (int k = 0; k < tempData["listCoordinate"].Count; k++) { var coordinate = tempData["listCoordinate"][k]; float latitude = (float)coordinate["latitude"]; float longitude = (float)coordinate["longitude"]; Debug.Log(latitude + " & " + longitude); perPoint[k] = new Vector3(latitude, 0f, longitude); } point.Add(perPoint); names.Add((string)tempData["roadName"]); } float distance = float.MaxValue; Vector3 startNamePos = Vector3.zero; Vector3 endNamePos = Vector3.zero; for (int l = 0; l < point.Count; l++) { string roadName = names[l]; Vector3[] tempVector = point[l]; for (int m = 0; m < tempVector.Length - 1; m++) { CreateRoadWaterMesh(tempVector[m], tempVector[m + 1], 2.0f, "MapObject", Color.red, "road"); Vector3 tempNamePost = Vector3.Lerp(tempVector[m], tempVector[m + 1], 0.5f); float tempDistance = Vector3.Distance(this.mainCam.transform.parent.position, tempNamePost); if (tempDistance < distance) { distance = tempDistance; startNamePos = tempVector[m]; endNamePos = tempVector[m + 1]; } } if (roadName != null) { Debug.Log(roadName); this.ShowName(startNamePos, endNamePos, roadName, "MapObject", "roadName", Color.green); } distance = float.MaxValue; } }
void RemoveOtherFromList(CymaticLabs.Unity3D.Amqp.SimpleJSON.JSONNode data) { bool found = false; List <OtherPlayerData> removeList = new List <OtherPlayerData>(); for (int i = 0; i < otherPlayerDataList.Count; i++) { OtherPlayerData other = otherPlayerDataList[i]; for (int j = 0; j < data.Count; j++) { string otherName = (string)data[j]["playerName"]; if (other.playerName == otherName) { found = true; break; } } if (!found) { removeList.Add(other); } found = false; } Debug.Log("Remove = " + removeList.Count); for (int i = 0; i < removeList.Count; i++) { OtherPlayerData remove = removeList[i]; GameObject otherPlayer = GameObject.Find(remove.playerName); GameObject otherPetPlayer = GameObject.Find("pet_" + remove.playerName); GameObject food = GameObject.Find("food_" + remove.playerName); GameObject ball = GameObject.Find("ball_" + remove.playerName); if (otherPlayer != (GameObject)null) { Destroy(otherPlayer); } if (otherPetPlayer != (GameObject)null) { Destroy(otherPetPlayer); } if (food != (GameObject)null) { Destroy(food); } if (ball != (GameObject)null) { Destroy(ball); } otherPlayerDataList.Remove(remove); } }
void LoadStatus(CymaticLabs.Unity3D.Amqp.SimpleJSON.JSONNode msg) { PlayerPrefs.SetString("username", (string)msg["username"]); //PlayerPrefs.SetInt("Health", (int)msg["data"][0]); //PlayerPrefs.SetInt("Bones", (int)msg["data"][1]); //PlayerPrefs.SetInt("XP", (int)msg["data"][2]); //PlayerPrefs.SetInt("Sleep", (int)msg["data"][3]); //PlayerPrefs.SetInt("Food", (int)msg["data"][4]); //PlayerPrefs.SetInt("Walk", (int)msg["data"][5]); //PlayerPrefs.SetInt("Fun", (int)msg["data"][6]); PlayerPrefs.SetString("petName", (string)msg["username"]); }
void CreateRoute(CymaticLabs.Unity3D.Amqp.SimpleJSON.JSONNode routeData) { for (int i = 0; i < routeData.Count - 1; i++) { float startLatitude = (float)routeData[i]["latitude"]; float startLongitude = (float)routeData[i]["longitude"]; Vector3 start = new Vector3(startLatitude, 0.0f, startLongitude); float endLatitude = (float)routeData[i + 1]["latitude"]; float endLongitude = (float)routeData[i + 1]["longitude"]; Vector3 end = new Vector3(endLatitude, 0.0f, endLongitude); CreateRoadWaterMesh(start, end, 8.0f, "RouteObject", Color.green, "route"); } }
void UpdateOtherBallState(CymaticLabs.Unity3D.Amqp.SimpleJSON.JSONNode data) { Debug.Log("Update Ball State"); string otherUsername = (string)data["username"]; string otherBallState = (string)data["ballState"]; float ballPosX = (float)data["ballPosX"]; float ballPosY = (float)data["ballPosY"]; float ballPosZ = (float)data["ballPosZ"]; if (otherUsername != this.playerName) { if (otherBallState == "live") { GameObject otherBall = GameObject.CreatePrimitive(PrimitiveType.Sphere); otherBall.name = "ball_" + otherUsername; otherBall.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); otherBall.transform.position = new Vector3(ballPosX - this.centerPosX, 10.0f, ballPosZ - this.centerPosY); Rigidbody ballRigibody = otherBall.AddComponent <Rigidbody>(); ballRigibody.mass = 1; ballRigibody.isKinematic = true; } else if (otherBallState == "none") { GameObject otherBall = GameObject.Find("ball_" + otherUsername); Destroy(otherBall); } else if (otherBallState == "throw") { GameObject otherBall = GameObject.Find("ball_" + otherUsername); otherBall.transform.position = otherBall.transform.position + new Vector3(ballPosX, ballPosY, ballPosZ) * (Camera.main.nearClipPlane + 2f); otherBall.GetComponent <Rigidbody>().isKinematic = false; otherBall.GetComponent <Rigidbody>().velocity = new Vector3(ballPosX, ballPosY, ballPosZ) * 5; } else if (otherBallState == "inground") { GameObject otherBall = GameObject.Find("ball_" + otherUsername); otherBall.GetComponent <Rigidbody>().isKinematic = true; otherBall.transform.position = new Vector3(ballPosX - this.centerPosX, 0.0f, ballPosZ - this.centerPosY); } } }
void UpdateOthersPosition(CymaticLabs.Unity3D.Amqp.SimpleJSON.JSONNode data) { Debug.Log("list player responses"); for (int i = 0; i < data.Count; i++) { string otherUsername = (string)data[i]["playerName"]; float otherPosX = (float)data[i]["posX"]; float otherPosY = (float)data[i]["posY"]; string otherPetName = (string)data[i]["petName"]; float otherPetPosX = (float)data[i]["petPosX"]; float otherPetPosY = (float)data[i]["petPosY"]; float otherPetLastPosX = (float)data[i]["petLastPosX"]; float otherPetLastPosY = (float)data[i]["petLastPosY"]; string otherStartTimeMoveString = (string)data[i]["timeStartMove"]; long otherStartTimeMove = 0L; if (otherStartTimeMoveString != "") { otherStartTimeMove = Convert.ToInt64(otherStartTimeMoveString); } string otherPetState = (string)data[i]["petState"]; float otherPetSpeed = (float)data[i]["petSpeed"]; Debug.Log("main player = " + this.playerName); Debug.Log("other player = " + otherUsername); if (otherUsername != this.playerName) { OtherPlayerData other = otherPlayerDataList.Find(x => x.playerName == otherUsername); if (other == null) { OtherPlayerData newOtherPlayer = new OtherPlayerData(); newOtherPlayer.playerName = otherUsername; newOtherPlayer.posX = otherPosX - this.centerPosX; newOtherPlayer.posY = otherPosY - this.centerPosY; newOtherPlayer.petName = otherPetName; newOtherPlayer.petState = otherPetState; float mapPetLastPosX = otherPetLastPosX - this.centerPosX; float mapPetLastPosY = otherPetLastPosY - this.centerPosY; float mapPetPosX = otherPetPosX - this.centerPosX; float mapPetPosY = otherPetPosY - this.centerPosY; Vector3 mapPetLastPos = new Vector3(mapPetLastPosX, 0.0f, mapPetLastPosY); Vector3 mapPetPos = new Vector3(mapPetLastPosY, 0.0f, mapPetLastPosY); float totalDistance = Vector3.Distance(mapPetLastPos, mapPetPos); float distanceTraveled = 0.0f; //double seconds = (DateTime.Now - new DateTime(otherStartTimeMove)).TotalSeconds; //Debug.Log(seconds); //float distanceTraveled = (float)(seconds * 1f); if (otherStartTimeMove != 0L) { double seconds = (DateTime.Now - new DateTime(otherStartTimeMove)).TotalSeconds; distanceTraveled = (float)(seconds * otherPetSpeed); } Debug.Log(distanceTraveled + " --- distance traveled"); Debug.Log(totalDistance + " --- total distance"); //Debug.Log(seconds + " --- time seconds"); Vector3 predictedPos; if (distanceTraveled >= totalDistance) { newOtherPlayer.petFromPosX = mapPetLastPosX; newOtherPlayer.petFromPosY = mapPetLastPosY; newOtherPlayer.petToPosX = mapPetPosX; newOtherPlayer.petToPosY = mapPetPosY; predictedPos = new Vector3(mapPetPosX, 0.0f, mapPetPosY); } else { float percentage = distanceTraveled / totalDistance; predictedPos = Vector3.Lerp(mapPetLastPos, mapPetPos, percentage); newOtherPlayer.petFromPosX = predictedPos.x; newOtherPlayer.petFromPosY = predictedPos.z; newOtherPlayer.petToPosX = mapPetPosX; newOtherPlayer.petToPosY = mapPetPosY; } newOtherPlayer.petSpeed = otherPetSpeed; otherPlayerDataList.Add(newOtherPlayer); //jika belum ada nama pet GameObject newPetObject = Instantiate(Resources.Load("PetPrefab")) as GameObject; newPetObject.name = "pet_" + otherPetName; newPetObject.transform.position = new Vector3(predictedPos.x, 0.0f, predictedPos.z); GameObject petName = newPetObject.transform.Find("PetNameText").gameObject; TextMesh petNameMesh = petName.GetComponent <TextMesh>(); petNameMesh.text = "<pet>\n" + otherPetName; petNameMesh.characterSize = 0.05f; petNameMesh.fontSize = 100; petNameMesh.color = Color.green; Font font = Resources.Load <Font>("Font/youmurdererbb_reg"); petNameMesh.font = font; var mr = petNameMesh.GetComponent <Renderer>(); mr.material = font.material; GameObject otherPlayerNameObject = new GameObject(); otherPlayerNameObject.AddComponent <NameController>(); otherPlayerNameObject.name = otherUsername; otherPlayerNameObject.transform.position = new Vector3(otherPosX - this.centerPosX, 10.0f, this.centerPosY); var meshText = otherPlayerNameObject.AddComponent <TextMesh>() as TextMesh; meshText.text = "<user>\n" + otherUsername; meshText.characterSize = 0.05f; meshText.fontSize = 100; meshText.color = Color.green; Font font1 = Resources.Load <Font>("Font/youmurdererbb_reg"); meshText.font = font1; var mr1 = meshText.GetComponent <Renderer>(); mr1.material = font1.material; } else { other.petToPosX = otherPetPosX - this.centerPosX; other.petToPosY = otherPetPosY - this.centerPosY; other.petState = otherPetState; other.petSpeed = otherPetSpeed; if (other.petState == "walkFood") { GameObject food = GameObject.CreatePrimitive(PrimitiveType.Cube); food.name = "food_" + other.playerName; food.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); food.transform.position = new Vector3(other.petToPosX, 0, other.petToPosY); } if (other.petState == "walktoball") { GameObject otherBallFound = GameObject.Find("ball_" + otherUsername); if (otherBallFound == (GameObject)null) { GameObject otherBall = GameObject.CreatePrimitive(PrimitiveType.Sphere); otherBall.name = "ball_" + otherUsername; otherBall.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); otherBall.transform.position = new Vector3(other.petToPosX, 0.0f, other.petToPosY); Rigidbody ballRigibody = otherBall.AddComponent <Rigidbody>(); ballRigibody.mass = 1; ballRigibody.isKinematic = true; } } if (other.petState == "walkbringball") { GameObject otherBall = GameObject.Find("ball_" + otherUsername); GameObject otherPet = GameObject.Find("pet_" + otherUsername); otherBall.transform.position = otherPet.transform.position; otherBall.transform.parent = otherPet.transform; } GameObject otherPlayer = GameObject.Find(otherUsername); if (otherPlayer != (GameObject)null) { otherPlayer.transform.position = new Vector3(otherPosX - this.centerPosX, 10.0f, otherPosY - centerPosY); } } } } }
void InitMessage(SimpleJSON.JSONNode msg) { DebugMessage("get init message"); var transportType = msg["TransportType"] != null ? msg["TransportType"].Value : Undefined; var ids = msg["Ids"] != null ? msg["Ids"].AsArray : new SimpleJSON.JSONArray(); var add = msg["Add"] != null ? msg["Add"].AsBool : false; switch (transportType) { case "Baggage": if (!add) { foreach (var baggage in Baggages.Values) { Destroy(baggage); } Baggages = new Dictionary <string, MovementScript>(); } for (int i = 0; i < ids.Count; i++) { Baggages.Add(ids[i], Instantiate(BaggagePrefab, _baggageGarage, new Quaternion())); } break; case "Bus": if (!add) { foreach (var bus in Buses.Values) { Destroy(bus); } Buses = new Dictionary <string, MovementScript>(); } for (int i = 0; i < ids.Count; i++) { Buses.Add(ids[i], Instantiate(BusPrefab, _busGarage, new Quaternion())); } break; case "FollowMe": if (!add) { foreach (var followMe in FollowMes.Values) { Destroy(followMe); } FollowMes = new Dictionary <string, MovementScript>(); } for (int i = 0; i < ids.Count; i++) { FollowMes.Add(ids[i].Value, Instantiate(FollowMePrefab, _followMeGarage, new Quaternion())); } break; case "Fuel": if (!add) { foreach (var fuel in Fuels.Values) { Destroy(fuel); } Fuels = new Dictionary <string, MovementScript>(); } for (int i = 0; i < ids.Count; i++) { Fuels.Add(ids[i].Value, Instantiate(FuelPrefab, _fuelGarage, new Quaternion())); } break; default: DebugMessage(string.Format("Can not recognize transport type \"{0}\"", transportType)); break; } }
void AnimationMessage(SimpleJSON.JSONNode msg) { if (msg["Duration"] == null) { DebugMessage("Can not find Duration"); return; } var duration = msg["Duration"].AsInt; var transportArray = msg["Transport"].Value.Split('|'); if (transportArray.Length != 2) { DebugMessage(string.Format("Incorrect transport format: \"{0}\"", msg["Transport"].Value)); return; } var type = msg["AnimationType"] != null ? msg["AnimationType"].Value : Undefined; DebugMessage(string.Format("Get {0} animation message", type)); switch (type) { case "touchdown": case "wheelsup": { if (transportArray[0] != "Aircraft") { DebugMessage("Expected aircraft transport type"); return; } var aircraftGuid = transportArray[1]; if (msg["Strip"] == null) { DebugMessage("Expected strip number"); return; } var stripNum = msg["Strip"].AsInt; if (stripNum < 1 || stripNum > 3) { DebugMessage("Expected strip number from 1 to 3 in animation"); return; } var stripAway = Map.GetLocation("Strip" + stripNum + "Away").Value; var strip = Map.GetLocation("Strip" + stripNum).Value; var distance = Vector3.Distance(stripAway, strip); DebugMessage(string.Format("stripAway: {0} strip: {1} speed {2}", stripAway, strip, distance / duration * 1000)); switch (type) { case "touchdown": { Aircrafts.Add(aircraftGuid, Instantiate(AircraftPrefab, stripAway, new Quaternion())); Aircrafts[aircraftGuid].Set(stripAway, strip, distance / duration * 1000); break; } case "wheelsup": if (!Aircrafts.ContainsKey(aircraftGuid)) { DebugMessage(string.Format("Can not find aircraft with id = {0}", aircraftGuid)); return; } var aircraft = Aircrafts[aircraftGuid]; aircraft.Set(strip, stripAway, distance / duration * 1000); aircraft.DestroyAfterFinish = true; Aircrafts.Remove(aircraftGuid); break; } break; } case "baggage": { if (transportArray[0] != "Baggage") { DebugMessage("Expected baggage transport type"); return; } if (!Baggages.ContainsKey(transportArray[1])) { DebugMessage(string.Format("Unknown id of transport: \"{0}\"", transportArray[1])); return; } var baggage = Baggages[transportArray[1]]; var speed = 100000 / duration; var progressBar = Instantiate(CanvasRadialProgressBarPrefab, baggage.transform.position, new Quaternion()); progressBar.Speed = speed; break; } case "passengers": { if (transportArray[0] != "Bus") { DebugMessage("Expected bus transport type"); return; } if (!Buses.ContainsKey(transportArray[1])) { DebugMessage(string.Format("Unknown id of transport: \"{0}\"", transportArray[1])); return; } var bus = Buses[transportArray[1]]; var speed = 100000 / duration; var progressBar = Instantiate(CanvasRadialProgressBarPrefab, bus.transform.position, new Quaternion()); progressBar.Speed = speed; break; } case "filling": { { if (transportArray[0] != "Fuel") { DebugMessage("Expected bus transport type"); return; } if (!Fuels.ContainsKey(transportArray[1])) { DebugMessage(string.Format("Unknown id of transport: \"{0}\"", transportArray[1])); return; } var fuel = Fuels[transportArray[1]]; var speed = 100000 / duration; Debug.Log(string.Format("fuel.transform.position: {0}", fuel.transform.position)); var progressBar = Instantiate(CanvasRadialProgressBarPrefab, fuel.transform.position, new Quaternion()); progressBar.Speed = speed; progressBar.GetComponent <RectTransform>().position = fuel.transform.position; break; } } default: DebugMessage(string.Format("Can not reconize animation type: \"{0}\"", type)); break; } }
void MovementMessage(SimpleJSON.JSONNode msg) { DebugMessage("get movement message"); if (msg["Transport"] == null) { DebugMessage("Transport is undefined"); return; } var transportArray = msg["Transport"].Value.Split('|'); if (transportArray.Length != 2) { DebugMessage(string.Format("Incorrect transport format: \"{0}\"", msg["Transport"].Value)); return; } MovementScript transport = null; var key = transportArray[1]; switch (transportArray[0]) { case "Baggage": if (Baggages.ContainsKey(key)) { transport = Baggages[key]; } break; case "Bus": if (Buses.ContainsKey(key)) { transport = Buses[key]; } break; case "FollowMe": if (FollowMes.ContainsKey(key)) { transport = FollowMes[key]; } break; case "Fuel": if (Fuels.ContainsKey(key)) { transport = Fuels[key]; } break; default: DebugMessage(string.Format("Can not recognize transport type \"{0}\"", transportArray[0])); return; } if (transport == null) { DebugMessage(string.Format("Can not find transport with id \"{0}\"", key)); return; } MovementScript aircraft = null; if (transportArray[0] == "FollowMe" && msg["Aircraft"] != null) { var aircraftGuid = msg["Aircraft"].Value; if (Aircrafts.ContainsKey(aircraftGuid)) { aircraft = Aircrafts[aircraftGuid]; } } var from = msg["From"] != null?Map.GetLocation(msg["From"].Value) : null; var to = msg["To"] != null?Map.GetLocation(msg["To"].Value) : null; if (from == null || to == null) { DebugMessage("Can not find From or/and To Locations"); return; } if (msg["Duration"] == null) { DebugMessage("Can not find Duration"); return; } var duration = msg["Duration"].AsInt; var distance = Vector3.Distance(to.Value, from.Value); transport.Set(from.Value, to.Value, distance / duration * 1000); if (aircraft != null && !FollowMeSpecialLocations.Contains(msg["From"].Value)) { var aircraftFrom = aircraft.FinishPosition ?? transform.position; //самолет как будто догоняет "followMe", поэтому он едет к старту текущей локации для followMe var aicraftDistance = Vector3.Distance(aircraftFrom, from.Value); aircraft.Set(aircraftFrom, from.Value, aicraftDistance / duration * 1000); } }