コード例 #1
0
    // Rebuild mesh
    public void UpdateUvs()
    {
        Material rSpriteMaterial = m_rSpriteData.renderMeshMaterial;

        // Handle the case where the atlas doesn't contains the texture anymore
        if (m_rSpriteSettings.ShouldUseAtlas(m_rSpriteSettings.textureContainer.GUID))
        {
            rSpriteMaterial   = m_rSpriteSettings.atlas.GetMaterial(m_rSpriteSettings.textureContainer.GUID);
            atlasGenerationID = m_rSpriteSettings.atlas.generationId;
        }
        else
        {
            m_rSpriteSettings.atlas = null;
            rSpriteMaterial         = m_rSpriteData.renderMeshMaterial;
            atlasGenerationID       = "";
        }

        // Update UVs
        Mesh rSpriteMesh = m_rSpriteData.renderMesh;

        rSpriteMesh.uv = Uni2DSpriteUtils.BuildUVs(m_rSpriteSettings.textureContainer,
                                                   m_rSpriteData.renderMeshUVs,
                                                   m_rSpriteSettings.atlas);

        // Update material
        Renderer rSpriteRender = this.renderer;

        if (rSpriteRender != null)
        {
            rSpriteRender.sharedMaterial = rSpriteMaterial;
        }

        EditorUtility.SetDirty(this);
    }
コード例 #2
0
 public static Vector2 ComputePivotCoords(Texture2D a_rTexture, PivotType a_eSpritePivotType, Vector2 a_f2CustomPivotPoint)
 {
     if (a_rTexture == null)
     {
         return(Uni2DSpriteUtils.ComputePivotCoords(0.0f, 0.0f, a_eSpritePivotType, a_f2CustomPivotPoint));
     }
     else
     {
         return(Uni2DSpriteUtils.ComputePivotCoords(a_rTexture.width, a_rTexture.height, a_eSpritePivotType, a_f2CustomPivotPoint));
     }
 }
コード例 #3
0
    // Set the frame draw by the sprite
    private void SetSpriteFrame(Texture2DContainer a_rTextureContainer, Uni2DTextureAtlas a_rTextureAtlas, int a_iWidth, int a_iHeight)
    {
        bool a_bUpdateMesh = false;

        if (m_iCurrentFrameTextureWidth != a_iWidth || m_iCurrentFrameTextureHeight != a_iHeight)
        {
            m_iCurrentFrameTextureWidth  = a_iWidth;
            m_iCurrentFrameTextureHeight = a_iHeight;
            a_bUpdateMesh = true;
        }

        bool a_bUpdateUV = false;

        if (m_rCurrentFrameAtlas != a_rTextureAtlas || (m_rCurrentFrameAtlas != null && m_rCurrentFrameTextureContainer != a_rTextureContainer))
        {
            m_rCurrentFrameTextureContainer = a_rTextureContainer;
            m_rCurrentFrameAtlas            = a_rTextureAtlas;
            a_bUpdateUV = true;
        }

        Uni2DSpriteUtils.SetSpriteFrame(this, a_rTextureContainer, a_rTextureAtlas, a_iWidth, a_iHeight, a_bUpdateMesh, a_bUpdateUV);
    }