Exemplo n.º 1
0
    /// <summary>
    /// Creates a Road Lattice debug object for currently loaded map, and clears any partial path
    /// finding display and state.
    /// </summary>
    /// <remarks>
    /// Configured through the Unity editor as a handler for the DidModifyLattice event.
    /// </remarks>
    /// <param name="args">Map loaded arguments</param>
    public void HandleDidModifyLattice(DidModifyRoadLatticeArgs args)
    {
        if (RoadLatticeDebugObject != null)
        {
            Destroy(RoadLatticeDebugObject);
        }

        RoadLatticeDebugObject = RoadLatticeTools.MakeRoadLatticeDebugGameObject(
            args.RoadLattice, LatticeMaterials, IndicateNodes, ShowPartitioned);
        RoadLatticeDebugObject.transform.Translate(Vector3.up * LatticeDisplayY);
        RoadLatticeDebugObject.transform.SetParent(transform, false);
    }
Exemplo n.º 2
0
        /// <summary>
        /// MapLoaded handler that creates a Road Lattice debug object for currently loaded map.
        /// </summary>
        /// <param name="args">Map loaded arguments</param>
        public void ShowRoadLattice(DidModifyRoadLatticeArgs args)
        {
            if (RoadLatticeDebugObject != null)
            {
                Destroy(RoadLatticeDebugObject);
            }

            RoadLatticeDebugObject = RoadLatticeTools.MakeAttributedLatticeDebugGameObject(
                args.RoadLattice, LatticeMaterials, IndicateNodes);
            RoadLatticeDebugObject.transform.Translate(Vector3.up);
            RoadLatticeDebugObject.transform.SetParent(transform, false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// RoadLattice handler that creates a Road Lattice debug object for currently loaded map.
        /// </summary>
        /// <param name="args">RoadLattice event data</param>
        void OnModifiedRoadLattice(DidModifyRoadLatticeArgs args)
        {
            if (RoadLattice != null)
            {
                // Deletes the previous road lattice debug object
                if (RoadLatticeDebugObject != null)
                {
                    Destroy(RoadLatticeDebugObject);
                }

                RoadLatticeDebugObject = RoadLatticeTools.MakeRoadLatticeDebugGameObject(
                    args.RoadLattice, LatticeMaterials, IndicateNodes, ShowPartitioned);
                RoadLatticeDebugObject.transform.Translate(Vector3.up);
                RoadLatticeDebugObject.transform.SetParent(RoadLattice.transform, false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Spawns as many vehicles as specified by <see cref="VehiclesToSpawn"/>.
        /// </summary>
        private void OnRoadLatticeModified(DidModifyRoadLatticeArgs args)
        {
            // Get the nodes in the road lattice.
            List <RoadLatticeNode> nodes = new List <RoadLatticeNode>(args.RoadLattice.Nodes);

            for (; VehiclesToSpawn > 0; VehiclesToSpawn--)
            {
                // Get a random node to spawn a vehicle on.
                RoadLatticeNode spawnNode = nodes[Random.Range(0, nodes.Count)];

                // Instantiate a random vehicle.
                Vehicle vehiclePrefab = Vehicles[Random.Range(0, Vehicles.Length)];
                Vehicle vehicle       = Instantiate(vehiclePrefab);

                // Initialize it at the spawn node.
                vehicle.Initialize(TrafficSystem, spawnNode);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Spawns as many vehicles as specified by <see cref="VehiclesToSpawn"/>.
        /// </summary>
        private void OnRoadLatticeModified(DidModifyRoadLatticeArgs args)
        {
            // Get all traversable nodes in the road lattice.
            List <RoadLatticeNode> nodes = new List <RoadLatticeNode>();

            foreach (RoadLatticeNode node in args.RoadLattice.Nodes)
            {
                foreach (RoadLatticeEdge edge in node.Edges)
                {
                    if (!Vehicle.IsTraversableRoad(edge.Segment))
                    {
                        continue;
                    }

                    nodes.Add(node);
                    break;
                }
            }

            // Don't spawn any vehicles if we have no traversable nodes to spawn them  on.
            if (nodes.Count == 0)
            {
                return;
            }

            for (; VehiclesToSpawn > 0; VehiclesToSpawn--)
            {
                // Get a random node to spawn a vehicle on.
                RoadLatticeNode spawnNode = nodes[Random.Range(0, nodes.Count)];

                // Instantiate a random vehicle.
                Vehicle vehiclePrefab = Vehicles[Random.Range(0, Vehicles.Length)];
                Vehicle vehicle       = Instantiate(vehiclePrefab);

                // Initialize it at the spawn node.
                vehicle.Initialize(TrafficSystem, spawnNode);
            }
        }