/// <summary> /// Create a RouteNode. /// </summary> /// <param name="data">Parameters of the RouteNode.</param> /// <param name="routeSet">RouteSet the RouteNode belongs to.</param> /// <param name="route">Route the RouteNode belongs to.</param> /// <param name="name">Name of the RouteNode.</param> /// <param name="createEvent">Function to create a RouteEvent.</param> /// <returns>The constructed RouteNode.</returns> private static RouteNode Create(FoxLib.Tpp.RouteSet.RouteNode data, RouteSet routeSet, Route route, string name, CreateEventDelegate createNodeEvent, CreateEventDelegate createEdgeEvent) { var gameObject = new GameObject(name); var nodeComponent = gameObject.AddComponent <RouteNode>(); gameObject.transform.position = FoxUtils.FoxToUnity(data.Position); gameObject.transform.SetParent(route.transform); // TODO: Remove? We don't share event instances anymore. routeSet.RegisterRouteEvent(data.EdgeEvent, gameObject, createEdgeEvent); nodeComponent.Events = (from @event in data.Events select routeSet.RegisterRouteNodeEvent(@event, gameObject.transform, createNodeEvent)) .ToList(); return(nodeComponent); }
/// <summary> /// Create a function to create RouteNodes. /// </summary> /// <param name="createEvent">Function to create a RouteEvent.</param> /// <returns>Function to create RouteNodes.</returns> public static CreateNodeDelegate CreateFactory(CreateEventDelegate createNodeEvent, CreateEventDelegate createEdgeEvent) { return((data, routeSet, route, name) => Create(data, routeSet, route, name, createNodeEvent, createEdgeEvent)); }
/// <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)); }
/// <summary> /// Registers a route event instance. /// </summary> /// <param name="data">Raw data associated with the event.</param> /// <param name="owner">GameObject for the event to attach to.</param> /// <param name="createEvent">Function to create a new event.</param> /// <returns>The new, registered route event instance.</returns> public RouteEvent RegisterRouteEvent(FoxLib.Tpp.RouteSet.RouteEvent data, GameObject owner, CreateEventDelegate createEvent) { RouteEvent eventInstance = createEvent(owner, data); return(eventInstance); }
/// <summary> /// Registers a route event instance. /// </summary> /// <param name="data">Raw data associated with the event.</param> /// <param name="parent">Parent object of the event.</param> /// <param name="createEvent">Function to create a new event.</param> /// <returns>The new, registered route event instance.</returns> public RouteEdgeEvent RegisterRouteEdgeEvent(FoxLib.Tpp.RouteSet.RouteEvent data, Transform parent, CreateEventDelegate createEvent) { var eventGameObject = new GameObject(); eventGameObject.transform.position = parent.transform.position; eventGameObject.transform.SetParent(parent); var eventInstance = createEvent(eventGameObject, data); eventGameObject.name = eventInstance.Name; return(eventInstance as RouteEdgeEvent); }