summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Core/Misc/GraphSnapshot.cs
blob: 4b21d17e09853b781c78e38c7bbe3873a1d447f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections.Generic;
using UnityEngine.Profiling;

namespace Pathfinding.Util {
	public interface IGraphSnapshot : System.IDisposable {
		/// <summary>
		/// Restores the graph data to the state it had when the snapshot was taken, in the bounding box that the snapshot captured.
		///
		/// You can get the context from the callback provided to the <see cref="AstarPath.AddWorkItem"/> method.
		/// </summary>
		void Restore(IGraphUpdateContext ctx);
	}

	/// <summary>
	/// A snapshot of parts of graphs.
	///
	/// See: <see cref="AstarPath.Snapshot"/>
	/// </summary>
	public struct GraphSnapshot : IGraphSnapshot {
		List<IGraphSnapshot> inner;

		internal GraphSnapshot (List<IGraphSnapshot> inner) {
			this.inner = inner;
		}

		/// <summary>\copydocref{IGraphSnapshot.Restore}</summary>
		public void Restore (IGraphUpdateContext ctx) {
			Profiler.BeginSample("Restoring Graph Snapshot");
			for (int i = 0; i < inner.Count; i++) {
				inner[i].Restore(ctx);
			}
			Profiler.EndSample();
		}

		public void Dispose () {
			if (inner != null) {
				for (int i = 0; i < inner.Count; i++) {
					inner[i].Dispose();
				}
				inner = null;
			}
		}
	}
}