예제 #1
0
        private void ExportWays()
        {
            NetManager netManager = Singleton <NetManager> .instance;

            NetSegment[] netSegments = netManager.m_segments.m_buffer;
            for (int segmentId = 0; segmentId < netSegments.Length; segmentId++)
            {
                NetSegment       netSegment   = netSegments[segmentId];
                NetSegment.Flags segmentFlags = netSegment.m_flags;

                if (segmentFlags.IsFlagSet(NetSegment.Flags.Created))
                {
                    OSMWay generatedWay = CreateWay(unindexedWayOffset++, netSegment, (ushort)segmentId);

                    if (generatedWay != null)
                    {
                        osmWays.Add(generatedWay);
                    }
                }
            }
        }
예제 #2
0
        private OSMWay CreateWay(int index, NetSegment segment, ushort segmentId)
        {
            OSMWay returnWay = null;

            NetSegment.Flags segmentFlags = segment.m_flags;
            NetManager       netManager   = Singleton <NetManager> .instance;
            List <OSMWayND>  wayPaths     = new List <OSMWayND>();
            List <OSMWayTag> wayTags;
            ushort           startNodeId = segment.m_startNode, endNodeId = segment.m_endNode;

            if (startNodeId != 0 && endNodeId != 0)
            {
                Vector3 startNodeDirection = segment.m_startDirection;
                Vector3 endNodeDirection   = segment.m_endDirection;

                if (segmentFlags.IsFlagSet(NetSegment.Flags.Invert))
                {
                    startNodeId        = segment.m_endNode;
                    endNodeId          = segment.m_startNode;
                    startNodeDirection = segment.m_endDirection;
                    endNodeDirection   = segment.m_startDirection;
                }

                NetNode startNode         = netManager.m_nodes.m_buffer[startNodeId];
                NetNode endNode           = netManager.m_nodes.m_buffer[endNodeId];
                Vector3 startNodePosition = startNode.m_position;
                Vector3 endNodePosition   = endNode.m_position;

                wayPaths.Add(new OSMWayND {
                    @ref = startNodeId
                });

                if (Vector3.Angle(startNodeDirection, -endNodeDirection) > 3f)
                {
                    Vector3 midPointA = Vector3.zero, midPointB = Vector3.zero;
                    NetSegment.CalculateMiddlePoints(startNodePosition, startNodeDirection, endNodePosition, endNodeDirection, false, false, out midPointA, out midPointB);
                    Bezier3 bezier = new Bezier3(startNodePosition, midPointA, midPointB, endNodePosition);

                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.25f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.5f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.75f)));

                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 3
                    });
                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 2
                    });
                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 1
                    });
                }

                wayPaths.Add(new OSMWayND {
                    @ref = endNodeId
                });

                if (Tagger.CreateWayTags(segment, out wayTags))
                {
                    if (haveRoadNamerMod)
                    {
                        // If road namer mod is available, then attempt to get the name asscociated with the segment, if any
                        string roadName = RoadNamerManager.Instance().getSegmentName((ushort)(segmentId));
                        if (roadName != null)
                        {
                            //If a name is available, add a name tag
                            wayTags.Add(new OSMWayTag {
                                k = "name", v = StringUtilities.RemoveTags(roadName)
                            });
                        }
                    }
                    returnWay = new OSMWay {
                        changeset = 50000000, id = (uint)index, timestamp = DateTime.Now, user = "******", nd = wayPaths.ToArray(), tag = wayTags.ToArray(), version = 1
                    };
                }
                else
                {
                    UniqueLogger.AddLog("Road names missing from search", segment.Info.name, "");
                }
            }

            return(returnWay);
        }
예제 #3
0
        /// <summary>
        /// Redraw the text to be drawn later with a mesh. Use sparingly, as
        /// this is an expensive task.
        /// </summary>
        private void RenderText()
        {
            DistrictManager districtManager = DistrictManager.instance;
            NetManager      netManager      = NetManager.instance;

            if (districtManager.m_properties.m_areaNameFont != null)
            {
                UIFontManager.Invalidate(districtManager.m_properties.m_areaNameFont);

                foreach (RouteContainer route in RouteManager.Instance().m_routeDict.Values)
                {
                    if (route.m_segmentId != 0)
                    {
                        string routeStr = route.m_route;

                        if (routeStr != null)
                        {
                            NetSegment       netSegment   = netManager.m_segments.m_buffer[route.m_segmentId];
                            NetSegment.Flags segmentFlags = netSegment.m_flags;

                            if (segmentFlags.IsFlagSet(NetSegment.Flags.Created))
                            {
                                //Load a route shield type ( generic motorway shield should be default value )
                                RouteShieldInfo shieldInfo = RouteShieldConfig.Instance().GetRouteShieldInfo(route.m_routePrefix);

                                NetNode startNode         = netManager.m_nodes.m_buffer[netSegment.m_startNode];
                                NetNode endNode           = netManager.m_nodes.m_buffer[netSegment.m_endNode];
                                Vector3 startNodePosition = startNode.m_position;

                                if (!SpriteUtils.m_textureStore.ContainsKey(shieldInfo.textureName))
                                {
                                    LoggerUtils.Log("WTF, No texture found for route shield" + shieldInfo.textureName);
                                }
                                Material mat = SpriteUtils.m_textureStore[shieldInfo.textureName];
                                route.m_shieldObject.GetComponent <Renderer>().material = mat;

                                //TODO: Make mesh size dependent on text size
                                route.m_shieldMesh.mesh = MeshUtils.CreateRectMesh(mat.mainTexture.width, mat.mainTexture.height);
                                route.m_shieldMesh.transform.position = startNodePosition;

                                route.m_shieldMesh.transform.LookAt(endNode.m_position, Vector3.up);
                                route.m_shieldMesh.transform.Rotate(90f, 0f, 90f);

                                //TODO: Bind the elevation of the mesh to the text z offset
                                route.m_shieldMesh.transform.position  += (Vector3.up * (0.5f));
                                route.m_shieldMesh.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                                route.m_shieldObject.GetComponent <Renderer>().sortingOrder = 1000;

                                route.m_numMesh.anchor = TextAnchor.MiddleCenter;

                                route.m_numMesh.font = FontUtils.m_fontStore.ContainsKey("Highway Gothic") ? FontUtils.m_fontStore["Highway Gothic"] : districtManager.m_properties.m_areaNameFont.baseFont;
                                route.m_numMesh.GetComponent <Renderer>().material = route.m_numMesh.font.material;
                                if (ShaderUtils.m_shaderStore.ContainsKey("font"))
                                {
                                    route.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["font"];
                                }
                                else
                                {
                                    route.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["fallback"];
                                }
                                //TODO: Tie the font size to the font size option
                                route.m_numMesh.fontSize           = 50;
                                route.m_numMesh.transform.position = startNode.m_position;
                                route.m_numMesh.transform.parent   = route.m_shieldObject.transform;

                                route.m_numMesh.transform.LookAt(endNode.m_position, Vector3.up);
                                route.m_numMesh.transform.Rotate(90f, 0f, 90f);

                                route.m_numMesh.transform.position = route.m_shieldObject.GetComponent <Renderer>().bounds.center;
                                //Just a hack, to make sure the text actually shows up above the shield
                                route.m_numMesh.offsetZ = 0.001f;
                                //TODO: Definitely get a map of the texture to the required text offsets
                                route.m_numMesh.transform.localPosition += (Vector3.up * shieldInfo.upOffset);
                                route.m_numMesh.transform.localPosition += (Vector3.left * shieldInfo.leftOffset);
                                //TODO: Figure out a better ratio for route markers
                                route.m_numMesh.transform.localScale = new Vector3(shieldInfo.textScale, shieldInfo.textScale, shieldInfo.textScale);
                                route.m_numMesh.GetComponent <Renderer>().material.color = shieldInfo.textColor;
                                route.m_numMesh.text = route.m_route.ToString();
                            }
                        }
                    }
                }

                foreach (SignContainer sign in RouteManager.Instance().m_signList)
                {
                    Vector3      position     = new Vector3(sign.x, sign.y, sign.z);
                    string       signPropType = (sign.m_exitNum == null || !m_signPropDict.ContainsKey(sign.m_exitNum)) ? "hwysign" : sign.m_exitNum;
                    SignPropInfo signPropInfo = SignPropConfig.signPropInfoDict[signPropType];
                    int          numSignProps = signPropInfo.isDoubleGantry ? 2 : 1;

                    sign.m_sign.GetComponent <Renderer>().material = m_signPropDict[signPropType].m_material;
                    //TODO: Make mesh size dependent on text size
                    sign.m_sign.mesh = m_signPropDict[signPropType].m_mesh;
                    sign.m_sign.transform.position = position;

                    if (sign.m_routePrefix != null)
                    {
                        RouteShieldInfo shieldInfo = RouteShieldConfig.Instance().GetRouteShieldInfo(sign.m_routePrefix);
                        Material        mat        = SpriteUtils.m_textureStore[shieldInfo.textureName];
                        sign.m_shieldObject.GetComponent <Renderer>().material = mat;

                        //TODO: Make mesh size dependent on text size
                        sign.m_shieldMesh.mesh = MeshUtils.CreateRectMesh(mat.mainTexture.width, mat.mainTexture.height);
                        sign.m_shieldMesh.transform.position = position;

                        //TODO: Bind the elevation of the mesh to the text z offset
                        sign.m_shieldMesh.transform.position  += (Vector3.up * (0.5f));
                        sign.m_shieldMesh.transform.localScale = signPropInfo.shieldScale;
                        sign.m_shieldObject.GetComponent <Renderer>().sortingOrder = 1000;

                        sign.m_numMesh.anchor = TextAnchor.MiddleCenter;
                        sign.m_numMesh.font   = FontUtils.m_fontStore.ContainsKey("Highway Gothic") ? FontUtils.m_fontStore["Highway Gothic"] : districtManager.m_properties.m_areaNameFont.baseFont;
                        sign.m_numMesh.GetComponent <Renderer>().material = sign.m_numMesh.font.material;
                        if (ShaderUtils.m_shaderStore.ContainsKey("font"))
                        {
                            sign.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["font"];
                        }
                        else
                        {
                            sign.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["fallback"];
                        }
                        //TODO: Tie the font size to the font size option
                        sign.m_numMesh.fontSize           = 50;
                        sign.m_numMesh.transform.position = position;
                        sign.m_numMesh.transform.parent   = sign.m_shieldObject.transform;

                        sign.m_numMesh.transform.position = sign.m_shieldObject.GetComponent <Renderer>().bounds.center;
                        //Just a hack, to make sure the text actually shows up above the shield
                        sign.m_numMesh.offsetZ = 0.01f;
                        //TODO: Definitely get a map of the texture to the required text offsets ds
                        sign.m_numMesh.transform.localPosition += (Vector3.up * shieldInfo.upOffset);
                        sign.m_numMesh.transform.localPosition += (Vector3.left * shieldInfo.leftOffset);
                        //TODO: Figure out a better ratio for route markers
                        sign.m_numMesh.transform.localScale = new Vector3(shieldInfo.textScale, shieldInfo.textScale, shieldInfo.textScale);
                        sign.m_numMesh.GetComponent <Renderer>().material.color = shieldInfo.textColor;
                        sign.m_numMesh.text = sign.m_route.ToString();
                        sign.m_numMesh.TE

                        sign.m_shieldMesh.transform.parent = sign.m_sign.transform;

                        sign.m_shieldMesh.transform.localPosition = signPropInfo.shieldOffset;
                    }


                    string[] destinationStrings = sign.m_destination.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

                    for (int i = 0; i < numSignProps; i++)
                    {
                        sign.m_destinationMesh[i].anchor = TextAnchor.MiddleCenter;
                        sign.m_destinationMesh[i].font   = FontUtils.m_fontStore.ContainsKey(signPropInfo.fontType) ? FontUtils.m_fontStore[signPropInfo.fontType] : districtManager.m_properties.m_areaNameFont.baseFont;
                        sign.m_destinationMesh[i].font.material.SetColor("Text Color", Color.white);

                        if (ShaderUtils.m_shaderStore.ContainsKey("font"))
                        {
                            sign.m_destinationMesh[i].font.material.shader = ShaderUtils.m_shaderStore["font"];
                        }
                        else
                        {
                            sign.m_destinationMesh[i].font.material.shader = ShaderUtils.m_shaderStore["fallback"];
                        }

                        sign.m_destinationMesh[i].GetComponent <Renderer>().material = sign.m_destinationMesh[i].font.material;
                        //TODO: Tie the font size to the font size option
                        sign.m_destinationMesh[i].fontSize           = 50;
                        sign.m_destinationMesh[i].transform.position = position;
                        sign.m_destinationMesh[i].transform.parent   = sign.m_sign.transform;

                        sign.m_destinationMesh[i].transform.position = position;
                        //Just a hack, to make sure the text actually shows up above the shield
                        sign.m_destinationMesh[i].offsetZ = 0.001f;
                        //TODO: Definitely get a map of the texture to the required text offsets
                        //TODO: Figure out a better ratio for route markers
                        sign.m_destinationMesh[i].transform.localScale = signPropInfo.textScale;
                        sign.m_destinationMesh[i].text = signPropInfo.isDoubleGantry ? destinationStrings[i] : sign.m_destination;

                        sign.m_destinationMesh[i].transform.localPosition = sign.m_routePrefix == null ? signPropInfo.textOffsetNoSign[i] : signPropInfo.textOffsetSign[i];
                    }
                }

                foreach (DynamicSignContainer sign in RouteManager.Instance().m_dynamicSignList)
                {
                    Vector3 position = new Vector3(sign.x, sign.y, sign.z);

                    sign.m_sign.GetComponent <Renderer>().material = m_signPropDict["electronic_sign_gantry"].m_material;
                    //TODO: Make mesh size dependent on text size
                    sign.m_sign.mesh = m_signPropDict["electronic_sign_gantry"].m_mesh;
                    sign.m_sign.transform.position = position;

                    sign.m_messageTextMesh.anchor = TextAnchor.MiddleLeft;
                    sign.m_messageTextMesh.font   = FontUtils.m_fontStore.ContainsKey("Electronic Highway Sign") ? FontUtils.m_fontStore["Electronic Highway Sign"] : districtManager.m_properties.m_areaNameFont.baseFont;

                    if (ShaderUtils.m_shaderStore.ContainsKey("font"))
                    {
                        sign.m_messageTextMesh.font.material.shader = ShaderUtils.m_shaderStore["font"];
                    }
                    else
                    {
                        sign.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["fallback"];
                    }
                    sign.m_messageTextMesh.color = (new Color(1, 0.77f, 0.56f, 1f));
                    sign.m_messageTextMesh.font.material.SetColor("Text Color", new Color(1, 0.77f, 0.56f, 1f));

                    sign.m_messageTextMesh.GetComponent <Renderer>().material = sign.m_messageTextMesh.font.material;
                    //TODO: Tie the font size to the font size option
                    sign.m_messageTextMesh.fontSize           = 50;
                    sign.m_messageTextMesh.transform.position = position;
                    sign.m_messageTextMesh.transform.parent   = sign.m_sign.transform;

                    sign.m_messageTextMesh.transform.position = position;
                    //Just a hack, to make sure the text actually shows up above the shield
                    sign.m_messageTextMesh.offsetZ = 0.001f;
                    //TODO: Definitely get a map of the texture to the required text odffsets
                    //TODO: Figure out a better ratio for route markers
                    sign.m_messageTextMesh.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);

                    String msgText = (sign.m_route == null ? "Traffic" : (sign.m_routePrefix + '-' + sign.m_route)) +
                                     " moving smoothly";
                    sign.m_messageTextMesh.text = msgText;

                    sign.m_messageTextMesh.transform.localPosition = new Vector3(0.7f, 8.4f, -19.7f);
                }
            }
        }