Esempio n. 1
0
    // ------------------------------------------------------------------
    /// \param _spriteFont the sprite font
    /// build the sprite font
    // ------------------------------------------------------------------

    public static void Build(this exSpriteFont _spriteFont)
    {
#if UNITY_3_4
        bool isPrefab = (EditorUtility.GetPrefabType(_spriteFont) == PrefabType.Prefab);
#else
        bool isPrefab = (PrefabUtility.GetPrefabType(_spriteFont) == PrefabType.Prefab);
#endif

        // when build, alway set dirty
        EditorUtility.SetDirty(_spriteFont);

        if (_spriteFont.fontInfo == null)
        {
            _spriteFont.clippingPlane = null;
            GameObject.DestroyImmediate(_spriteFont.meshFilter.sharedMesh, true);
            _spriteFont.meshFilter.sharedMesh = null;
            _spriteFont.GetComponent <Renderer>().sharedMaterial = null;
            return;
        }

        // prefab do not need rebuild mesh
        if (isPrefab == false)
        {
            exClipping clipping = _spriteFont.clippingPlane;
            if (clipping != null)
            {
                clipping.RemovePlane(_spriteFont);
            }

            //
            Mesh newMesh = new Mesh();
            newMesh.hideFlags = HideFlags.DontSave;
            newMesh.Clear();

            // update material
            _spriteFont.GetComponent <Renderer>().sharedMaterial = _spriteFont.fontInfo.pageInfos[0].material;

            // update mesh
            _spriteFont.ForceUpdateMesh(newMesh);

            //
            GameObject.DestroyImmediate(_spriteFont.meshFilter.sharedMesh, true);   // delete old mesh (to avoid leaking)
            _spriteFont.meshFilter.sharedMesh = newMesh;

            //
            if (clipping != null)
            {
                clipping.AddPlaneInEditor(_spriteFont);
            }
        }

        // update collider
        if (_spriteFont.collisionHelper)
        {
            _spriteFont.collisionHelper.UpdateCollider();
        }
    }
Esempio n. 2
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public static void ScreenPrint(Vector2 _pos, string _text, GUIStyle _style = null)
    {
        if (instance.showScreenDebugText)
        {
#if EX2D
            exSpriteFont debugText = instance.debugTextPool.Request <exSpriteFont>();

            Vector2          screenPos      = debugText.renderCamera.WorldToScreenPoint(_pos);
            exScreenPosition screenPosition = debugText.GetComponent <exScreenPosition>();
            screenPosition.x = screenPos.x;
            screenPosition.y = Screen.height - screenPos.y;

            debugText.text    = _text;
            debugText.enabled = true;
#else
            TextInfo info = new TextInfo(_pos, _text, _style);
            instance.debugTextPool.Add(info);
#endif
        }
    }