Пример #1
0
 public static RouteManager Instance()
 {
     if (instance == null)
     {
         instance = new RouteManager();
     }
     return(instance);
 }
Пример #2
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);
                }
            }
        }
Пример #3
0
        protected override void BeginOverlayImpl(RenderManager.CameraInfo cameraInfo)
        {
            NetManager      netManager      = NetManager.instance;
            DistrictManager districtManager = DistrictManager.instance;

            cameraInfo.m_height = 100;
            if (m_lastCount != RouteManager.Instance().m_routeDict.Count)
            {
                m_lastCount = RouteManager.Instance().m_routeDict.Count;

                try
                {
                    RenderText();
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
            }

            if (!textHidden && cameraInfo.m_height > m_renderHeight)
            {
                foreach (RouteContainer route in RouteManager.Instance().m_routeDict.Values)
                {
                    route.m_shieldMesh.GetComponent <Renderer>().enabled = false;
                    route.m_numMesh.GetComponent <Renderer>().enabled    = false;
                }

                foreach (SignContainer sign in RouteManager.Instance().m_signList)
                {
                    /*sign.m_destinationMesh.GetComponent<Renderer>().enabled = false;
                     * sign.m_shieldMesh.GetComponent<Renderer>().enabled = false;
                     * sign.m_numMesh.GetComponent<Renderer>().enabled = false;*/
                    sign.m_sign.GetComponent <Renderer>().enabled = false;
                }
                textHidden = true;
            }
            else if (textHidden && cameraInfo.m_height <= m_renderHeight)  //This is a mess, and I'll sort it soon :)
            {
                if (m_routeEnabled)
                {
                    foreach (RouteContainer route in RouteManager.Instance().m_routeDict.Values)
                    {
                        route.m_shieldMesh.GetComponent <Renderer>().enabled = true;
                        route.m_numMesh.GetComponent <Renderer>().enabled    = true;
                    }

                    foreach (SignContainer sign in RouteManager.Instance().m_signList)
                    {
                        /*sign.m_destinationMesh.GetComponent<Renderer>().enabled = true;
                         * sign.m_shieldMesh.GetComponent<Renderer>().enabled = true;
                         * sign.m_numMesh.GetComponent<Renderer>().enabled = true;*/
                        sign.m_sign.GetComponent <Renderer>().enabled = true;
                    }
                }
                textHidden = false;
            }

            if (m_updateDynamicSignFlag)
            {
                m_updateDynamicSignFlag = false;
                float  avg;
                float  lowTrafficMsgChance;
                String msgText;
                foreach (DynamicSignContainer sign in RouteManager.Instance().m_dynamicSignList)
                {
                    avg  = (float)sign.m_trafficDensity;
                    avg -= sign.m_trafficDensity / 3;
                    avg += netManager.m_segments.m_buffer[sign.m_segment].m_trafficDensity / 3;
                    sign.m_trafficDensity = avg;
                    msgText = (sign.m_route == null ? "Traffic" : (sign.m_routePrefix + '-' + sign.m_route)) +
                              String.Format(" moving {0}", sign.m_trafficDensity > 65 ? "slowly" : "well");

                    if (sign.m_trafficDensity < 35)
                    {
                        lowTrafficMsgChance = 0.8f;
                    }
                    else
                    {
                        lowTrafficMsgChance = 0.1f;
                    }

                    sign.m_messageTextMesh.text = (messageRandom.NextDouble() > lowTrafficMsgChance) ? msgText :
                                                  DynamicSignConfig.Instance().msgStrings[messageRandom.Next(DynamicSignConfig.Instance().msgStrings.Count)];
                }
            }
        }