本文整理汇总了C#中dfAtlas类的典型用法代码示例。如果您正苦于以下问题:C# dfAtlas类的具体用法?C# dfAtlas怎么用?C# dfAtlas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
dfAtlas类属于命名空间,在下文中一共展示了dfAtlas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadImage
internal void LoadImage(dfAtlas atlas, string source)
{
dfAtlas.ItemInfo item = atlas[source];
if (item == null)
{
throw new InvalidOperationException(string.Concat("Sprite does not exist in atlas: ", source));
}
this.Atlas = atlas;
this.Source = source;
this.Size = item.sizeInPixels;
this.Baseline = (int)this.Size.y;
}
示例2: buildItemTooltip
private string buildItemTooltip( dfAtlas.ItemInfo sprite )
{
if( sprite == null )
return "";
var width = (int)sprite.sizeInPixels.x;
var height = (int)sprite.sizeInPixels.y;
return string.Format(
"Atlas: {3} Sprite: {0} Size: {1}x{2}",
sprite.name,
width,
height,
atlas.name
);
}
示例3: Show
public static void Show( string title, dfAtlas atlas, string sprite, SelectionCallback callback )
{
if( atlas == null )
throw new Exception( "No Texture Atlas was specified" );
// Detect whether the user has deleted the textures after adding them to the Atlas
if( atlas.Texture == null )
throw new Exception( "The Texture Atlas does not have a texture or the texture was deleted" );
var dialog = ScriptableWizard.DisplayWizard<dfSpriteSelectionDialog>( title );
dialog.atlas = atlas;
dialog.selectedSprite = sprite;
dialog.minSize = new Vector2( 300, 200 );
dialog.callback = callback;
dialog.selectionShown = string.IsNullOrEmpty( sprite );
dialog.ShowAuxWindow();
}
示例4: RemoveSprite
public void RemoveSprite( dfAtlas atlas, string spriteName )
{
selectedTextures.Clear();
atlas[ spriteName ].deleted = true;
rebuildAtlas( atlas );
}
示例5: ShowAtlasActions
private static void ShowAtlasActions( dfAtlas atlas )
{
dfEditorUtil.DrawSeparator();
EditorGUILayout.BeginHorizontal();
{
if( GUILayout.Button( "Rebuild" ) )
{
rebuildAtlas( atlas );
}
if( GUILayout.Button( "Refresh Views" ) )
{
dfGUIManager.RefreshAll( true );
}
}
EditorGUILayout.EndHorizontal();
}
示例6: drawSprite
private void drawSprite( Rect rect, dfAtlas.ItemInfo sprite )
{
var size = sprite.sizeInPixels;
var destRect = rect;
if( destRect.width < size.x || destRect.height < size.y )
{
var newHeight = size.y * rect.width / size.x;
if( newHeight <= rect.height )
destRect.height = newHeight;
else
destRect.width = size.x * rect.height / size.y;
}
else
{
destRect.width = size.x;
destRect.height = size.y;
}
if( destRect.width < rect.width ) destRect.x = rect.x + ( rect.width - destRect.width ) * 0.5f;
if( destRect.height < rect.height ) destRect.y = rect.y + ( rect.height - destRect.height ) * 0.5f;
GUI.DrawTextureWithTexCoords( destRect, atlas.Material.mainTexture, sprite.region, true );
}
示例7: createImageBox
private dfMarkupBox createImageBox( dfAtlas atlas, string source, dfMarkupStyle style )
{
if( source.ToLowerInvariant().StartsWith( "http://" ) )
{
return null;
}
else if( atlas != null && atlas[ source ] != null )
{
var spriteBox = new dfMarkupBoxSprite( this, dfMarkupDisplayType.inline, style );
spriteBox.LoadImage( atlas, source );
return spriteBox;
}
else
{
var texture = dfMarkupImageCache.Load( source );
if( texture != null )
{
var textureBox = new dfMarkupBoxTexture( this, dfMarkupDisplayType.inline, style );
textureBox.LoadTexture( texture );
return textureBox;
}
}
return null;
}
示例8: Reimport
internal static void Reimport( dfAtlas atlas )
{
var textureFilePath = AssetDatabase.GUIDToAssetPath( atlas.imageFileGUID );
if( !File.Exists( textureFilePath ) )
{
Debug.LogError( string.Format( "The image file for atlas {0} could not be found", atlas.name ), atlas );
return;
}
var dataFilePath = AssetDatabase.GUIDToAssetPath( atlas.dataFileGUID );
if( !File.Exists( dataFilePath ) )
{
Debug.LogError( string.Format( "The data file for atlas {0} could not be found", atlas.name ), atlas );
return;
}
var dataFile = AssetDatabase.LoadAssetAtPath( dataFilePath, typeof( TextAsset ) ) as TextAsset;
if( dataFile == null )
{
Debug.LogError( string.Format( "Faile to open the data file for the {0} atlas", atlas.name ), atlas );
return;
}
var textureFile = AssetDatabase.LoadAssetAtPath( textureFilePath, typeof( Texture2D ) ) as Texture2D;
if( textureFile == null )
{
Debug.LogError( string.Format( "Faile to open the image file for the {0} atlas", atlas.name ), atlas );
return;
}
dfTextureAtlasInspector.setAtlasTextureSettings( textureFilePath, false );
var uvx = 1f / textureFile.width;
var uvy = 1f / textureFile.height;
var newSprites = new List<dfAtlas.ItemInfo>();
var oldSprites = atlas.Items;
var data = JSON.JsonDecode( dataFile.text ) as DICT;
var frames = data[ "frames" ] as DICT;
foreach( var key in frames.Keys )
{
var itemData = frames[ key ] as DICT;
var spriteName = Path.GetFileNameWithoutExtension( key );
var isRotated = (bool)itemData[ "rotated" ];
if( isRotated )
{
Debug.LogError( string.Format( "Sprite '{0}' is rotated. Rotated sprites are not yet supported", spriteName ) );
continue;
}
var frameRect = extractUVRect( itemData[ "frame" ] as DICT, textureFile );
var spriteSize = new Vector2( frameRect.width / uvx, frameRect.height / uvy );
var sprite = new dfAtlas.ItemInfo()
{
name = spriteName,
border = new RectOffset(),
deleted = false,
region = frameRect,
rotated = false,
sizeInPixels = spriteSize
};
newSprites.Add( sprite );
for( int i = 0; i < oldSprites.Count; i++ )
{
var old = oldSprites[ i ];
if( string.Equals( old.name, spriteName, StringComparison.OrdinalIgnoreCase ) )
{
sprite.border = old.border;
break;
}
}
}
newSprites.Sort();
atlas.Items.Clear();
atlas.Items.AddRange( newSprites );
var prefabPath = AssetDatabase.GetAssetPath( atlas );
var go = atlas.gameObject;
#region Delay execution of object selection to work around a Unity issue
// Declared with null value to eliminate "uninitialized variable"
// compiler error in lambda below.
EditorApplication.CallbackFunction callback = null;
callback = () =>
{
EditorUtility.FocusProjectWindow();
go = AssetDatabase.LoadMainAssetAtPath( prefabPath ) as GameObject;
Selection.objects = new UnityEngine.Object[] { go };
EditorGUIUtility.PingObject( go );
Debug.Log( "Texture Atlas prefab re-imported at " + prefabPath, go );
//.........这里部分代码省略.........
示例9: EditAtlasOptions
private void EditAtlasOptions( dfAtlas atlas )
{
if( atlas.generator == dfAtlas.TextureAtlasGenerator.Internal )
{
using( dfEditorUtil.BeginGroup( "Global Options" ) )
{
var packingMethodConfig = (dfTexturePacker.dfTexturePackingMethod)EditorPrefs.GetInt( "DaikonForge.AtlasPackingMethod", (int)dfTexturePacker.dfTexturePackingMethod.RectBestAreaFit );
var packingMethod = (dfTexturePacker.dfTexturePackingMethod)EditorGUILayout.EnumPopup( "Packing Method", packingMethodConfig );
if( packingMethod != packingMethodConfig )
{
EditorPrefs.SetInt( "DaikonForge.AtlasPackingMethod", (int)packingMethod );
}
var sizes = new string[] { "256", "512", "1024", "2048", "4096" };
var defaultIndex = Mathf.Max( 0, getIndex( sizes, dfTextureAtlasInspector.MaxAtlasSize.ToString() ) );
var selectedIndex = EditorGUILayout.Popup( "Max Size", defaultIndex, sizes );
dfTextureAtlasInspector.MaxAtlasSize = int.Parse( sizes[ selectedIndex ] );
var paddingConfig = EditorPrefs.GetInt( "DaikonForge.AtlasDefaultPadding", 2 );
var padding = Mathf.Max( 0, EditorGUILayout.IntField( "Padding", paddingConfig ) );
{
if( padding != paddingConfig )
{
EditorPrefs.SetInt( "DaikonForge.AtlasDefaultPadding", padding );
}
}
ForceSquare = EditorGUILayout.Toggle( "Force square", ForceSquare );
var extrudeSpritesConfig = EditorPrefs.GetBool( "DaikonForge.AtlasExtrudeSprites", false );
var extrudeSprites = EditorGUILayout.Toggle( "Extrude Edges", extrudeSpritesConfig );
{
if( extrudeSprites != extrudeSpritesConfig )
{
EditorPrefs.SetBool( "DaikonForge.AtlasExtrudeSprites", extrudeSprites );
}
}
}
}
else if( atlas.generator == dfAtlas.TextureAtlasGenerator.TexturePacker )
{
using( dfEditorUtil.BeginGroup( "Imported Texture Atlas" ) )
{
var dataFilePath = AssetDatabase.GUIDToAssetPath( atlas.dataFileGUID );
var dataFile = AssetDatabase.LoadAssetAtPath( dataFilePath, typeof( TextAsset ) ) as TextAsset;
EditorGUILayout.ObjectField( "Image File", atlas.Texture, typeof( Texture2D ), false );
EditorGUILayout.ObjectField( "Data File", dataFile, typeof( TextAsset ), false );
}
}
using( dfEditorUtil.BeginGroup( "Atlas Options" ) )
{
EditAtlasReplacement( atlas );
}
}
示例10: ShowAtlasActions
private static void ShowAtlasActions( dfAtlas atlas )
{
dfEditorUtil.DrawSeparator();
EditorGUILayout.BeginHorizontal();
{
if( atlas.generator == dfAtlas.TextureAtlasGenerator.TexturePacker )
{
if( GUILayout.Button( "Reimport" ) )
{
dfTexturePackerImporter.Reimport( atlas );
}
}
else if( GUILayout.Button( "Rebuild" ) )
{
rebuildAtlas( atlas );
}
if( GUILayout.Button( "Refresh Views" ) )
{
dfGUIManager.RefreshAll( true );
}
}
EditorGUILayout.EndHorizontal();
}
示例11: getTexture
private static Texture2D getTexture( dfAtlas atlas, string sprite )
{
var spriteInfo = atlas[ sprite ];
if( spriteInfo == null )
return null;
var guid = atlas[ sprite ].textureGUID;
if( string.IsNullOrEmpty( guid ) )
return null;
var path = AssetDatabase.GUIDToAssetPath( guid );
if( string.IsNullOrEmpty( path ) )
return null;
return AssetDatabase.LoadAssetAtPath( path, typeof( Texture2D ) ) as Texture2D;
}
示例12: DrawSprite
private static void DrawSprite( Rect rect, dfAtlas atlas, string sprite )
{
var spriteInfo = atlas[ sprite ];
var size = spriteInfo.sizeInPixels;
var destRect = rect;
if( destRect.width < size.x || destRect.height < size.y )
{
var newHeight = size.y * rect.width / size.x;
if( newHeight <= rect.height )
destRect.height = newHeight;
else
destRect.width = size.x * rect.height / size.y;
}
else
{
destRect.width = size.x;
destRect.height = size.y;
}
if( destRect.width < rect.width ) destRect.x = rect.x + ( rect.width - destRect.width ) * 0.5f;
if( destRect.height < rect.height ) destRect.y = rect.y + ( rect.height - destRect.height ) * 0.5f;
dfEditorUtil.DrawSprite( destRect, atlas, sprite );
}
示例13: SelectFontDefinition
protected internal static void SelectFontDefinition( string label, dfAtlas atlas, dfGUIManager view, string propertyName, bool colorizeIfMissing, int labelWidth )
{
var savedColor = GUI.color;
var showDialog = false;
try
{
GUI.enabled = ( atlas != null );
var value = (dfFontBase)getValue( view, propertyName );
if( value == null && colorizeIfMissing )
GUI.color = EditorGUIUtility.isProSkin ? Color.yellow : Color.red;
dfPrefabSelectionDialog.FilterCallback filterCallback = delegate( GameObject item )
{
if( atlas == null )
return false;
var font = item.GetComponent<dfFontBase>();
if( font == null )
return false;
if( font is dfFont )
{
var bitmappedFont = (dfFont)font;
if( bitmappedFont.Atlas == null || !dfAtlas.Equals( bitmappedFont.Atlas, atlas ) )
return false;
}
return true;
};
dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate( GameObject item )
{
var font = ( item == null ) ? null : item.GetComponent<dfFontBase>();
dfEditorUtil.MarkUndo( view, "Change Font" );
setValue( view, propertyName, font );
};
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField( label, "", GUILayout.Width( labelWidth ) );
var displayText = value == null ? "[none]" : value.name;
GUILayout.Label( displayText, "TextField" );
var evt = Event.current;
if( evt != null )
{
Rect textRect = GUILayoutUtility.GetLastRect();
if( evt.type == EventType.mouseDown && evt.clickCount == 2 )
{
if( textRect.Contains( evt.mousePosition ) )
{
if( GUI.enabled && value != null )
{
Selection.activeObject = value;
EditorGUIUtility.PingObject( value );
}
}
}
else if( evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform )
{
if( textRect.Contains( evt.mousePosition ) )
{
var draggedObject = DragAndDrop.objectReferences.First() as GameObject;
var draggedFont =
( draggedObject != null )
? draggedObject.GetComponent<dfFontBase>()
: null;
DragAndDrop.visualMode =
( draggedFont != null )
? DragAndDropVisualMode.Copy
: DragAndDropVisualMode.None;
if( evt.type == EventType.DragPerform )
{
selectionCallback( draggedObject );
}
evt.Use();
}
}
}
if( GUI.enabled && GUILayout.Button( new GUIContent( " ", "Edit Font" ), "IN ObjectField", GUILayout.Width( 14 ) ) )
{
showDialog = true;
}
}
EditorGUILayout.EndHorizontal();
//.........这里部分代码省略.........
示例14: createImageBox
private dfMarkupBox createImageBox(dfAtlas atlas, string source, dfMarkupStyle style)
{
if (source.ToLowerInvariant().StartsWith("http://"))
{
return null;
}
if (atlas != null && atlas[source] != null)
{
dfMarkupBoxSprite _dfMarkupBoxSprite = new dfMarkupBoxSprite(this, dfMarkupDisplayType.inline, style);
_dfMarkupBoxSprite.LoadImage(atlas, source);
return _dfMarkupBoxSprite;
}
Texture texture = dfMarkupImageCache.Load(source);
if (texture == null)
{
return null;
}
dfMarkupBoxTexture _dfMarkupBoxTexture = new dfMarkupBoxTexture(this, dfMarkupDisplayType.inline, style);
_dfMarkupBoxTexture.LoadTexture(texture);
return _dfMarkupBoxTexture;
}
示例15: getTexture
private static Texture2D getTexture( dfAtlas atlas, string sprite )
{
var guid = atlas[ sprite ].textureGUID;
var path = AssetDatabase.GUIDToAssetPath( guid );
return AssetDatabase.LoadAssetAtPath( path, typeof( Texture2D ) ) as Texture2D;
}