Exemplo n.º 1
0
        bool GenerateMesh()
        {
            UIFont uifont = LoadingScreen.instance.uifont;

            if (uifont == null)
            {
                return(false);
            }

            long           t = Profiling.Ticks;
            UIFontRenderer uiFontRenderer = uifont.ObtainRenderer();
            UIRenderData   uiRenderData   = UIRenderData.Obtain();

            try
            {
                mesh.Clear();
                uiFontRenderer.defaultColor  = Color.white;
                uiFontRenderer.textScale     = 1f;
                uiFontRenderer.pixelRatio    = 1f;
                uiFontRenderer.processMarkup = true;
                uiFontRenderer.multiLine     = true;
                uiFontRenderer.maxSize       = new Vector2(LoadingScreen.instance.meshWidth, LoadingScreen.instance.meshHeight);
                uiFontRenderer.shadow        = false;
                uiFontRenderer.Render(text, uiRenderData);

                mesh.vertices  = uiRenderData.vertices.ToArray();
                mesh.colors32  = uiRenderData.colors.ToArray();
                mesh.uv        = uiRenderData.uvs.ToArray();
                mesh.triangles = uiRenderData.triangles.ToArray();
            }
            catch (Exception e)
            {
                Util.DebugPrint("Cannot generate font mesh");
                UnityEngine.Debug.LogException(e);
                return(false);
            }
            finally
            {
                uiFontRenderer.Dispose();
                uiRenderData.Dispose();
            }

            return(true);
        }
Exemplo n.º 2
0
            private static void Postfix(
                UIGraph __instance,
                List <CurveSettings> ___m_Curves,
                Rect ___m_GraphRect,
                PoolList <UIRenderData> ___m_RenderData,
                PoolList <Vector3> vertices,
                PoolList <int> indices,
                PoolList <Vector2> uvs,
                PoolList <Color32> colors)
            {
                // Note: this method is extracted from the original game and is slightly modified
                if (___m_Curves.Count == 0)
                {
                    return;
                }

                float   units       = pixelsToUnits(__instance);
                var     maxSize     = new Vector2(__instance.size.x, __instance.size.y);
                Vector3 center      = __instance.pivot.TransformToCenter(__instance.size, __instance.arbitraryPivotOffset) * units;
                Vector3 size        = units * __instance.size;
                float   aspectRatio = __instance.size.x / __instance.size.y;

                using (UIFontRenderer uiFontRenderer = __instance.font.ObtainRenderer())
                {
                    float xmin        = units * __instance.width * (-0.5f + ___m_GraphRect.xMin);
                    float xmax        = units * __instance.width * (-0.5f + ___m_GraphRect.xMax);
                    float minInterval = GridIntervalX * units;

                    float    startTicks     = __instance.StartTime.Ticks;
                    DateTime visibleEndTime = GetVisibleEndTime(___m_Curves, __instance.StartTime, __instance.EndTime);
                    float    endTicks       = visibleEndTime.Ticks;

                    float minRangeTicks = __instance.StartTime.AddDays(MinRangeInDays).Ticks - __instance.StartTime.Ticks;
                    float rangeTicks    = __instance.EndTime.Ticks - __instance.StartTime.Ticks;
                    float timeScale     = minRangeTicks / rangeTicks;

                    float    scaledX = Mathf.Lerp(xmin, xmax, timeScale) - xmin;
                    TimeSpan step    = scaledX <= 0.0001f ? TimeSpan.FromDays(10000) : TimeSpan.FromDays(minInterval / scaledX);

                    UIRenderData textRenderData = ___m_RenderData.Count > 1 ? ___m_RenderData[1] : null;

                    for (DateTime current = __instance.StartTime.AddDays(1); current <= visibleEndTime; current += step)
                    {
                        float  currentTicks = current.Ticks;
                        float  x            = Mathf.Lerp(xmin, xmax, (currentTicks - startTicks) / (endTicks - startTicks));
                        string text         = current.ToString("M", currentCulture);
                        uiFontRenderer.textScale    = 1f;
                        uiFontRenderer.vectorOffset = new Vector3(x, __instance.height * units * -0.95f, 0f);
                        uiFontRenderer.pixelRatio   = units;
                        uiFontRenderer.maxSize      = maxSize;
                        uiFontRenderer.textAlign    = UIHorizontalAlignment.Center;
                        uiFontRenderer.defaultColor = __instance.TextColor;
                        uiFontRenderer.Render(text, textRenderData);
                        float val     = Mathf.Lerp(-0.5f + ___m_GraphRect.xMin, -0.5f + ___m_GraphRect.xMax, (currentTicks - startTicks) / (endTicks - startTicks));
                        var   corner1 = new Vector2(val - (units * __instance.HelpAxesWidth * aspectRatio), -0.5f + ___m_GraphRect.yMin);
                        var   corner2 = new Vector2(val + (units * __instance.HelpAxesWidth * aspectRatio), corner1.y + ___m_GraphRect.height);
                        addSolidQuad(
                            __instance,
                            Vector3.Scale(corner1, size) + center,
                            Vector3.Scale(corner2, size) + center,
                            __instance.HelpAxesColor,
                            vertices,
                            indices,
                            uvs,
                            colors);
                    }
                }
            }
Exemplo n.º 3
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();
            }
        }