/// <summary> /// Create a RouteNode. /// </summary> /// <param name="data">Parameters of the RouteNode to construct.</param> /// <param name="getEventInstance">Function to get an existing RouteEvent instance.</param> /// <param name="registerEventInstance">Function to register a RouteEvent instance.</param> /// <param name="createEvent">Function to create a RouteEvent.</param> /// <returns>Function to create a RouteNode.</returns> private static FoxLib.Tpp.RouteSet.RouteNode Create(RouteNode data, TryGetEventInstanceDelegate getEventInstance, RegisterEventInstanceDelegate registerEventInstance, CreateEventDelegate createEvent) { FoxLib.Tpp.RouteSet.RouteEvent edgeEvent; if (!getEventInstance(data.EdgeEvent, out edgeEvent)) { edgeEvent = createEvent(data.EdgeEvent); registerEventInstance(data.EdgeEvent, edgeEvent); } List <FoxLib.Tpp.RouteSet.RouteEvent> eventInstances = new List <FoxLib.Tpp.RouteSet.RouteEvent>(); foreach (var @event in data.Events) { FoxLib.Tpp.RouteSet.RouteEvent eventInstance; if (!getEventInstance(@event, out eventInstance)) { var newInstance = createEvent(@event); registerEventInstance(@event, newInstance); eventInstances.Add(newInstance); continue; } eventInstances.Add(eventInstance); } return(new FoxLib.Tpp.RouteSet.RouteNode( FoxUtils.UnityToFox(data.transform.position), edgeEvent, eventInstances.ToArray() )); }
/// <summary> /// Create a function to create RouteNode. /// </summary> /// <param name="getEventInstance">Function to get an existing RouteEvent instance.</param> /// <param name="registerEventInstance">Function to register a RouteEvent instance.</param> /// <param name="createEvent">Function to create a RouteEvent.</param> /// <returns>Function to create a RouteNode</returns> public static CreateNodeDelegate CreateFactory(TryGetEventInstanceDelegate getEventInstance, RegisterEventInstanceDelegate registerEventInstance, CreateEventDelegate createEvent) { return(data => Create(data, getEventInstance, registerEventInstance, createEvent)); }