Ejemplo n.º 1
0
        public static ushort CreateSegment(ushort startNodeId, ushort endNodeId, Vector3 startDirection, Vector3 endDirection, NetInfo netInfo, bool invert = false, bool switchStartAndEnd = false, bool dispatchPlacementEffects = false)
        {
            var randomizer = Singleton <SimulationManager> .instance.m_randomizer;

            NetNode startNode = Node(startNodeId);
            NetNode endNode   = Node(endNodeId);

            if ((startNode.m_flags & NetNode.Flags.Created) == NetNode.Flags.None || (endNode.m_flags & NetNode.Flags.Created) == NetNode.Flags.None)
            {
                throw new Exception("Failed to create NetSegment: Invalid node(s)");
            }

            var result = NetManager.instance.CreateSegment(out ushort newSegmentId, ref randomizer, netInfo, switchStartAndEnd ? endNodeId : startNodeId,
                                                           switchStartAndEnd ? startNodeId : endNodeId,
                                                           (switchStartAndEnd ? endDirection : startDirection), (switchStartAndEnd ? startDirection : endDirection), Singleton <SimulationManager> .instance.m_currentBuildIndex,
                                                           Singleton <SimulationManager> .instance.m_currentBuildIndex, invert);

            if (!result)
            {
                throw new Exception("Failed to create NetSegment");
            }

            Singleton <SimulationManager> .instance.m_currentBuildIndex++;

            if (dispatchPlacementEffects)
            {
                bool smoothStart = (startNode.m_flags & NetNode.Flags.Middle) != NetNode.Flags.None;
                bool smoothEnd   = (endNode.m_flags & NetNode.Flags.Middle) != NetNode.Flags.None;
                NetSegment.CalculateMiddlePoints(startNode.m_position, startDirection, endNode.m_position, endDirection, smoothStart, smoothEnd, out Vector3 b, out Vector3 c);
                NetTool.DispatchPlacementEffect(startNode.m_position, b, c, endNode.m_position, netInfo.m_halfWidth, false);
            }

            return(newSegmentId);
        }