本文整理汇总了C#中dfAtlas.RebuildIndexes方法的典型用法代码示例。如果您正苦于以下问题:C# dfAtlas.RebuildIndexes方法的具体用法?C# dfAtlas.RebuildIndexes怎么用?C# dfAtlas.RebuildIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dfAtlas
的用法示例。
在下文中一共展示了dfAtlas.RebuildIndexes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: rebuildAtlas
internal static bool rebuildAtlas( dfAtlas atlas )
{
try
{
EditorUtility.DisplayProgressBar( "Rebuilding Texture Atlas", "Processing changes to the texture atlas...", 0 );
var sprites = atlas.Items
.Where( i => i != null && !i.deleted )
.Select( i => new { source = i, texture = getTexture( i.textureGUID ) } )
.Where( i => i.texture != null )
.OrderByDescending( i => i.texture.width * i.texture.height )
.ToList();
var textures = sprites.Select( i => i.texture ).ToList();
var oldAtlasTexture = atlas.Material.mainTexture;
var texturePath = AssetDatabase.GetAssetPath( oldAtlasTexture );
var padding = EditorPrefs.GetInt( "DaikonForge.AtlasDefaultPadding", 2 );
var newAtlasTexture = new Texture2D( 0, 0, TextureFormat.RGBA32, false );
var newRects = newAtlasTexture.PackTextures2( textures.ToArray(), padding, dfTextureAtlasInspector.MaxAtlasSize, dfTextureAtlasInspector.ForceSquare );
byte[] bytes = newAtlasTexture.EncodeToPNG();
System.IO.File.WriteAllBytes( texturePath, bytes );
bytes = null;
DestroyImmediate( newAtlasTexture );
setAtlasTextureSettings( texturePath, false );
// Fix up the new sprite locations
for( int i = 0; i < sprites.Count; i++ )
{
sprites[ i ].source.region = newRects[ i ];
sprites[ i ].source.sizeInPixels = new Vector2( textures[ i ].width, textures[ i ].height );
sprites[ i ].source.texture = null;
}
// Remove any deleted sprites
atlas.Items.RemoveAll( i => i.deleted );
// Re-sort the Items collection
atlas.Items.Sort();
atlas.RebuildIndexes();
EditorUtility.SetDirty( atlas );
EditorUtility.SetDirty( atlas.Material );
dfGUIManager.RefreshAll( true );
return true;
}
catch( Exception err )
{
Debug.LogError( err.ToString(), atlas );
EditorUtility.DisplayDialog( "Error Rebuilding Texture Atlas", err.Message, "OK" );
return false;
}
finally
{
EditorUtility.ClearProgressBar();
}
}