/// <summary> /// Create a Route. /// </summary> /// <param name="data">Parameters of the Route to construct.</param> /// <param name="routeSet">RouteSet the Route belongs to.</param> /// <param name="createNode">Function to create a RouteNode.</param> /// <param name="getRouteName">Function to get a Route's name.</param> /// <param name="generateNodeName">Function to generate a RouteNode name.</param> /// <returns>The constructed Route.</returns> private static Route Create(FoxLib.Tpp.RouteSet.Route data, RouteSet routeSet, CreateNodeDelegate createNode, TryUnhashDelegate <uint> getRouteName, GenerateNodeNameDelegate generateNodeName) { var gameObject = new GameObject(); var routeComponent = gameObject.AddComponent <Route>(); var routeNameContainer = getRouteName(data.Name); if (routeNameContainer.WasNameUnhashed) { gameObject.name = routeNameContainer.UnhashedString; } else { gameObject.name = routeNameContainer.Hash.ToString(); routeComponent.TreatNameAsHash = true; } routeComponent.Nodes = data.Nodes .Select((node, index) => createNode.Invoke(node, routeSet, routeComponent, generateNodeName(gameObject.name, index))) .ToList(); return(routeComponent); }
/// <summary> /// Create a function to create Routes. /// </summary> /// <param name="createNode">Function to create a RouteNode.</param> /// <param name="getRouteName">Function to get a Route's name.</param> /// <param name="generateNodeName">Function to generate a RouteNode name.</param> /// <returns>Function to construct Routes.</returns> public static CreateRouteDelegate CreateFactory(CreateNodeDelegate createNode, TryUnhashDelegate <uint> getRouteName, GenerateNodeNameDelegate generateNodeName) { return((data, routeSet) => Create(data, routeSet, createNode, getRouteName, generateNodeName)); }
private static IEnumerable <TNode> TreeWalkImpl <T, TNode>(IEnumerable <T> root, Func <T, IEnumerable <T> > getChildren, CreateNodeDelegate <T, TNode> createNode, T parent) { foreach (var node in root) { yield return(createNode(parent, node)); var children = getChildren(node); if (children != null) { foreach (var child in TreeWalkImpl(children, getChildren, createNode, node)) { yield return(child); } } } }
/// <summary> /// Enumerates every node of a tree structure using pre-order walk traversing method. /// </summary> /// <typeparam name="T">The type of the nodes.</typeparam> /// <typeparam name="TNode">The type of the resulting nodes.</typeparam> /// <param name="root">A sequence containing the root nodes.</param> /// <param name="getChildren">A function that returns the children of a node.</param> /// <param name="createNode">A function that takes the .</param> /// <returns></returns> public static IEnumerable <TNode> TreeWalk <T, TNode>(this IEnumerable <T> root, Func <T, IEnumerable <T> > getChildren, CreateNodeDelegate <T, TNode> createNode) { if (root == null) { throw new ArgumentNullException("root"); } if (getChildren == null) { throw new ArgumentNullException("getChildren"); } if (createNode == null) { throw new ArgumentNullException("createNode"); } return(TreeWalkImpl(root, getChildren, createNode, default(T))); }
/// <summary> /// Create a Route. /// </summary> /// <param name="data">Parameters of the Route to construct.</param> /// <param name="getRouteNameHash">Function to get the StrCode32 hash of a Route's name.</param> /// <param name="createNode">Function to create a RouteNode.</param> /// <returns>The constructed Route.</returns> private static FoxLib.Tpp.RouteSet.Route Create(Route data, GetRouteNameHashDelegate getRouteNameHash, CreateNodeDelegate createNode) { var nodes = from node in data.Nodes select createNode(node); return(new FoxLib.Tpp.RouteSet.Route(getRouteNameHash(data), nodes.ToArray())); }
/// <summary> /// Create a function to create Routes. /// </summary> /// <param name="createNode">Function to create a RouteNode.</param> /// <param name="getRouteNameHash">Function to get the StrCode32 hash of a Route's name.</param> /// <returns>Function to create a Route.</returns> public static CreateRouteDelegate CreateFactory(CreateNodeDelegate createNode, GetRouteNameHashDelegate getRouteNameHash) { return(data => Create(data, getRouteNameHash, createNode)); }