/// <summary> /// Handles the Claim Action Message from the server. Passes the data onto the voxel editor. /// </summary> /// <param name="props">Properties.</param> public void ClaimObjectMessage(Dictionary <string, object> props) { // Debug.LogError("ClaimObjectMessage "); try { int objectID = (int)props["id"]; int templateID = (int)props["templateID"]; string prefabName = (string)props["gameObject"]; Vector3 loc = (Vector3)props["loc"]; Quaternion orient = (Quaternion)props["orient"]; int claimID = (int)props["claimID"]; //string state = (string)props["state"]; AtavismLogger.LogDebugMessage("Got claim object: " + gameObject); //SpawnClaimObject(objectID, claimID, prefabName, loc, orient); ClaimObjectData objectData = new ClaimObjectData(); objectData.objectID = objectID; objectData.claimID = claimID; objectData.templateID = templateID; objectData.prefabName = prefabName; objectData.loc = loc; objectData.orient = orient; objectData.state = ""; objectData.health = (int)props["health"]; objectData.maxHealth = (int)props["maxHealth"]; objectData.complete = (bool)props["complete"]; objectsToLoad.Add(objectData); } catch (System.Exception e) { Debug.LogError("ClaimObjectMessage Exception=" + e); } // Debug.LogError("ClaimObjectMessage objectsToLoad=" + objectsToLoad.Count); }
void SpawnClaimObject(ClaimObjectData objectData) { // Add the gameObject to the claim Claim claim = GetClaim(objectData.claimID); if (claim == null) { AtavismLogger.LogWarning("No Claim found for Claim Object"); return; } if (claim.claimObjects.ContainsKey(objectData.objectID)) { return; } // Spawn the object in the world string prefabName = objectData.prefabName; int resourcePathPos = prefabName.IndexOf("Resources/"); prefabName = prefabName.Substring(resourcePathPos + 10); prefabName = prefabName.Remove(prefabName.Length - 7); GameObject prefab = (GameObject)Resources.Load(prefabName); if (prefab == null) { Debug.LogError("Builder prefab " + prefabName + " not found in the resources"); return; } GameObject claimObject = (GameObject)UnityEngine.Object.Instantiate(prefab, objectData.loc + claim.loc, objectData.orient); // TEMP: set claim object to don't delete on load DontDestroyOnLoad(claimObject); // Get the Claim Object Component ClaimObject cObject = claimObject.GetComponentInChildren <ClaimObject>(); if (cObject == null) { cObject = claimObject.AddComponent <ClaimObject>(); } cObject.ClaimID = objectData.claimID; cObject.StateUpdated(objectData.state); cObject.ID = objectData.objectID; cObject.TemplateID = objectData.templateID; cObject.Health = objectData.health; cObject.MaxHealth = objectData.maxHealth; cObject.Complete = objectData.complete; //cObject.ItemReqs = objectData. claim.claimObjects.Add(objectData.objectID, cObject); if (cObject.ID == selectedID) { SelectedObject = cObject; } }
/// <summary> /// Handles the Claim Action Bulk Message which is used to transfer large amounts of actions at once. /// </summary> /// <param name="props">Properties.</param> public void ClaimObjectBulkMessage(Dictionary <string, object> props) { // Debug.LogError("ClaimObjectBulkMessage "); try { int numObjects = (int)props["numObjects"]; AtavismLogger.LogDebugMessage("Got numObjects: " + numObjects); for (int i = 0; i < numObjects; i++) { string actionString = (string)props["object_" + i]; string[] actionData = actionString.Split(';'); string objectID = actionData[0]; string templateID = actionData[1]; string gameObject = actionData[2]; string[] locData = actionData[3].Split(','); // Debug.LogError("ClaimObjectBulkMessage Loc=>"+string.Join("|",locData) +"< string="+ actionData[3]); Vector3 loc = new Vector3(float.Parse(locData[0]), float.Parse(locData[1]), float.Parse(locData[2])); string[] normalData = actionData[4].Split(','); // Debug.LogError("ClaimObjectBulkMessage Rot=>" + string.Join("|", normalData) + "< string=" + actionData[4]); Quaternion orient = new Quaternion(float.Parse(normalData[0]), float.Parse(normalData[1]), float.Parse(normalData[2]), float.Parse(normalData[3])); string state = actionData[5]; int health = int.Parse(actionData[6]); int maxHealth = int.Parse(actionData[7]); bool complete = bool.Parse(actionData[8]); //SpawnClaimObject(int.Parse(objectID), int.Parse(claimID), gameObject, loc, orient); ClaimObjectData objectData = new ClaimObjectData(); objectData.objectID = int.Parse(objectID); objectData.templateID = int.Parse(templateID); objectData.claimID = (int)props["claimID"]; objectData.prefabName = gameObject; objectData.loc = loc; objectData.orient = orient; objectData.state = state; objectData.health = health; objectData.maxHealth = maxHealth; objectData.complete = complete; objectsToLoad.Add(objectData); } } catch (System.Exception e) { Debug.LogError("ClaimObjectBulkMessage Exception=" + e); } // Debug.LogError("ClaimObjectBulkMessage objectsToLoad=" + objectsToLoad.Count); }