/** * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary> * <param name = "stringData">The data, serialised as a string</param> */ public override void LoadData(string stringData) { NavMesh2DData data = Serializer.LoadScriptData <NavMesh2DData> (stringData); if (data == null) { return; } SavePrevented = data.savePrevented; if (savePrevented) { return; } if (GetComponent <NavigationMesh>()) { NavigationMesh navMesh = GetComponent <NavigationMesh>(); navMesh.polygonColliderHoles.Clear(); KickStarter.navigationManager.navigationEngine.ResetHoles(navMesh); if (!string.IsNullOrEmpty(data._linkedIDs)) { int[] linkedIDs = StringToIntArray(data._linkedIDs); for (int i = 0; i < linkedIDs.Length; i++) { PolygonCollider2D polyHole = Serializer.returnComponent <PolygonCollider2D> (linkedIDs[i]); if (polyHole != null) { navMesh.AddHole(polyHole); } } } } }
/** * <summary>Serialises appropriate GameObject values into a string.</summary> * <returns>The data, serialised as a string</returns> */ public override string SaveData() { NavMesh2DData navMesh2DData = new NavMesh2DData(); navMesh2DData.objectID = constantID; navMesh2DData.savePrevented = savePrevented; if (GetComponent <NavigationMesh>()) { NavigationMesh navMesh = GetComponent <NavigationMesh>(); List <int> linkedIDs = new List <int>(); for (int i = 0; i < navMesh.polygonColliderHoles.Count; i++) { if (navMesh.polygonColliderHoles[i].GetComponent <ConstantID>()) { linkedIDs.Add(navMesh.polygonColliderHoles[i].GetComponent <ConstantID>().constantID); } else { ACDebug.LogWarning("Cannot save " + this.gameObject.name + "'s holes because " + navMesh.polygonColliderHoles[i].gameObject.name + " has no Constant ID!"); } } navMesh2DData._linkedIDs = ArrayToString <int> (linkedIDs.ToArray()); } return(Serializer.SaveScriptData <NavMesh2DData> (navMesh2DData)); }
/** * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary> * <param name = "stringData">The data, serialised as a string</param> */ public override void LoadData(string stringData) { NavMesh2DData data = Serializer.LoadScriptData <NavMesh2DData> (stringData); if (data == null) { return; } if (GetComponent <NavigationMesh>()) { NavigationMesh navMesh = GetComponent <NavigationMesh>(); navMesh.polygonColliderHoles.Clear(); if (data._linkedIDs.Length > 0) { int[] linkedIDs = StringToIntArray(data._linkedIDs); for (int i = 0; i < linkedIDs.Length; i++) { PolygonCollider2D polyHole = Serializer.returnComponent <PolygonCollider2D> (linkedIDs[i]); if (polyHole != null) { navMesh.AddHole(polyHole); } } } } }
public override string SaveData() { NavMesh2DData navMesh2DData = new NavMesh2DData (); navMesh2DData.objectID = constantID; if (GetComponent <NavigationMesh>()) { NavigationMesh navMesh = GetComponent <NavigationMesh>(); List<int> linkedIDs = new List<int>(); for (int i=0; i<navMesh.polygonColliderHoles.Count; i++) { if (navMesh.polygonColliderHoles[i].GetComponent <ConstantID>()) { linkedIDs.Add (navMesh.polygonColliderHoles[i].GetComponent <ConstantID>().constantID); } else { Debug.LogWarning ("Cannot save " + this.gameObject.name + "'s holes because " + navMesh.polygonColliderHoles[i].gameObject.name + " has no Constant ID!"); } } navMesh2DData._linkedIDs = ArrayToString <int> (linkedIDs.ToArray ()); } return Serializer.SaveScriptData <NavMesh2DData> (navMesh2DData); }
public NavMesh2DData SaveData () { NavMesh2DData navMesh2DData = new NavMesh2DData (); navMesh2DData.objectID = constantID; if (GetComponent <NavigationMesh>()) { NavigationMesh navMesh = GetComponent <NavigationMesh>(); navMesh2DData.linkedIDs = new List<int>(); for (int i=0; i<navMesh.polygonColliderHoles.Count; i++) { if (navMesh.polygonColliderHoles[i].GetComponent <ConstantID>()) { navMesh2DData.linkedIDs.Add (navMesh.polygonColliderHoles[i].GetComponent <ConstantID>().constantID); } else { Debug.LogWarning ("Cannot save " + this.gameObject.name + "'s holes because " + navMesh.polygonColliderHoles[i].gameObject.name + " has no Constant ID!"); } } } return navMesh2DData; }
public void LoadData (NavMesh2DData data) { if (GetComponent <NavigationMesh>()) { NavigationMesh navMesh = GetComponent <NavigationMesh>(); navMesh.polygonColliderHoles.Clear (); for (int i=0; i<data.linkedIDs.Count; i++) { PolygonCollider2D polyHole = Serializer.returnComponent <PolygonCollider2D> (data.linkedIDs[i]); if (polyHole != null) { navMesh.AddHole (polyHole); } } } }