/// <summary> /// Creates map nodes for all spawn points of the given type. /// </summary> /// <param name="item">The company item.</param> /// <param name="spawnPointType">The spawn point type.</param> /// <param name="node0Pos">The ppd position of the prefab's red control node.</param> /// <returns>A list of map nodes.</returns> private List <INode> CreateSpawnPointNodes(PrefabSlaveItem item, SpawnPointType spawnPointType) { var selected = clonedPoints.Where(x => x.Type == spawnPointType).ToList(); var list = new List <INode>(selected.Count); foreach (var spawnPoint in selected) { var spawnPos = GetAbsolutePosition(spawnPoint.Position); var spawnNode = map.AddNode(spawnPos, false); spawnNode.Rotation = Quaternion.Normalize( spawnPoint.Rotation * prefabRot); spawnNode.ForwardItem = item; list.Add(spawnNode); } for (int i = 0; i < selected.Count; i++) { clonedPoints.Remove(selected[i]); } return(list); }
/// <summary> /// Base method for adding a new SingleNodeItem to the map. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="map"></param> /// <param name="position"></param> /// <returns></returns> internal static T Add <T>(IItemContainer map, Vector3 position) where T : SingleNodeItem, new() { var node = map.AddNode(position, true); var newItem = new T(); newItem.Node = node; newItem.Node.ForwardItem = newItem; map.AddItem(newItem); return(newItem); }
/// <summary> /// Creates a single, unconnected item. /// <para>This method will create an empty item, add two new nodes to /// the map, update fwd/bwd references and then add the item to the map. /// </para> /// </summary> /// <typeparam name="T">The type of the item that will be created.</typeparam> /// <param name="map">The map the item will be added to.</param> /// <param name="backwardPos">The backward position of the item.</param> /// <param name="forwardPos">The forward position of the item.</param> /// <returns>A new, empty item which has been added to the map.</returns> internal static T Add <T>(IItemContainer map, Vector3 backwardPos, Vector3 forwardPos) where T : PolylineItem, new() { var backwardNode = map.AddNode(backwardPos, true); var forwardNode = map.AddNode(forwardPos, false); var newItem = new T(); backwardNode.ForwardItem = newItem; forwardNode.BackwardItem = newItem; newItem.Node = backwardNode; newItem.ForwardNode = forwardNode; // rotation: // for the first two nodes, the Rotation of the nodes is just // the angle formed by pos2-pos1 and the Z axis var rotation = MathEx.GetNodeRotation(backwardPos, forwardPos); newItem.Node.Rotation = rotation; newItem.ForwardNode.Rotation = rotation; map.AddItem(newItem); return(newItem); }
/// <summary> /// Creates map nodes for this item. /// </summary> /// <param name="map"></param> /// <param name="nodePositions"></param> /// <param name="item"></param> protected static void CreateNodes(IItemContainer map, IList <Vector3> nodePositions, MultiNodeItem item) { // all nodes have the item as ForwardItem; // how the nodes connect is determined by their position in the list only for (int i = 0; i < nodePositions.Count; i++) { var node = map.AddNode(nodePositions[i]); if (i == 0) { // one node has to have the red node flag. // without it, the item can't be deleted. node.IsRed = true; } node.ForwardItem = item; item.Nodes.Add(node); } }