SetCharacterSize() public method

Sets the size (height) of the text such that a capital character that extends from the baseline to the absolute top of the line will be the specified height in world units. All other characters will be sized proportionately. If called while set to pixel perfect, pixel-perfect will be automatically disabled.
public SetCharacterSize ( float size ) : void
size float The size of a full-height character, in world units.
return void
コード例 #1
0
    /// <summary>
    /// Sets the change attrbute.
    /// </summary>
    /// <param name='value'>
    /// Value. Show Value
    /// </param>
    /// <param name='pos'>
    /// Position.
    /// </param>
    /// <param name='space'>
    /// Space.
    /// </param>
    public void SetChangeAttrbute(int value = 0, float pos = 0, float space = 10)
    {
        if (value == 0)
        {
            if (mChangeValueText != null)
            {
                Destroy(mChangeValueText.gameObject);
                mChangeValueText = null;
            }
        }
        else
        {
            if (ChangeValueText != null && mChangeValueText == null)
            {
                mChangeValueText = Instantiate(ChangeValueText) as SpriteText;
                if (mChangeValueText == null)
                {
                    return;
                }

                Transform    tPackedTran   = mChangeValueText.transform.Find("Icon");
                PackedSprite tPackedSprite = tPackedTran.GetComponent <PackedSprite>();

                string color = GUIFontColor.White255255255;
                if (value > 0)
                {
                    color = GUIFontColor.LimeGreen089210000;
                    tPackedSprite.PlayAnim(0);
                }
                else if (value < 0)
                {
                    color = GUIFontColor.DarkRed210000005;
                    tPackedSprite.PlayAnim(1);
                    value = -value;
                }

                mChangeValueText.SetCharacterSize(mAttributeText.characterSize);
                mChangeValueText.Text = color + value;

                mChangeValueText.transform.parent = transform;

                mChangeValueText.transform.localScale = Vector3.one;
                if (pos == 0)
                {
                    mChangeValueText.transform.localPosition = new Vector3(mAttributeText.transform.localPosition.x + mAttributeText.PixelSize.x + space, mAttributeText.transform.localPosition.y, mAttributeText.transform.localPosition.z);
                    tPackedSprite.transform.localPosition    = new Vector3(tPackedSprite.transform.localPosition.x + mChangeValueText.PixelSize.x + space, tPackedSprite.transform.localPosition.y, tPackedSprite.transform.localPosition.z);
                }
                else
                {
                    mChangeValueText.transform.localPosition = new Vector3(mAttributeText.transform.localPosition.x + pos, mAttributeText.transform.localPosition.y, mAttributeText.transform.localPosition.z);
                    tPackedSprite.transform.localPosition    = new Vector3(tPackedSprite.transform.localPosition.x + space, tPackedSprite.transform.localPosition.y, tPackedSprite.transform.localPosition.z);
                }
            }
        }
    }
コード例 #2
0
    //crit font
    private void ReleaseEffect(Transform parent, Vector3 position, EffectType type, int val, string skillName, Vector3 offset)
    {
        // Vector3 warshipViewPosition = _mainCamera.WorldToViewportPoint(position);
        // Vector3 uiOffset = new Vector3((warshipViewPosition.x - 0.5f) * Screen.width,(warshipViewPosition.y - 0.5f) * Screen.height,100);

        _gobjCrit = new GameObject("BattleCritFont");
        _gobjCrit.transform.position   = position;
        _gobjCrit.transform.parent     = Globals.Instance.MGUIManager.MGUICamera.transform;
        _gobjCrit.transform.localScale = new Vector3(Globals.Instance.MGUIManager.widthRatio,
                                                     Globals.Instance.MGUIManager.heightRatio, 1);
        // _gobjCrit.transform.localPosition = uiOffset + offset;

        PackedSprite effectFont = null;
        SpriteText   textSkill  = null;
        PackedSprite number     = null;

        switch (type)
        {
        case EffectType.CRIT:
            // effectFont = GameObject.Instantiate(effectFontPreb) as PackedSprite;
            // effectFont.transform.parent = _gobjCrit.transform;
            // effectFont.transform.localPosition = new Vector3 (0, 0, 0);
            // effectFont.PlayAnim ("RedCrit");
            // AnimateScale.Do (_gobjCrit, EZAnimation.ANIM_MODE.To, Vector3.one * 2, EZAnimation.linear, AnimScaleDurationTime, 0f, null, null);
            // FadeSpriteAlpha.Do (effectFont, EZAnimation.ANIM_MODE.To, Color.clear, EZAnimation.linear, AnimAlphaDurationTime, AnimAlphaDelayTime, null, DestroyEffectObj);
            break;

        case EffectType.DODGE:
            effectFont = GameObject.Instantiate(effectFontPreb) as PackedSprite;
            effectFont.transform.parent        = _gobjCrit.transform;
            effectFont.transform.localPosition = new Vector3(0, 0, 0);
            effectFont.transform.localScale    = Vector3.one;
            effectFont.PlayAnim("Shan");

            AnimateScale.Do(_gobjCrit, EZAnimation.ANIM_MODE.To, Vector3.one * 2, EZAnimation.linear, AnimScaleDurationTime, 0f, null, null);
            FadeSpriteAlpha.Do(effectFont, EZAnimation.ANIM_MODE.To, Color.clear, EZAnimation.linear, AnimAlphaDurationTime, AnimAlphaDelayTime, null, DestroyEffectObj);

            break;

        case EffectType.SKILL:
            //delay = 0;
            //duration = 6;
            textSkill = GameObject.Instantiate(textSkillPreb) as SpriteText;
            textSkill.transform.parent        = _gobjCrit.transform;
            textSkill.transform.localPosition = new Vector3(0, 0, 0);
            textSkill.transform.localScale    = Vector3.one;
            textSkill.Text = skillName;
            //textSkill.SetColor(new Color32(255,129,54,255));
            // textSkill.SetColor(new Color32(255,255,0,255));
            textSkill.SeaColor = SeaClientColorType.DarkRed210000005;
            //textSkill.SetColor(Color.magenta);
            textSkill.SetCharacterSize(40);
            FadeText.Do(textSkill, EZAnimation.ANIM_MODE.To, Color.clear, EZAnimation.linear, AnimAlphaDurationTime, AnimAlphaDelayTime, null, DestroyEffectObj);
            break;

        case EffectType.CRIT_SKILL:
            //delay = 0;
            //duration = 6;
            // effectFont = GameObject.Instantiate(effectFontPreb) as PackedSprite;
            // effectFont.transform.parent = _gobjCrit.transform;
            // effectFont.transform.localPosition = new Vector3 (0, 20, 0);
            // effectFont.PlayAnim ("RedCrit");
            // //DoAnimationFade (effectFont, DestroyEffectObj);
            // AnimateScale.Do (_gobjCrit, EZAnimation.ANIM_MODE.To, Vector3.one * 1.5f, EZAnimation.linear, AnimScaleDurationTime, 0f, null, null);
            // FadeSpriteAlpha.Do (effectFont, EZAnimation.ANIM_MODE.To, Color.clear, EZAnimation.linear, AnimAlphaDurationTime, AnimAlphaDelayTime, null, DestroyEffectObj);

            textSkill = GameObject.Instantiate(textSkillPreb) as SpriteText;
            textSkill.transform.parent        = _gobjCrit.transform;
            textSkill.transform.localPosition = new Vector3(0, 0, 0);
            textSkill.transform.localScale    = Vector3.one;
            textSkill.Text = skillName;

            // textSkill.SetColor(new Color32(255,255,0,255));
            textSkill.SeaColor = SeaClientColorType.DarkRed210000005;
            //textSkill.SetColor(Color.magenta);
            textSkill.SetCharacterSize(40);
            FadeText.Do(textSkill, EZAnimation.ANIM_MODE.To, Color.clear, EZAnimation.linear, AnimAlphaDurationTime, AnimAlphaDelayTime, null, DestroyEffectObj);

            break;

        case EffectType.NUMBER_GRAY:
            this.PlayAttackNumber(type, "NumMinus", "NumRed", val);
            break;

        case EffectType.NUMBER_RED:
            this.PlayAttackNumber(type, "NumMinus", "NumRed", val);
            break;

        case EffectType.NUMBER_GREEN:
            this.PlayAttackNumber(type, "GreenPlus", "NumGreen", val);
            break;
        }

        if (type == EffectType.CRIT || type == EffectType.CRIT_SKILL || type == EffectType.NUMBER_RED)
        {
            iTween.ShakePosition(_gobjCrit, new Vector3(5, 5, 0), AnimAlphaDurationTime);
            // _gobjCrit.transform.localScale = new Vector3(2.5f,2.5f,1);
        }
    }
コード例 #3
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();
    }