Пример #1
0
        public void EndFileVisit(AseFile file)
        {
            BuildAnimations();

            var renderer = m_GameObject.AddComponent <SpriteRenderer>();

            renderer.sprite           = m_Sprites[0];
            renderer.sortingLayerName = m_SortingLayerName;
            renderer.sortingOrder     = m_SortingOrder;

            var animator = m_GameObject.AddComponent <Animator>();

            animator.runtimeAnimatorController = m_AnimatorController;
            animator.cullingMode = m_AnimatorCullingMode;

            m_AseFile = null;
            m_Context = null;
            m_Palette.Clear();
            m_Layers.Clear();
            m_Frames.Clear();
            m_Sprites.Clear();
            m_Clips.Clear();
            m_AseFrameTagsChunk = null;
            m_UniqueNameifier.Clear();
            m_GameObject = null;
        }
Пример #2
0
        public void EndFileVisit(AseFile file)
        {
            // Add sprites to sprite atlas (or more correctly, add the scritable object that will add the sprites when import completes)
            var spriteAtlasUser = SpriteAtlasUserAsset.CreateSpriteAtlasUserAsset(m_SpriteAtlas);

            m_Context.AddObjectToAsset("__atlas", spriteAtlasUser);

            BuildAnimations();

            var renderer = m_GameObject.AddComponent <SpriteRenderer>();

            renderer.sprite           = m_Sprites[0];
            renderer.sortingLayerName = m_SortingLayerName;
            renderer.sortingOrder     = m_SortingOrder;

            var animator = m_GameObject.AddComponent <Animator>();

            animator.runtimeAnimatorController = m_AnimatorController;
            animator.cullingMode = m_AnimatorCullingMode;

            m_AseFile = null;
            m_Context = null;
            m_Palette.Clear();
            m_Layers.Clear();
            m_Frames.Clear();
            m_Sprites.Clear();
            m_Clips.Clear();
            m_AseFrameTagsChunk = null;
            m_UniqueNameifier.Clear();
            m_GameObject = null;
        }
Пример #3
0
        public AseFrame(AseFile file, AseReader reader)
        {
            AseFile = file;

            NumBytesInFrame = reader.ReadDWORD();
            MagicNumber     = reader.ReadWORD();
            NumChunks       = reader.ReadWORD();
            FrameDurationMs = reader.ReadWORD();

            // Ingore next two bytes
            reader.ReadBYTEs(2);

            // Later versions of Aseprite may overwrite our number of chunks
            var nchunks = reader.ReadDWORD();

            if (NumChunks == 0xFFFF && NumChunks < nchunks)
            {
                NumChunks = nchunks;
            }

            // Read in old and new chunks
            Chunks = Enumerable.Repeat <AseChunk>(null, (int)NumChunks).ToList();
            for (int i = 0; i < NumChunks; i++)
            {
                Chunks[i] = ReadChunk(reader);
            }

            Debug.Assert(MagicNumber == 0xF1FA);
        }
Пример #4
0
        public void BeginFileVisit(AseFile file)
        {
            m_AseFile = file;
            m_Pivot   = null;

            // Start off with a an empty 256 palette
            m_Palette = Enumerable.Repeat(m_TransparentColor, 256).ToList();

            // Create the array of clear pixels we'll use to begin each frame
            m_ClearPixels = Enumerable.Repeat(Color.clear, m_AseFile.Header.Width * m_AseFile.Header.Height).ToArray();

            var icon = AssetDatabaseEx.LoadFirstAssetByFilter <Texture2D>("aseprite2unity-icon-0x1badd00d");

            m_GameObject = new GameObject(Path.GetFileNameWithoutExtension(assetPath));
            m_Context.AddObjectToAsset("_main", m_GameObject, icon);
            m_Context.SetMainObject(m_GameObject);
        }
Пример #5
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            m_Errors.Clear();

#if UNITY_2018_1_OR_NEWER
            m_Context = ctx;

            using (var reader = new AseReader(ctx.assetPath))
            {
                m_AseFile = new AseFile(reader);
                m_AseFile.VisitContents(this);
            }
#else
            string msg = string.Format("Aesprite2Unity requires Unity 2018.3 or later. You are using {0}", Application.unityVersion);
            m_Errors.Add(msg);
            Debug.LogError(msg);
#endif
        }