ConvertToTexCoords() static public method

Convert from top-left based pixel coordinates to bottom-left based UV coordinates.
static public ConvertToTexCoords ( Rect rect, int width, int height ) : Rect
rect Rect
width int
height int
return Rect
Beispiel #1
0
    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture mainTexture = this.mainTexture;

        if (mainTexture == null)
        {
            return;
        }
        if (mSprite == null)
        {
            mSprite = atlas.GetSprite(spriteName);
        }
        if (mSprite != null)
        {
            Rect rect  = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
            Rect rect2 = new Rect(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop, mSprite.width - mSprite.borderLeft - mSprite.borderRight, mSprite.height - mSprite.borderBottom - mSprite.borderTop);
            rect  = NGUIMath.ConvertToTexCoords(rect, mainTexture.width, mainTexture.height);
            rect2 = NGUIMath.ConvertToTexCoords(rect2, mainTexture.width, mainTexture.height);
            int size = verts.size;
            Fill(verts, uvs, cols, rect, rect2);
            if (onPostFill != null)
            {
                onPostFill(this, size, verts, uvs, cols);
            }
        }
    }
Beispiel #2
0
    private void InitSpriteUVList()
    {
        if (mSpriteNum == 0)
        {
            string str = string.Format("mSpriteNum is 0, transform.name = {0}", transform.name);
            Debug.LogError(str);
            return;
        }

        mSpriteUVList = new List <Vector4>(mSpriteNum);

        int  texW    = mAtlasTex.width;
        int  texH    = mAtlasTex.height;
        int  spriteW = texW / mColNum;
        int  spriteH = texH / mRowNum;
        Rect rect    = new Rect();

        for (int row = 0; row < mRowNum; ++row)
        {
            rect.yMin = spriteH * row;
            rect.yMax = spriteH * (row + 1);
            for (int col = 0; col < mColNum; ++col)
            {
                rect.xMin = spriteW * col;
                rect.xMax = spriteW * (col + 1);
                Rect uv = NGUIMath.ConvertToTexCoords(rect, texW, texH);
                mSpriteUVList.Add(new Vector4(uv.xMin, uv.xMax, uv.yMin, uv.yMax));
            }
        }
    }
Beispiel #3
0
    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture mainTexture = this.mainTexture;

        if (mainTexture == null)
        {
            return;
        }
        if (this.mSprite == null)
        {
            this.mSprite = this.atlas.GetSprite(this.spriteName);
        }
        if (this.mSprite == null)
        {
            return;
        }
        Rect rect  = new Rect((float)this.mSprite.x, (float)this.mSprite.y, (float)this.mSprite.width, (float)this.mSprite.height);
        Rect rect2 = new Rect((float)(this.mSprite.x + this.mSprite.borderLeft), (float)(this.mSprite.y + this.mSprite.borderTop), (float)(this.mSprite.width - this.mSprite.borderLeft - this.mSprite.borderRight), (float)(this.mSprite.height - this.mSprite.borderBottom - this.mSprite.borderTop));

        rect  = NGUIMath.ConvertToTexCoords(rect, mainTexture.width, mainTexture.height);
        rect2 = NGUIMath.ConvertToTexCoords(rect2, mainTexture.width, mainTexture.height);
        int size = verts.size;

        base.Fill(verts, uvs, cols, rect, rect2);
        if (this.onPostFill != null)
        {
            this.onPostFill(this, size, verts, uvs, cols);
        }
    }
Beispiel #4
0
    public virtual void UpdateUVs(bool force)
    {
        if ((type == Type.Sliced || type == Type.Tiled) && cachedTransform.localScale != mScale)
        {
            mScale   = cachedTransform.localScale;
            mChanged = true;
        }

        if (isValid && force)
        {
            var mainTexture = this.mainTexture;
            if (mainTexture != null)
            {
                mInner   = mSprite.inner;
                mOuter   = mSprite.outer;
                mInnerUV = mInner;
                mOuterUV = mOuter;
                if (atlas.coordinates == UIAtlas.Coordinates.Pixels)
                {
                    mOuterUV = NGUIMath.ConvertToTexCoords(mOuterUV, mainTexture.width, mainTexture.height);
                    mInnerUV = NGUIMath.ConvertToTexCoords(mInnerUV, mainTexture.width, mainTexture.height);
                }
            }
        }
    }
    /// <summary>
    /// Update the texture UVs used by the widget.
    /// </summary>

    override public void UpdateUVs(bool force)
    {
        if (cachedTransform.localScale != mScale)
        {
            mScale   = cachedTransform.localScale;
            mChanged = true;
        }

        if (sprite != null && (force || mInner != mSprite.inner || mOuter != mSprite.outer))
        {
            Texture tex = mainTexture;

            if (tex != null)
            {
                mInner = mSprite.inner;
                mOuter = mSprite.outer;

                mInnerUV = mInner;
                mOuterUV = mOuter;

                if (atlas.coordinates == UIAtlas.Coordinates.Pixels)
                {
                    mOuterUV = NGUIMath.ConvertToTexCoords(mOuterUV, tex.width, tex.height);
                    mInnerUV = NGUIMath.ConvertToTexCoords(mInnerUV, tex.width, tex.height);
                }
            }
        }
    }
Beispiel #6
0
    /// <summary>
    /// Draw the sprite preview.
    /// </summary>

    public override void OnPreviewGUI(Rect rect, GUIStyle background)
    {
        if (mSprite == null || mAtlas == null)
        {
            return;
        }

        Texture2D tex = mAtlas.texture as Texture2D;

        if (tex == null)
        {
            return;
        }

        Rect outer = new Rect(mSprite.outer);
        Rect inner = new Rect(mSprite.inner);
        Rect uv    = outer;

        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
        {
            uv = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);
        }
        else
        {
            outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);
            inner = NGUIMath.ConvertToPixels(inner, tex.width, tex.height, true);
        }
        NGUIEditorTools.DrawSprite(tex, rect, outer, inner, uv, Color.white);
    }
    // Token: 0x060008C1 RID: 2241 RVA: 0x00046134 File Offset: 0x00044334
    public override void OnFill(List <Vector3> verts, List <Vector2> uvs, List <Color> cols)
    {
        Texture mainTexture = this.mainTexture;

        if (mainTexture == null)
        {
            return;
        }
        if ((!this.mSpriteSet || this.mSprite == null) && this.GetAtlasSprite() == null)
        {
            return;
        }
        Rect rect  = new Rect((float)this.mSprite.x, (float)this.mSprite.y, (float)this.mSprite.width, (float)this.mSprite.height);
        Rect rect2 = new Rect((float)(this.mSprite.x + this.mSprite.borderLeft), (float)(this.mSprite.y + this.mSprite.borderTop), (float)(this.mSprite.width - this.mSprite.borderLeft - this.mSprite.borderRight), (float)(this.mSprite.height - this.mSprite.borderBottom - this.mSprite.borderTop));

        rect  = NGUIMath.ConvertToTexCoords(rect, mainTexture.width, mainTexture.height);
        rect2 = NGUIMath.ConvertToTexCoords(rect2, mainTexture.width, mainTexture.height);
        int count = verts.Count;

        base.Fill(verts, uvs, cols, rect, rect2);
        if (this.onPostFill != null)
        {
            this.onPostFill(this, count, verts, uvs, cols);
        }
    }
Beispiel #8
0
    /// <summary>
    /// Update the texture UVs used by the widget.
    /// </summary>

    virtual public void UpdateUVs(bool force)
    {
        if ((type == Type.Sliced || type == Type.Tiled) && cachedTransform.localScale != mScale)
        {
            mScale   = cachedTransform.localScale;
            mChanged = true;
        }

        if (isValid && (force
#if UNITY_EDITOR
                        || !Application.isPlaying && (mOuter != mSprite.outer || mInner != mSprite.inner)
#endif
                        ))
        {
            Texture tex = mainTexture;

            if (tex != null)
            {
                mInner = mSprite.inner;
                mOuter = mSprite.outer;

                mInnerUV = mInner;
                mOuterUV = mOuter;

                if (atlas.coordinates == UIAtlas.Coordinates.Pixels)
                {
                    mOuterUV = NGUIMath.ConvertToTexCoords(mOuterUV, tex.width, tex.height);
                    mInnerUV = NGUIMath.ConvertToTexCoords(mInnerUV, tex.width, tex.height);
                }
            }
        }
    }
Beispiel #9
0
 public bool Validate(UIAtlas atlas)
 {
     if (atlas == null)
     {
         return(false);
     }
     if (!this.mIsValid)
     {
         if (string.IsNullOrEmpty(this.spriteName))
         {
             return(false);
         }
         this.mSprite = ((!(atlas != null)) ? null : atlas.GetSprite(this.spriteName));
         if (this.mSprite != null)
         {
             Texture texture = atlas.texture;
             if (texture == null)
             {
                 this.mSprite = null;
             }
             else
             {
                 this.mUV      = new Rect((float)this.mSprite.x, (float)this.mSprite.y, (float)this.mSprite.width, (float)this.mSprite.height);
                 this.mUV      = NGUIMath.ConvertToTexCoords(this.mUV, texture.width, texture.height);
                 this.mOffsetX = this.mSprite.paddingLeft;
                 this.mOffsetY = this.mSprite.paddingTop;
                 this.mWidth   = this.mSprite.width;
                 this.mHeight  = this.mSprite.height;
                 this.mAdvance = this.mSprite.width + (this.mSprite.paddingLeft + this.mSprite.paddingRight);
                 this.mIsValid = true;
             }
         }
     }
     return(this.mSprite != null);
 }
Beispiel #10
0
    /// <summary>
    /// Virtual function called by the UIPanel that fills the buffers.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture tex = mainTexture;

        if (tex == null)
        {
            return;
        }

        if (mSprite == null)
        {
            mSprite = atlas.GetSprite(spriteName);
        }
        if (mSprite == null)
        {
            return;
        }

        Rect outer = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
        Rect inner = new Rect(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop,
                              mSprite.width - mSprite.borderLeft - mSprite.borderRight,
                              mSprite.height - mSprite.borderBottom - mSprite.borderTop);

        outer = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);
        inner = NGUIMath.ConvertToTexCoords(inner, tex.width, tex.height);

        Fill(verts, uvs, cols, outer, inner);
    }
Beispiel #11
0
    Vector3 startPoint;     // Started position based on world


    public void CreateParticleUnit(Particle2D particle, float curTime)
    {
        // Sprite
        Texture tex = particle.atlas.texture;

        spriteData = particle.atlas.GetSprite(particle.GetSpriteNameRandomly());
        Rect outer = new Rect(spriteData.x, spriteData.y, spriteData.width, spriteData.height);
        Rect inner = new Rect(spriteData.x + spriteData.borderLeft, spriteData.y + spriteData.borderTop, spriteData.width - spriteData.borderLeft - spriteData.borderRight, spriteData.height - spriteData.borderBottom - spriteData.borderTop);

        texCoordsOuter = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);
        texCoordsInner = NGUIMath.ConvertToTexCoords(inner, tex.width, tex.height);

        // Emitter
        if (particle.emitter == Particle2D.Emitter.RECT)
        {
            float halfWidth  = particle.emitterWidth * 0.5f;
            float halfHeight = particle.emitterHeight * 0.5f;
            generatedPosition = new Vector3(UnityEngine.Random.Range(-halfWidth, halfWidth), UnityEngine.Random.Range(-halfHeight, halfHeight), 0);
        }
        else if (particle.emitter == Particle2D.Emitter.CIRCLE)
        {
            float rad   = particle.emitterRadius;
            float r     = UnityEngine.Random.Range(-rad, rad);
            float angle = UnityEngine.Random.Range(0, Mathf.PI);
            float x     = Mathf.Cos(angle) * r;
            float y     = Mathf.Sin(angle) * r;
            generatedPosition = new Vector3(x, y, 0);
        }
        else
        {
            generatedPosition = Vector3.zero;
        }

        startPoint = particle.transform.position;

        // Life
        maxLife = UnityEngine.Random.Range(particle.minLifeTime, particle.maxLifeTime);

        // Size
        float size = UnityEngine.Random.Range(particle.minSize, particle.maxSize);

        scale = new Vector2(size, size);

        // Rotation
        if (particle.useRotation)
        {
            localRotation = Quaternion.Euler(new Vector3(-UnityEngine.Random.Range(particle.minRotation.x, particle.maxRotation.x), -UnityEngine.Random.Range(particle.minRotation.y, particle.maxRotation.y), -UnityEngine.Random.Range(particle.minRotation.z, particle.maxRotation.z)));
        }
        else
        {
            localRotation = Quaternion.identity;
        }

        // Velocity
        velocity = Quaternion.AngleAxis(UnityEngine.Random.Range(particle.minAngle, particle.maxAngle), Vector3.back) * new Vector3(0f, UnityEngine.Random.Range(particle.minPower, particle.maxPower), 0f);

        // Time
        startTime = curTime;
        endTime   = startTime + maxLife;
    }
Beispiel #12
0
    /// <summary>
    /// Virtual function called by the UIPanel that fills the buffers.
    /// </summary>

    public override void OnFill(List <Vector3> verts, List <Vector2> uvs, List <Color> cols)
    {
        Texture tex = mainTexture;

        if (tex == null)
        {
            return;
        }

        if (mSprite == null)
        {
            GetAtlasSprite();
        }
        if (mSprite == null)
        {
            return;
        }

        Rect outer = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
        Rect inner = new Rect(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop,
                              mSprite.width - mSprite.borderLeft - mSprite.borderRight,
                              mSprite.height - mSprite.borderBottom - mSprite.borderTop);

        outer = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);
        inner = NGUIMath.ConvertToTexCoords(inner, tex.width, tex.height);

        int offset = verts.Count;

        Fill(verts, uvs, cols, outer, inner);

        if (onPostFill != null)
        {
            onPostFill(this, offset, verts, uvs, cols);
        }
    }
Beispiel #13
0
    /// <summary>
    /// Virtual function called by the UIPanel that fills the buffers.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color> cols)
    {
        var tex = mainTexture;

        if (tex == null)
        {
            return;
        }

        if (mSprite == null)
        {
            mSprite = atlas.GetSprite(spriteName);
        }
        if (mSprite == null)
        {
            return;
        }

        var outer = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
        var inner = new Rect(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop,
                             mSprite.width - mSprite.borderLeft - mSprite.borderRight,
                             mSprite.height - mSprite.borderBottom - mSprite.borderTop);

        outer = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);
        inner = NGUIMath.ConvertToTexCoords(inner, tex.width, tex.height);

        var offset = verts.size;

        Fill(verts, uvs, cols, outer, inner);

        if (onPostFill != null)
        {
            onPostFill(this, offset, verts, uvs, cols);
        }
    }
Beispiel #14
0
 public bool Validate(UIAtlas atlas)
 {
     if (atlas == null)
     {
         return(false);
     }
     if (!mIsValid)
     {
         if (string.IsNullOrEmpty(spriteName))
         {
             return(false);
         }
         mSprite = ((!(atlas != null)) ? null : atlas.GetSprite(spriteName));
         if (mSprite != null)
         {
             Texture texture = atlas.texture;
             if (texture == null)
             {
                 mSprite = null;
             }
             else
             {
                 mUV      = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
                 mUV      = NGUIMath.ConvertToTexCoords(mUV, texture.width, texture.height);
                 mOffsetX = mSprite.paddingLeft;
                 mOffsetY = mSprite.paddingTop;
                 mWidth   = mSprite.width;
                 mHeight  = mSprite.height;
                 mAdvance = mSprite.width + (mSprite.paddingLeft + mSprite.paddingRight);
                 mIsValid = true;
             }
         }
     }
     return(mSprite != null);
 }
Beispiel #15
0
 public static Rect MakePixelPerfect(Rect rect, int width, int height)
 {
     rect      = NGUIMath.ConvertToPixels(rect, width, height, true);
     rect.xMin = (float)Mathf.RoundToInt(rect.xMin);
     rect.yMin = (float)Mathf.RoundToInt(rect.yMin);
     rect.xMax = (float)Mathf.RoundToInt(rect.xMax);
     rect.yMax = (float)Mathf.RoundToInt(rect.yMax);
     return(NGUIMath.ConvertToTexCoords(rect, width, height));
 }
Beispiel #16
0
    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture tex = mainTexture;

        if (tex == null)
        {
            return;
        }

        if (mSprite == null)
        {
            mSprite = atlas.GetSprite(spriteName);
        }
        if (mSprite == null)
        {
            return;
        }

        Rect outer = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
        Rect inner = new Rect(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop,
                              mSprite.width - mSprite.borderLeft - mSprite.borderRight,
                              mSprite.height - mSprite.borderBottom - mSprite.borderTop);

        outer = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);
        inner = NGUIMath.ConvertToTexCoords(inner, tex.width, tex.height);

        int offset = verts.size;

        mOuterUV = outer;
        mInnerUV = inner;

        switch (symmetryType)
        {
        case SymmetryType.SimpleLR:
            SimpleFillLR(verts, uvs, cols);
            break;

        case SymmetryType.SimpleBoth:
            SimpleFillBoth(verts, uvs, cols);
            break;

        case SymmetryType.SliceLR:
            SlicedFillLR(verts, uvs, cols);
            break;

        case SymmetryType.SliceBoth:
            SlicedFillBoth(verts, uvs, cols);
            break;
        }


        if (onPostFill != null)
        {
            onPostFill(this, offset, verts, uvs, cols);
        }
    }
Beispiel #17
0
    /// <summary>
    /// Validate this symbol, given the specified atlas.
    /// </summary>

    public bool Validate(UIAtlas atlas)
    {
        if (atlas == null)
        {
            return(false);
        }

#if UNITY_EDITOR
        if (!Application.isPlaying || mSprite == null)
#else
        if (mSprite == null)
#endif
        {
            if (string.IsNullOrEmpty(spriteName))
            {
                return(false);
            }

            mSprite = (atlas != null) ? atlas.GetSprite(spriteName) : null;

            if (mSprite != null)
            {
                Texture tex = atlas.texture;

                if (tex == null)
                {
                    mSprite = null;
                }
                else
                {
                    Rect inner = mSprite.inner;
                    Rect outer = mSprite.outer;
                    mUV = outer;

                    if (atlas.coordinates == UIAtlas.Coordinates.Pixels)
                    {
                        mUV = NGUIMath.ConvertToTexCoords(mUV, tex.width, tex.height);
                    }
                    else
                    {
                        inner = NGUIMath.ConvertToPixels(inner, tex.width, tex.height, true);
                        outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);
                    }

                    mOffsetX     = Mathf.RoundToInt(outer.x - inner.x);
                    mOffsetY     = Mathf.RoundToInt(outer.y - inner.y);
                    mOuterWidth  = Mathf.RoundToInt(outer.width);
                    mOuterHeight = Mathf.RoundToInt(outer.height);
                    mInnerWidth  = Mathf.RoundToInt(inner.width);
                }
            }
        }
        return(mSprite != null);
    }
Beispiel #18
0
    /// <summary>
    /// Validate this symbol, given the specified atlas.
    /// </summary>

    public bool Validate(UIAtlas atlas)
    {
        if (atlas == null)
        {
            return(false);
        }

#if UNITY_EDITOR
        if (!Application.isPlaying || !mIsValid)
#else
        if (!mIsValid)
#endif
        {
            if (string.IsNullOrEmpty(spriteName))
            {
                return(false);
            }

            mSprite = (atlas != null) ? atlas.GetSprite(spriteName) : null;

            if (mSprite != null)
            {
                Texture tex = atlas.texture;

                if (tex == null)
                {
                    mSprite = null;
                }
                else
                {
                    Rect outer = mSprite.outer;
                    mUV = outer;

                    if (atlas.coordinates == UIAtlas.Coordinates.Pixels)
                    {
                        mUV = NGUIMath.ConvertToTexCoords(mUV, tex.width, tex.height);
                    }
                    else
                    {
                        outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);
                    }

                    mOffsetX = Mathf.RoundToInt(mSprite.paddingLeft * outer.width);
                    mOffsetY = Mathf.RoundToInt(mSprite.paddingTop * outer.width);
                    mWidth   = Mathf.RoundToInt(outer.width);
                    mHeight  = Mathf.RoundToInt(outer.height);
                    mAdvance = Mathf.RoundToInt(outer.width + (mSprite.paddingRight + mSprite.paddingLeft) * outer.width);
                    mIsValid = true;
                }
            }
        }
        return(mSprite != null);
    }
Beispiel #19
0
    public void FillV2(
        BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols,
        BetterList <Vector3> vertex1, BetterList <Vector4> vertex2, BetterList <Vector2> vertex3)
    {
        Vector3       initPos;
        bool          isFacingRright;
        PopEntryType  type;
        string        loadPath;
        List <string> popValue;

        foreach (mPopValue mPopValue in this.list)
        {
            initPos        = mPopValue.pos;
            isFacingRright = mPopValue.isFacingRright;
            type           = mPopValue.popType;
            loadPath       = "VertexFrame/" + type;
            popValue       = mPopValue.value;


            for (int i = 0; i < popValue.Count; i++)
            {
                ///第一帧
                ///第二帧关键帧
                ///第三帧关键帧
                ///第四帧关键帧

                ///是否是多个字符串组合
                if (isMultiply(type))
                {
                    multoPop_Meta_Info popInfo = Resources.Load <multoPop_Meta_Info>(loadPath);
                    popInfo.Fill(initPos, isFacingRright, i, popValue.Count, verts, vertex1, vertex2, vertex3, cols);
                }
                else
                {
                    sinlePop_Meta_Info popInfo = Resources.Load <sinlePop_Meta_Info>(loadPath);
                    popInfo.Fill(initPos, isFacingRright, verts, vertex1, vertex2, vertex3, cols);
                }

                UISpriteData mSprite =
                    mPopEntryManagerV2.Instance.uiAtlas.GetSprite(popValue[i].ToString());

                Texture tex   = mPopEntryManagerV2.Instance.uiAtlas.texture;
                Rect    outer = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
                outer = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);

                uvs.Add(new Vector2(outer.xMin, outer.yMin));
                uvs.Add(new Vector2(outer.xMin, outer.yMax));
                uvs.Add(new Vector2(outer.xMax, outer.yMax));
                uvs.Add(new Vector2(outer.xMax, outer.yMin));
            }
        }
    }
Beispiel #20
0
    void InitUVs()
    {
        if (Animations.Length > 1)
        {
            uv0  = new Vector2[Animations.Length];
            uv1  = new Vector2[Animations.Length];
            uv2  = new Vector2[Animations.Length];
            uv3  = new Vector2[Animations.Length];
            size = new Vector2[Animations.Length];

            for (int i = 0; i < Animations.Length; i++)
            {
                UIAtlas.Sprite sprite = atlas.GetSprite(Animations[i]);

                if (sprite == null)
                {
                    uv0[i] = Vector2.zero;
                    uv1[i] = Vector2.zero;
                    uv2[i] = Vector2.zero;
                    uv3[i] = Vector2.zero;
                }
                else
                {
                    Rect outuv = sprite.outer;
                    size[i].x = outuv.width;
                    size[i].y = outuv.height;

                    outuv  = NGUIMath.ConvertToTexCoords(outuv, atlas.texture.width, atlas.texture.height);
                    uv0[i] = new Vector2(outuv.xMin, outuv.yMin);
                    uv1[i] = new Vector2(outuv.xMax, outuv.yMax);
                    uv2[i] = new Vector2(uv1[i].x, uv0[i].y);
                    uv3[i] = new Vector2(uv0[i].x, uv1[i].y);
                }
            }
        }
        else
        {
            uv0  = new Vector2[1];
            uv1  = new Vector2[1];
            uv2  = new Vector2[1];
            uv3  = new Vector2[1];
            size = new Vector2[1];

            uv0[0]    = new Vector2(mOuterUV.xMin, mOuterUV.yMin);
            uv1[0]    = new Vector2(mOuterUV.xMax, mOuterUV.yMax);
            uv2[0]    = new Vector2(uv1[0].x, uv0[0].y);
            uv3[0]    = new Vector2(uv0[0].x, uv1[0].y);
            size[0].x = sprite.outer.width;
            size[0].y = sprite.outer.height;
        }
    }
Beispiel #21
0
    /// <summary>
    /// Virtual function called by the UIPanel that fills the buffers.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture tex = mainTexture;

        if (tex == null)
        {
            return;
        }

        if (mSprite == null)
        {
            mSprite = atlas.GetSprite(spriteName);
        }
        if (mSprite == null)
        {
            return;
        }

        Rect outer = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
        Rect inner = new Rect(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop,
                              mSprite.width - mSprite.borderLeft - mSprite.borderRight,
                              mSprite.height - mSprite.borderBottom - mSprite.borderTop);

        //Taesang remove edge
        if (mSprite.removeEdge == 1)
        {
            outer.x      += 1;
            outer.width  -= 2;
            outer.y      += 1;
            outer.height -= 2;

            inner.x      += 1;
            inner.width  -= 2;
            inner.y      += 1;
            inner.height -= 2;
        }
        //End Taesang

        outer = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);
        inner = NGUIMath.ConvertToTexCoords(inner, tex.width, tex.height);

        int offset = verts.size;

        Fill(verts, uvs, cols, outer, inner);

        if (onPostFill != null)
        {
            onPostFill(this, offset, verts, uvs, cols);
        }
    }
Beispiel #22
0
    /// <summary>
    /// Virtual function called by the UIPanel that fills the buffers.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture tex = mainTexture;

        if (tex == null)
        {
            return;
        }

        if (mSprite == null)
        {
            mSprite = atlas.GetSprite(spriteName);
        }
        if (mSprite == null)
        {
            return;
        }

        mOuterUV.Set(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
        mInnerUV.Set(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop,
                     mSprite.width - mSprite.borderLeft - mSprite.borderRight,
                     mSprite.height - mSprite.borderBottom - mSprite.borderTop);

        mOuterUV = NGUIMath.ConvertToTexCoords(mOuterUV, tex.width, tex.height);
        mInnerUV = NGUIMath.ConvertToTexCoords(mInnerUV, tex.width, tex.height);

        switch (type)
        {
        case Type.Simple:
            SimpleFill(verts, uvs, cols);
            break;

        case Type.Sliced:
            SlicedFill(verts, uvs, cols);
            break;

        case Type.Filled:
            FilledFill(verts, uvs, cols);
            break;

        case Type.Tiled:
            TiledFill(verts, uvs, cols);
            break;

        case Type.Advanced:
            AdvancedFill(verts, uvs, cols);
            break;
        }
    }
Beispiel #23
0
 public void UpdateUVRect()
 {
     if (!(mAtlas == null))
     {
         Texture texture = mAtlas.texture;
         if (texture != null)
         {
             mUVRect = new Rect((float)(mSprite.x - mSprite.paddingLeft), (float)(mSprite.y - mSprite.paddingTop), (float)(mSprite.width + mSprite.paddingLeft + mSprite.paddingRight), (float)(mSprite.height + mSprite.paddingTop + mSprite.paddingBottom));
             mUVRect = NGUIMath.ConvertToTexCoords(mUVRect, texture.width, texture.height);
             if (mSprite.hasPadding)
             {
                 Trim();
             }
         }
     }
 }
Beispiel #24
0
    /// <summary>
    /// Update the texture UVs used by the widget.
    /// </summary>

    override public void UpdateUVs()
    {
        Init();
        Texture tex = mainTexture;

        if (tex != null && sprite != null)
        {
            mOuterUV.Set(mSprite.outer.x, mSprite.outer.y, mSprite.outer.width, mSprite.outer.height);
            mInnerUV.Set(mSprite.outer.x + mSprite.borderLeft, mSprite.outer.y + mSprite.borderTop, mSprite.outer.width - mSprite.borderLeft - mSprite.borderRight, mSprite.outer.height - mSprite.borderBottom - mSprite.borderTop);

            mOuterUV = NGUIMath.ConvertToTexCoords(mOuterUV, tex.width, tex.height);
            mInnerUV = NGUIMath.ConvertToTexCoords(mInnerUV, tex.width, tex.height);

            mChanged = true;
        }
    }
Beispiel #25
0
    public bool Validate(UIAtlas atlas)
    {
        if (atlas == null)
        {
            return(false);
        }

        if (!mIsValid)
        {
            if (string.IsNullOrEmpty(spriteName))
            {
                return(false);
            }

            mSprite = atlas == null ? null : atlas.GetSprite(spriteName);
            if (mSprite != null)
            {
                var texture = atlas.texture;
                if (texture == null)
                {
                    mSprite = null;
                }
                else
                {
                    var outer = mSprite.outer;
                    mUV = outer;
                    if (atlas.coordinates == UIAtlas.Coordinates.Pixels)
                    {
                        mUV = NGUIMath.ConvertToTexCoords(mUV, texture.width, texture.height);
                    }
                    else
                    {
                        outer = NGUIMath.ConvertToPixels(outer, texture.width, texture.height, true);
                    }

                    mOffsetX = Mathf.RoundToInt(mSprite.paddingLeft * outer.width);
                    mOffsetY = Mathf.RoundToInt(mSprite.paddingTop * outer.width);
                    mWidth   = Mathf.RoundToInt(outer.width);
                    mHeight  = Mathf.RoundToInt(outer.height);
                    mAdvance = Mathf.RoundToInt(outer.width + (mSprite.paddingRight + mSprite.paddingLeft) * outer.width);
                    mIsValid = true;
                }
            }
        }

        return(mSprite != null);
    }
Beispiel #26
0
    /// <summary>
    /// Forcefully update the font's sprite reference.
    /// </summary>

    public void UpdateUVRect()
    {
        if (mAtlas == null)
        {
            return;
        }

        Texture tex = null;
        var     ia  = mAtlas as INGUIAtlas;

        if (ia != null)
        {
            tex = ia.texture;
        }

        if (tex != null)
        {
            mUVRect = new Rect(
                mSprite.x - mSprite.paddingLeft,
                mSprite.y - mSprite.paddingTop,
                mSprite.width + mSprite.paddingLeft + mSprite.paddingRight,
                mSprite.height + mSprite.paddingTop + mSprite.paddingBottom);

            mUVRect = NGUIMath.ConvertToTexCoords(mUVRect, tex.width, tex.height);
#if UNITY_EDITOR
            // The font should always use the original texture size
            if (mFont != null)
            {
                float tw = (float)mFont.texWidth / tex.width;
                float th = (float)mFont.texHeight / tex.height;

                if (tw != mUVRect.width || th != mUVRect.height)
                {
                    //Debug.LogWarning("Font sprite size doesn't match the expected font texture size.\n" +
                    //	"Did you use the 'inner padding' setting on the Texture Packer? It must remain at '0'.", this);
                    mUVRect.width  = tw;
                    mUVRect.height = th;
                }
            }
#endif
            // Trimmed sprite? Trim the glyphs
            if (mSprite.hasPadding)
            {
                Trim();
            }
        }
    }
 public void UpdateUVRect()
 {
     if (this.mAtlas == null)
     {
         return;
     }
     Texture texture = this.mAtlas.texture;
     if (texture != null)
     {
         this.mUVRect = new Rect((float)(this.mSprite.x - this.mSprite.paddingLeft), (float)(this.mSprite.y - this.mSprite.paddingTop), (float)(this.mSprite.width + this.mSprite.paddingLeft + this.mSprite.paddingRight), (float)(this.mSprite.height + this.mSprite.paddingTop + this.mSprite.paddingBottom));
         this.mUVRect = NGUIMath.ConvertToTexCoords(this.mUVRect, texture.get_width(), texture.get_height());
         if (this.mSprite.hasPadding)
         {
             this.Trim();
         }
     }
 }
Beispiel #28
0
 public virtual void UpdateUVs(bool force)
 {
     if (this.sprite != null && (force || this.mOuter != this.mSprite.outer))
     {
         Texture texture = base.mainTexture;
         if (texture != null)
         {
             this.mOuter   = this.mSprite.outer;
             this.mOuterUV = this.mOuter;
             if (this.mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
             {
                 this.mOuterUV = NGUIMath.ConvertToTexCoords(this.mOuterUV, texture.width, texture.height);
             }
             base.ChangedAuto();
         }
     }
 }
Beispiel #29
0
    public void UpdateUVRect()
    {
        if (this.mAtlas == (UnityEngine.Object)null)
        {
            return;
        }
        Texture texture = this.mAtlas.texture;

        if (texture != (UnityEngine.Object)null)
        {
            this.mUVRect = new Rect((Single)(this.mSprite.x - this.mSprite.paddingLeft), (Single)(this.mSprite.y - this.mSprite.paddingTop), (Single)(this.mSprite.width + this.mSprite.paddingLeft + this.mSprite.paddingRight), (Single)(this.mSprite.height + this.mSprite.paddingTop + this.mSprite.paddingBottom));
            this.mUVRect = NGUIMath.ConvertToTexCoords(this.mUVRect, texture.width, texture.height);
            if (this.mSprite.hasPadding)
            {
                this.Trim();
            }
        }
    }
Beispiel #30
0
 static public int ConvertToTexCoords_s(IntPtr l)
 {
     try {
         UnityEngine.Rect a1;
         checkValueType(l, 1, out a1);
         System.Int32 a2;
         checkType(l, 2, out a2);
         System.Int32 a3;
         checkType(l, 3, out a3);
         var ret = NGUIMath.ConvertToTexCoords(a1, a2, a3);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }