예제 #1
0
        /// <summary>
        /// Tries to create a new node.
        /// </summary>
        /// <param name="position">Node position</param>
        /// <param name="netPrefab">A <see cref="NetInfo"/> object</param>
        /// <param name="nodeId">The id of new node</param>
        /// <returns>True if the node is created, false otherwise.</returns>
        public static bool TryCreateNode(Vector3 position, NetInfo netPrefab, out ushort nodeId)
        {
            // Gets managers
            var netManager = Singleton <NetManager> .instance;

            // Gets default randomizer
            var randomizer = SimulationUtils.GetRandomizer();

            LoggerUtils.Log("Creating node");

            // Create Node
            return(netManager.CreateNode(out nodeId, ref randomizer, netPrefab, position, SimulationUtils.GetNewBuildIndex()));
        }
예제 #2
0
        /// <summary>
        /// Tries to create a new segment
        /// </summary>
        /// <param name="idStartNode">Id of start node</param>
        /// <param name="startPosition">Position of start node</param>
        /// <param name="idEndNode">Id of end node</param>
        /// <param name="endPosition">Position of end node</param>
        /// <param name="netPrefab">A <see cref="NetInfo"/> object</param>
        /// <param name="segmentId">The id of new segment</param>
        /// <returns>True if the segment is created, false otherwise.</returns>
        public static bool TryCreateSegment(ushort idStartNode, Vector3 startPosition, ushort idEndNode, Vector3 endPosition, NetInfo netPrefab, out ushort segmentId)
        {
            // Gets managers
            var netManager = Singleton <NetManager> .instance;

            // Gets default randomizer
            var randomizer = SimulationUtils.GetRandomizer();

            LoggerUtils.Log("Creating net");

            var startDirection = endPosition - startPosition;
            var endDirection   = startPosition - endPosition;

            if (startDirection.magnitude > 80)
            {
                LoggerUtils.Warning("The length of the segment is longer that the recommend (80 units)");
            }

            var buildIndex = SimulationUtils.GetNewBuildIndex();

            // Create segment
            return(netManager.CreateSegment(out segmentId, ref randomizer, netPrefab, idStartNode, idEndNode, startDirection.normalized, endDirection.normalized, buildIndex, buildIndex, false));
        }