コード例 #1
0
ファイル: NetworkEdge.cs プロジェクト: zhechkoz/MMK
        override public NetworkLane GetLaneByID(string id)
        {
            NetworkLane searchedLane = forwardLanes.Find(lane => lane.id == id);

            if (searchedLane == null)
            {
                searchedLane = backwardLanes.Find(lane => lane.id == id);
            }

            return(searchedLane);
        }
コード例 #2
0
        private void BuildConnectivityGraph(JSONNode root)
        {
            foreach (JSONNode connectionJSON in root["connections"].AsArray.Children)
            {
                string fromLaneID = connectionJSON ["fromLane"];
                string toLaneID   = connectionJSON ["toLane"];

                List <NetworkLane> viaLanes = new List <NetworkLane> ();
                foreach (string laneID in connectionJSON["via"].AsArray.Children)
                {
                    NetworkLane viaLane = GetLaneByID(laneID);
                    if (viaLane == null)
                    {
                        Debug.Log("viaLane does not exist!");
                        continue;
                    }
                    viaLanes.Add(viaLane);
                }

                NetworkLaneConnection connection;
                if (connectivityGraph.TryGetValue(fromLaneID, out connection))
                {
                    connection.AppendLane(toLaneID, viaLanes);
                }
                else
                {
                    NetworkLane fromLane = GetLaneByID(fromLaneID);

                    if (fromLane == null)
                    {
                        Debug.Log("Lane " + fromLaneID + " does not exist!");
                        continue;
                    }

                    connection = new NetworkLaneConnection(fromLane);
                    connection.AppendLane(toLaneID, viaLanes);
                    connectivityGraph.Add(fromLaneID, connection);
                }

                if (!connectivityGraph.ContainsKey(toLaneID))
                {
                    NetworkLane toLane = GetLaneByID(toLaneID);
                    if (toLane == null)
                    {
                        Debug.Log("Lane " + toLaneID + " does not exist!");
                        continue;
                    }
                    connectivityGraph.Add(toLaneID, new NetworkLaneConnection(toLane));
                }
            }
        }
コード例 #3
0
ファイル: NetworkLane.cs プロジェクト: zhechkoz/MMK
        public static NetworkLane DeserializeFromJSON(JSONNode laneJSON)
        {
            string      id     = laneJSON ["id"];
            int         index  = laneJSON ["lane"];
            double      length = laneJSON ["length"];
            NetworkLane lane   = new NetworkLane(id, index, length);

            JSONArray jsonVertices = laneJSON ["vertices"].AsArray;

            foreach (JSONNode jsonVertex in jsonVertices)
            {
                float x = jsonVertex ["x"].AsFloat;
                float y = jsonVertex ["y"].AsFloat;
                float z = jsonVertex ["z"].AsFloat;
                lane.vertices.Add(new Vector3(x, y, z));
            }

            return(lane);
        }
コード例 #4
0
        private void BuildNetwork(JSONNode root)
        {
            foreach (JSONNode laneJSON in root["lanes"].AsArray.Children)
            {
                NetworkLane lane = NetworkLane.DeserializeFromJSON(laneJSON);
                lanes [lane.id] = lane;
            }

            GameObject networkDescription = new GameObject("RoadsDescription");

            foreach (JSONNode segmentJSON in root["segments"].AsArray.Children)
            {
                GameObject roadSegment =
                    CreateGameObject(NetworkComponentType.Edge, segmentJSON, networkDescription);
                networkItems.Add(roadSegment.name, roadSegment);
            }

            foreach (JSONNode nodeJSON in root["nodes"].AsArray.Children)
            {
                GameObject roadSegment =
                    CreateGameObject(NetworkComponentType.Node, nodeJSON, networkDescription);
                networkItems.Add(roadSegment.name, roadSegment);
            }
        }
コード例 #5
0
ファイル: NetworkLaneConnection.cs プロジェクト: zhechkoz/MMK
 public NetworkLaneConnection(NetworkLane lane)
 {
     this.lane          = lane;
     this.adjacentLanes = new List <string> ();
     this.via           = new Dictionary <string, List <NetworkLane> > ();
 }