Exemplo n.º 1
0
        public void SetFont()
        {
            try
            {
                uifont       = UIView.GetAView().defaultFont;
                textMaterial = new Material(uifont.material);
                UIFontManager.Invalidate(uifont);

                List <Text> list = new List <Text>(5);
                list.Add(new Text(new Vector3(-1.2f, 0.7f, 10f), new DualProfilerSource("Scenes and Assets:", 36)));
                list.Add(new Text(new Vector3(-0.33f, -0.52f, 10f), new SimpleProfilerSource("Main:", LoadingManager.instance.m_loadingProfilerMain)));
                list.Add(new Text(new Vector3(-0.33f, -0.62f, 10f), new SimpleProfilerSource("Simulation:", LoadingManager.instance.m_loadingProfilerSimulation)));
                list.Add(new Text(new Vector3(-0.12f, 0.7f, 10f), new LineSource("Assets Loader:", 2, AssetLoader.IsActive)));
                list.Add(new Text(new Vector3(-0.1f, 0.38f, 10f), new TimeSource(), 1.5f));

                if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
                {
                    list.Add(new Text(new Vector3(-0.1f, 0.27f, 10f), new MemorySource(), 1.5f));
                }

                texts      = list.ToArray();
                fontLoaded = uifont != null;
            }
            catch (Exception e)
            {
                Util.DebugPrint("Font setup failed");
                UnityEngine.Debug.LogException(e);
            }
        }
Exemplo n.º 2
0
        void RequestCharacterInfo()
        {
            UIDynamicFont uIDynamicFont = uifont as UIDynamicFont;

            if (uIDynamicFont == null || !UIFontManager.IsDirty(uIDynamicFont))
            {
                return;
            }

            uIDynamicFont.AddCharacterRequest("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-:", 1, FontStyle.Normal);
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 4
0
        private void UpdateNames()
        {
            UIFontManager.Invalidate(this.m_properties.m_areaNameFont);
            namesModifiedField.SetValue(this, false);
            UIRenderData destination  = UIRenderData.Obtain();
            UIRenderData uiRenderData = UIRenderData.Obtain();

            try
            {
                destination.Clear();
                uiRenderData.Clear();
                PoolList <Vector3> vertices1  = uiRenderData.vertices;
                PoolList <Vector3> normals1   = uiRenderData.normals;
                PoolList <Color32> colors1    = uiRenderData.colors;
                PoolList <Vector2> uvs1       = uiRenderData.uvs;
                PoolList <int>     triangles1 = uiRenderData.triangles;
                PoolList <Vector3> vertices2  = destination.vertices;
                PoolList <Vector3> normals2   = destination.normals;
                PoolList <Color32> colors2    = destination.colors;
                PoolList <Vector2> uvs2       = destination.uvs;
                PoolList <int>     triangles2 = destination.triangles;
                for (int district = 1; district < 128; ++district)
                {
                    if (this.m_districts.m_buffer[district].m_flags != District.Flags.None)
                    {
                        string text = this.GetDistrictName(district) + "\n";
                        PositionData <DistrictPolicies.Policies>[] orderedEnumData = Utils.GetOrderedEnumData <DistrictPolicies.Policies>();
                        for (int index = 0; index < orderedEnumData.Length; ++index)
                        {
                            if (this.IsDistrictPolicySet(orderedEnumData[index].enumValue, (byte)district))
                            {
                                string str = "IconPolicy" + orderedEnumData[index].enumName;
                                text = text + "<sprite " + str + "> ";
                            }
                        }
                        if (text != null)
                        {
                            int count1 = normals2.Count;
                            int count2 = normals1.Count;
                            using (UIFontRenderer renderer = this.m_properties.m_areaNameFont.ObtainRenderer())
                            {
                                UIDynamicFont.DynamicFontRenderer dynamicFontRenderer = renderer as UIDynamicFont.DynamicFontRenderer;
                                if (dynamicFontRenderer != null)
                                {
                                    dynamicFontRenderer.spriteAtlas  = this.m_properties.m_areaIconAtlas;
                                    dynamicFontRenderer.spriteBuffer = uiRenderData;
                                }
                                float x1 = 450f;
                                renderer.defaultColor  = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)64);
                                renderer.textScale     = 2f;
                                renderer.pixelRatio    = 1f;
                                renderer.processMarkup = true;
                                renderer.multiLine     = true;
                                renderer.wordWrap      = true;
                                renderer.textAlign     = UIHorizontalAlignment.Center;
                                renderer.maxSize       = new Vector2(x1, 900f);
                                renderer.shadow        = false;
                                renderer.shadowColor   = (Color32)Color.black;
                                renderer.shadowOffset  = Vector2.one;
                                Vector2 vector2 = renderer.MeasureString(text);
                                float   x2      = vector2.x;
                                if ((double)vector2.x > (double)x1)
                                {
                                    x2 = x1 + (float)(((double)vector2.x - (double)x1) * 0.5);
                                    x1 = vector2.x;
                                    renderer.maxSize = new Vector2(x1, 900f);
                                    vector2          = renderer.MeasureString(text);
                                }
                                this.m_districts.m_buffer[district].m_nameSize = vector2;
                                vertices2.Add(new Vector3(-x2, -vector2.y, 1f));
                                vertices2.Add(new Vector3(-x2, vector2.y, 1f));
                                vertices2.Add(new Vector3(x2, vector2.y, 1f));
                                vertices2.Add(new Vector3(x2, -vector2.y, 1f));
                                colors2.Add(new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
                                colors2.Add(new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
                                colors2.Add(new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
                                colors2.Add(new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
                                uvs2.Add(new Vector2(-1f, -1f));
                                uvs2.Add(new Vector2(-1f, 1f));
                                uvs2.Add(new Vector2(1f, 1f));
                                uvs2.Add(new Vector2(1f, -1f));
                                triangles2.Add(vertices2.Count - 4);
                                triangles2.Add(vertices2.Count - 3);
                                triangles2.Add(vertices2.Count - 1);
                                triangles2.Add(vertices2.Count - 1);
                                triangles2.Add(vertices2.Count - 3);
                                triangles2.Add(vertices2.Count - 2);
                                renderer.vectorOffset = new Vector3(x1 * -0.5f, vector2.y * 0.5f, 0.0f);
                                renderer.Render(text, destination);
                            }
                            int     count3  = vertices2.Count;
                            int     count4  = normals2.Count;
                            Vector3 vector3 = this.m_districts.m_buffer[district].m_nameLocation;
                            for (int index = count1; index < count4; ++index)
                            {
                                normals2[index] = vector3;
                            }
                            for (int index = count4; index < count3; ++index)
                            {
                                normals2.Add(vector3);
                            }
                            int count5 = vertices1.Count;
                            int count6 = normals1.Count;
                            for (int index = count2; index < count6; ++index)
                            {
                                normals1[index] = vector3;
                            }
                            for (int index = count6; index < count5; ++index)
                            {
                                normals1.Add(vector3);
                            }
                        }
                    }
                }
                if ((Mesh)nameMeshField.GetValue(this) == null)
                {
                    nameMeshField.SetValue(this, new Mesh());
                }
                var nameMesh = (Mesh)nameMeshField.GetValue(this);
                nameMesh.Clear();
                nameMesh.vertices  = vertices2.ToArray();
                nameMesh.normals   = normals2.ToArray();
                nameMesh.colors32  = colors2.ToArray();
                nameMesh.uv        = uvs2.ToArray();
                nameMesh.triangles = triangles2.ToArray();
                //begin mod
                nameMesh.bounds = new Bounds(Vector3.zero, new Vector3(GRID * 19.2f, 1024f, GRID * 19.2f));
                //end mod
                if ((Mesh)iconMeshField.GetValue(this) == null)
                {
                    iconMeshField.SetValue(this, new Mesh());
                }
                var iconMesh = (Mesh)iconMeshField.GetValue(this);
                iconMesh.Clear();
                iconMesh.vertices  = vertices1.ToArray();
                iconMesh.normals   = normals1.ToArray();
                iconMesh.colors32  = colors1.ToArray();
                iconMesh.uv        = uvs1.ToArray();
                iconMesh.triangles = triangles1.ToArray();
                //begin mod
                iconMesh.bounds = new Bounds(Vector3.zero, new Vector3(GRID * 19.2f, 1024f, GRID * 19.2f));
                //end mod
            }
            finally
            {
                destination.Release();
                uiRenderData.Release();
            }
        }