示例#1
0
        /// <summary>
        /// Load the document.
        /// </summary>
        void LoadDocument()
        {
            if (layout.layoutDocumentAsset == null)
            {
                return;
            }

            // load the map
            layout.Load();

            // update the root friendly name
            if (layout.document != null & layout.document.allLayers != null)
            {
                layout.document.allLayers[0].photoshopLayerName = layout.GetFriendlyDocumentName();
            }

            // try to auto-detect the texture source
            FormatGuesser guesser = new FormatGuesser();

            guesser.layout = layout;
            switch (guesser.Guess())
            {
            case TextureSource.AssetFolder:
                SpriteAssigner.AssignSpritesFromFolder(layout);
                break;

            case TextureSource.Spritesheet:
                SpriteAssigner.AssignSpritesFromSpritesheet(layout);
                break;

#if PS2D_TK2D
            case TextureSource.Tk2dSpriteCollection:
                _spriteCollectionData = guesser.spriteCollectionData;
                SpriteAssigner.AssignSpritesFromTk2dCollection(layout, _spriteCollectionData);
                break;
#endif
            default:
                break;
            }
        }
示例#2
0
        /// <summary>
        /// Choose the spritesheet.
        /// </summary>
        void MakeSpritesheetField()
        {
            if (layout == null ||
                layout.document == null ||
                layout.imageSource != TextureSource.Spritesheet
                )
            {
                return;
            }

            var        previousValue = layout.spritesheetTexture;
            GUIContent labelContent  = new GUIContent();

            labelContent.text         = "Spritesheet";
            labelContent.tooltip      = "The place where your spritesheet lives.";
            layout.spritesheetTexture = (Texture)EditorGUILayout.ObjectField(labelContent, layout.spritesheetTexture, typeof(Texture), false, GUILayout.ExpandWidth(false));

            // did we change?
            if (layout.spritesheetTexture != null && previousValue != layout.spritesheetTexture)
            {
                SpriteAssigner.AssignSpritesFromSpritesheet(layout);
            }
        }
示例#3
0
        /// <summary>
        /// Allows users to pick the asset folder containing their images.
        /// </summary>
        void MakeImageAssetsFolderField()
        {
            if (layout == null ||
                layout.document == null ||
                layout.imageSource != TextureSource.AssetFolder
                )
            {
                return;
            }

            var previousValue = layout.imageSourceAssetFolder;

            GUIContent contentLabel = new GUIContent();

            contentLabel.text             = "Asset Folder";
            contentLabel.tooltip          = "The asset folder which contains the textures.";
            layout.imageSourceAssetFolder = EditorGUILayout.ObjectField(contentLabel, layout.imageSourceAssetFolder, typeof(Object), false);

            // did we change?
            if (layout.imageSourceAssetFolder != null && previousValue != layout.imageSourceAssetFolder)
            {
                SpriteAssigner.AssignSpritesFromFolder(layout);
            }
        }
示例#4
0
        /// <summary>
        /// Choose a 2D Toolkit Sprite Collection field.
        /// </summary>
        void MakeTk2dSpriteCollectionField()
        {
#if PS2D_TK2D
            if (layout == null ||
                layout.document == null ||
                layout.imageSource != TextureSource.Tk2dSpriteCollection
                )
            {
                return;
            }

            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();

            GUIContent labelContent = new GUIContent();
            labelContent.text    = "Sprite Collection";
            labelContent.tooltip = "The 2D Toolkit sprite collection to use.";
            EditorGUILayout.PrefixLabel(labelContent);

            // discover the state of the sprite collection build keys
            bool freshBuildKey     = layout.currentSpriteCollectionBuildKey == 0;
            bool differentBuildKey = _spriteCollectionData != null && _spriteCollectionData.buildKey != layout.currentSpriteCollectionBuildKey;

            // should we reset the tk2d sprite collection cache?
            if (freshBuildKey || differentBuildKey)
            {
                _forceRefreshOfTk2dCollection = true;
                ReloadCollection();
            }

            // show the list
            EditorGUI.BeginChangeCheck();
            var previousSpriteCollection = _spriteCollectionData;
            _spriteCollectionData = tk2dSpriteGuiUtility.SpriteCollectionList(previousSpriteCollection);
            bool changed = EditorGUI.EndChangeCheck();

            // did we change to something valid?
            if (changed && _spriteCollectionData != null)
            {
                // let's just reload the collection... this too WAY too long to figure out
                // and I'm still convinced I'm doing it wrong.  It seems to work though.
                // then again, so does communism until you get it into the hands of the people.
                ReloadCollection();
            }


            // open in tk2d sprite collection editor
            GUIContent openInEditorContent = new GUIContent();
            openInEditorContent.image   = layout.editorGraphics.cog;
            openInEditorContent.tooltip = "Opens the 2D Toolkit sprite collection window.";
            GUIStyle openInEditorStyle = new GUIStyle(EditorStyles.miniButton);
            if (GUILayout.Button(openInEditorContent, openInEditorStyle))
            {
                // do we have a valid collection data?
                if (_spriteCollectionData != null)
                {
                    // find and load the collection asset
                    string collectionPath = AssetDatabase.GUIDToAssetPath(_spriteCollectionData.spriteCollectionGUID);
                    tk2dSpriteCollection spriteCollectionReload = AssetDatabase.LoadAssetAtPath(collectionPath, typeof(tk2dSpriteCollection)) as tk2dSpriteCollection;

                    // got it?
                    if (spriteCollectionReload != null)
                    {
                        // find and show the editor
                        tk2dSpriteCollectionEditorPopup v = EditorWindow.GetWindow(typeof(tk2dSpriteCollectionEditorPopup), false, "Sprite Collection Editor") as tk2dSpriteCollectionEditorPopup;
                        v.SetGeneratorAndSelectedSprite(spriteCollectionReload, _spriteCollectionData.FirstValidDefinitionIndex);
                        v.Show();
                    }
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            // should we reassign the sprites in our list?
            if ((_forceRefreshOfTk2dCollection || changed) && _spriteCollectionData != null)
            {
                // do we have a different tk2d build key?
                differentBuildKey = _spriteCollectionData.buildKey != layout.currentSpriteCollectionBuildKey;
                layout.currentSpriteCollectionBuildKey = _spriteCollectionData.buildKey;
                if (differentBuildKey || _forceRefreshOfTk2dCollection)
                {
                    // let's reload our sprite collection
                    SpriteAssigner.AssignSpritesFromTk2dCollection(layout, _spriteCollectionData);
                }
            }
            _forceRefreshOfTk2dCollection = false;
#endif
        }