private HeightfieldLayerSet(IntPtr root, int layerCount) { this.root = root; mLayerCount = layerCount; mLayers = new HeightfieldLayer[layerCount]; for (int i = 0; i < mLayerCount; i++) { HeightfieldLayer layer = new HeightfieldLayer(); HeightfieldLayserSetEx.nmlsGetLayer(root, i, layer); mLayers[i] = layer; } }
/// <summary> /// Frees and marks as disposed all resoures associated with the object. /// (Including its <see cref="HeightfieldLayer"/> objects.) /// </summary> public void RequestDisposal() { if (!IsDisposed) { HeightfieldLayserSetEx.nmlsFreeLayers(root); root = IntPtr.Zero; mLayerCount = 0; for (int i = 0; i < mLayers.Length; i++) { mLayers[i].Reset(); } } }
/// <summary> /// Builds a layer set from the <see cref="CompactHeightfield"/>. /// </summary> /// <param name="context">The context to use duing the operation.</param> /// <param name="field">The source field.</param> /// <returns>The resulting layer set, or null on failure.</returns> public static HeightfieldLayerSet Build(BuildContext context, CompactHeightfield field) { if (context == null) { return(null); } IntPtr ptr = IntPtr.Zero; int layerCount = HeightfieldLayserSetEx.nmlsBuildLayers(context.root , field , field.BorderSize , field.WalkableHeight , ref ptr); if (ptr == IntPtr.Zero) { return(null); } return(new HeightfieldLayerSet(ptr, layerCount)); }