Ejemplo n.º 1
0
    // ----------------------------------------------------------------------------------
    void CreateSpriteAtlas(Material tarMat)
    {
        if (m_Sel.renderer == null)
        {
            Debug.LogWarning("m_Sel.renderer is nul!!!");
            return;
        }
        if (m_Sel.renderer.sharedMaterial == null)
        {
            Debug.LogWarning("m_Sel.renderer.sharedMaterial is nul!!!");
            return;
        }
        if (m_Sel.m_SpriteList == null || m_Sel.m_SpriteList.Count < 1)
        {
            return;
        }

        Texture2D AtlasTexture;

        AtlasTexture = BuildSpriteAtlas();

        byte[] bytes       = AtlasTexture.EncodeToPNG();
        string pathTexture = (tarMat.mainTexture != null ? AssetDatabase.GetAssetPath(tarMat.mainTexture) : NgFile.TrimFileExt(AssetDatabase.GetAssetPath(tarMat)) + ".png");

        // save texture
        File.WriteAllBytes(pathTexture, bytes);
        Debug.Log(pathTexture);
        AssetDatabase.Refresh();
        Object.DestroyImmediate(AtlasTexture);
//		ReimportTexture(pathTexture, m_wrapMode, m_filterMode, m_anisoLevel, m_nSpriteTextureSizes[(int)m_fSpriteTextureIndex], m_SpriteTextureFormat[(int)m_fSpriteTextureFormatIdx]);

        // Material
        tarMat.mainTexture = (Texture)AssetDatabase.LoadAssetAtPath(pathTexture, typeof(Texture));
        AssetDatabase.SaveAssets();

        m_Sel.SetSprite(m_Sel.GetCurrentSpriteIndex(), false);
    }