当前位置: 首页>>代码示例>>C#>>正文


C# dfAtlas类代码示例

本文整理汇总了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;
 }
开发者ID:HexHash,项目名称:LegacyRust,代码行数:12,代码来源:dfMarkupBoxSprite.cs

示例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
        );
    }
开发者ID:dashqasar,项目名称:GoogleMap,代码行数:16,代码来源:dfSpriteSelectionDialog.cs

示例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();
    }
开发者ID:BjarkeHou,项目名称:ProjectGuard,代码行数:17,代码来源:dfSpriteSelectionDialog.cs

示例4: RemoveSprite

 public void RemoveSprite( dfAtlas atlas, string spriteName )
 {
     selectedTextures.Clear();
     atlas[ spriteName ].deleted = true;
     rebuildAtlas( atlas );
 }
开发者ID:BjarkeHou,项目名称:ProjectGuard,代码行数:6,代码来源:dfTextureAtlasInspector.cs

示例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();
    }
开发者ID:haozi000005,项目名称:happy2d,代码行数:20,代码来源:dfTextureAtlasInspector.cs

示例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 );
    }
开发者ID:dashqasar,项目名称:GoogleMap,代码行数:26,代码来源:dfSpriteSelectionDialog.cs

示例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;
    }
开发者ID:AhrenLi,项目名称:2048,代码行数:31,代码来源:dfMarkupTags.cs

示例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 );
//.........这里部分代码省略.........
开发者ID:CoryBerg,项目名称:drexelNeonatal,代码行数:101,代码来源:dfTexturePackerImporter.cs

示例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 );
        }
    }
开发者ID:BjarkeHou,项目名称:ProjectGuard,代码行数:63,代码来源:dfTextureAtlasInspector.cs

示例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();
    }
开发者ID:BjarkeHou,项目名称:ProjectGuard,代码行数:27,代码来源:dfTextureAtlasInspector.cs

示例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;
    }
开发者ID:kvelury,项目名称:apocalyptia,代码行数:16,代码来源:dfFontDefinitionInspector.cs

示例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 );
    }
开发者ID:kvelury,项目名称:apocalyptia,代码行数:27,代码来源:dfAnimationClipInspector.cs

示例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();
//.........这里部分代码省略.........
开发者ID:zc1415926,项目名称:Unity-SelectCharacter-Scene,代码行数:101,代码来源:dfGUIManagerInspector.cs

示例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;
 }
开发者ID:HexHash,项目名称:LegacyRust,代码行数:21,代码来源:dfMarkupTagImg.cs

示例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;
    }
开发者ID:dashqasar,项目名称:GoogleMap,代码行数:7,代码来源:dfFontDefinitionInspector.cs


注:本文中的dfAtlas类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。