コード例 #1
0
        public void AddAnimationsToContext(AseSheetData aseSheetData,
                                           Dictionary <string, AnimationOptions> animationOptionsByTagName = null
                                           )
        {
            if (aseSheetData.meta.frameTags == null || aseSheetData.meta.frameTags.Length == 0)
            {
                return;
            }
            if (IndividualSprites == null)
            {
                GenerateIndividualSprites(aseSheetData, true);
            }

            foreach (var metaFrameTag in aseSheetData.meta.frameTags)
            {
                var anim = GenerateAnimation(metaFrameTag, aseSheetData.frames, IndividualSprites,
                                             animationOptionsByTagName?.ContainsKey(metaFrameTag.name) == true
                         ? animationOptionsByTagName[metaFrameTag.name]
                         : GetDefaultAnimationOptions);

                if (anim != null)
                {
                    AseFileContext.AddObjectToAsset("anim_" + metaFrameTag.name, anim);
                }
            }
        }
コード例 #2
0
        public Texture2D AddMainTextureToContext(string sheetFile)
        {
            GenerateMainTextureFromSheetFile(sheetFile);
            var objects = new List <Object>();

            AseFileContext.GetObjects(objects);
            var found = objects.Find(o => o.name == "AseSheetMainTexture");

            if (found)
            {
                Object.DestroyImmediate(found);
            }

            AseFileContext.AddObjectToAsset("AseSheetMainTexture", MainTexture, AseUtils.GetPixelArtIcon());
            AseFileContext.SetMainObject(MainTexture);

            return(MainTexture);
        }
コード例 #3
0
        public void GenerateIndividualSprites(AseSheetData sheetData, bool addToContext = false)
        {
            if (SpriteImportOptions == null)
            {
                SpriteImportOptions = SpriteImportOptions.Default;
            }

            if (MainTexture == null)
            {
                GenerateMainTextureFromSheetFile(Path.Combine(
                                                     Path.GetDirectoryName(sheetData.pathToSheetData) ??
                                                     throw new InvalidOperationException("Error while processing data path"),
                                                     sheetData.meta.image));
            }

            if (IndividualSprites != null)
            {
                foreach (var individualSprite in IndividualSprites)
                {
                    Object.DestroyImmediate(individualSprite);
                }
                IndividualSprites.Clear();
            }
            else
            {
                IndividualSprites = new List <Sprite>();
            }

            var addedObjects = new Dictionary <string, int>();



            if (!Config.IsLiteVersion && sheetData.meta.slices?.Length > 0 &&
                (sheetData.meta.frameTags?.Length > 0))
            {
                Debug.LogWarning(
                    "It seems that you have enabled the 'Split slices' option and have animations. This is not well supported and is usually only for static images. No slices will be exported now");
            }


            foreach (var sprite in EnumerateSprites(sheetData))
            {
                //Make sure we prevent import of two assets with the same name
                if (addedObjects.ContainsKey(sprite.name))
                {
                    var newCount = addedObjects[sprite.name] + 1;
                    addedObjects[sprite.name] = newCount;
                    sprite.name = sprite.name + "_" + newCount;
                }
                else
                {
                    addedObjects.Add(sprite.name, 1);
                }

                if (addToContext)
                {
                    AseFileContext.AddObjectToAsset(sprite.name, sprite);
                }

                IndividualSprites.Add(sprite);
            }
        }