Exemple #1
0
        public bool SetSpriteTextRichFont(SpriteTextRich ST)
        {
            bool result = false;

            if (FontList.Count == 0)
            {
                LoadxFont();
            }
            // if (ST.font.name[0] == 'c' && ST.font.name[1] == 'n') return result;

            //Debug.Log("[xFont2-1]" + ST.font.name + " :: " + ST.text);
            for (int i = 0; i < ST.font.fonts.Length; i++)
            {
                if (ST.font.fonts[i].fontText.name[0] == 'c' && ST.font.fonts[i].fontText.name[1] == 'n')
                {
                    continue;
                }

                Font2Font f2f = GetFont2Font(ST.font.fonts[i].fontText.name);
                Debug.Log("[xFont2]" + ST.font.name + "-->>" + f2f.Name + " :: " + ST.text);
                ST.font.fonts[i].fontText   = f2f.fontDef;
                ST.font.fonts[i].material   = f2f.fontMat;
                ST.font.fonts[i].SpriteFont = FontStore.GetFont(f2f.fontDef);
                //Debug.Log("[xFont2-2]" + ST.font.name + "-->>" + f2f.Name + " :: " + ST.text);
                result = true;
            }
            ST.font.name = "cn" + ST.font.name;
            return(result);
        }
Exemple #2
0
        public void GetFont_NoFont_ThrowsFontNotFound()
        {
            Mock <Font> mockedFont = new Mock <Font>(null);

            FontStore.DefaultFont = mockedFont.Object;
            Assert.That(() => FontStore.GetFont("test"), Throws.TypeOf <FontNotFoundException>());
        }
Exemple #3
0
        /// <summary>
        /// Gets the font from the FontStore, with the name passed to FontFamily constructor and assigns it to the TextWidget.
        /// Then the new space required by the widget is calculated and updated.
        /// </summary>
        /// <param name="widget"></param>
        /// <exception cref="IncompatibleWidgetException"></exception>
        public void ApplyOn(IWidget widget)
        {
            ApplicationDone = false;

            var tail = widget.Skip(1).OfType <Widgets.BuiltIn.Text>().ToList();

            if (widget is Widgets.BuiltIn.Text text)
            {
                text.Font = FontStore.GetFont(_name);
            }
            if (tail.Count > 0)
            {
                foreach (var t in tail)
                {
                    var alreadyHasFontFamilyProp = t.Props.SafeGetByProp <FontFamily>().TryGetValue(out var l);
                    if (!alreadyHasFontFamilyProp || l.Count == 0)
                    {
                        t.Font = FontStore.GetFont(_name);
                    }
                }
            }
            else
            {
                Log.Warning(
                    "FontFamily was applied to a widget that is not a Text nor has any Text in its sub-tree");
            }

            ApplicationDone = true;
            OnApplied();
        }
Exemple #4
0
        public void SetSpriteTextRichFont(SpriteTextRich ST)
        {
            if (FontList.Count == 0)
            {
                LoadxFont();
            }

            for (int i = 0; i < ST.font.fonts.Length; i++)
            {
                if (ST.font.fonts[i].fontText.name[0] == 'c' && ST.font.fonts[i].fontText.name[1] == 'n')
                {
                    return;
                }

                Font2Font f2f = GetFont2Font(ST.font.fonts[i].fontText.name);
                Debug.Log("xFont:" + ST.font.name + "-->>" + f2f.Name);
                ST.font.fonts[i].fontText   = f2f.fontDef;
                ST.font.fonts[i].material   = f2f.fontMat;
                ST.font.fonts[i].SpriteFont = FontStore.GetFont(f2f.fontDef);
            }
        }
Exemple #5
0
    // Let's do this thing!:
    void OnWizardCreate()
    {
        float worldUnitsPerScreenPixel;
        int   skipped = 0;       // How many texts had to be skipped because they were prefabs?

        if (disablePixelPerfect)
        {
            disablePixelPerfect = EditorUtility.DisplayDialog("Are you sure?", "Are you sure you wish to disable pixel-perfect on all selected texts?", "Yes", "No");
        }

        // Get our desired texts:
        FindSpriteTexts();


        if (renderCamera.isOrthoGraphic)
        {
            // Use orthographic logic:
            worldUnitsPerScreenPixel = (renderCamera.orthographicSize * 2f) / targetScreenHeight;

            // Now set their sizes:
            for (int i = 0; i < texts.Count; ++i)
            {
                SpriteText text   = (SpriteText)texts[i];
                float      pxSize = (float)FontStore.GetFont(text.font).PixelSize;

                if (disablePixelPerfect)
                {
                    text.pixelPerfect = false;
                }

                text.SetCharacterSize(pxSize * worldUnitsPerScreenPixel);

                EditorUtility.SetDirty(((SpriteText)texts[i]).gameObject);
            }
        }
        else
        {
            // Use perspective logic:
            float dist;
            Plane nearPlane;

            // Now set their sizes:
            for (int i = 0; i < texts.Count; ++i)
            {
#if (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9)
#if (UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9)
                PrefabType ptype = PrefabUtility.GetPrefabType(((SpriteText)texts[i]).gameObject);
#else
                PrefabType ptype = EditorUtility.GetPrefabType(((SpriteText)texts[i]).gameObject);
#endif
                // We can't do prefabs with perspective cameras:
                if (ptype == PrefabType.Prefab || ptype == PrefabType.ModelPrefab)
                {
                    ++skipped;
                    Debug.LogWarning("SpriteText \"" + ((SpriteText)texts[i]).name + "\" skipped because it is a prefab and the selected camera is perspective. Size cannot be calculated for perspective cameras without the object actually being positioned in front of the camera.\n Either use an orthographic camera, or use an instance of the prefab in the scene instead.");
                    continue;
                }
#endif
                SpriteText text = (SpriteText)texts[i];
                nearPlane = new Plane(renderCamera.transform.forward, renderCamera.transform.position);
                float pxSize = (float)FontStore.GetFont(text.font).PixelSize;

                // Determine the world distance between two vertical
                // screen pixels for this camera:
                dist = nearPlane.GetDistanceToPoint(text.transform.position);
                worldUnitsPerScreenPixel = Vector3.Distance(renderCamera.ScreenToWorldPoint(new Vector3(0, 1, dist)), renderCamera.ScreenToWorldPoint(new Vector3(0, 0, dist)));

                if (disablePixelPerfect)
                {
                    text.pixelPerfect = false;
                }

                text.SetCharacterSize(pxSize * worldUnitsPerScreenPixel);

                EditorUtility.SetDirty(((SpriteText)texts[i]).gameObject);
            }
        }



        // See if we need to advise the user to reload the scene:
        if (applyToAllPrefabs)
        {
            EditorUtility.DisplayDialog("NOTE", "You may need to reload the current scene for prefab instances to reflect your changes.", "OK");
        }

        Debug.Log((texts.Count - skipped) + " texts sized.");

        // Save our settings for next time:
        SaveSettings();
    }