HonorLee 1 年之前
父节点
当前提交
f18f74b568
共有 3 个文件被更改,包括 16 次插入11 次删除
  1. 8 7
      CGTool/Anime.cs
  2. 5 4
      CGTool/AnimePlayer.cs
  3. 3 0
      README.md

+ 8 - 7
CGTool/Anime.cs

@@ -52,7 +52,7 @@ namespace CGTool
         //GraphicInfo;
         public GraphicInfoData GraphicInfo;
         //动画Sprite
-        public Sprite AnimeSprite;
+        public Dictionary<int,Sprite> AnimeSprites = new Dictionary<int, Sprite>();
     }
 
     //动画数据
@@ -64,7 +64,8 @@ namespace CGTool
         public int ActionType;
         public uint CycleTime;
         public uint FrameCount;
-        public Texture2D AnimeTexture;
+        public Dictionary<int,Texture2D> AnimeTextures = new Dictionary<int, Texture2D>();
+        // public Texture2D AnimeTexture;
         public AnimeFrameInfo[] AnimeFrameInfos;
         // public byte[] unknown;
     }
@@ -218,9 +219,9 @@ namespace CGTool
         }
 
         //预处理动画图形合批烘焙
-        public static void BakeAnimeFrames(AnimeDetail animeDetail)
+        public static void BakeAnimeFrames(AnimeDetail animeDetail,int paletIndex = 0)
         {
-            if(animeDetail.AnimeTexture != null) return;
+            if(animeDetail.AnimeTextures.ContainsKey(paletIndex)) return;
             //所有帧的图形数据
             GraphicData[] graphicDatas = new GraphicData[animeDetail.FrameCount];
             
@@ -234,7 +235,7 @@ namespace CGTool
                 //载入图档
                 GraphicInfoData graphicInfoData = GraphicInfo.GetGraphicInfoDataByIndex(animeDetail.Version,animeDetail.AnimeFrameInfos[i].GraphicIndex);
                 if (graphicInfoData == null) continue;
-                GraphicData graphicData = Graphic.GetGraphicData(graphicInfoData);
+                GraphicData graphicData = Graphic.GetGraphicData(graphicInfoData, paletIndex);
                 if(graphicData == null) continue;
                 graphicDatas[i] = graphicData;
                 if(graphicData.Height > textureHeight) textureHeight = graphicData.Height;
@@ -267,7 +268,7 @@ namespace CGTool
             }
             texture2dMix.Apply();
             
-            animeDetail.AnimeTexture = texture2dMix;
+            animeDetail.AnimeTextures.Add(paletIndex,texture2dMix);
             
             //创建动画每帧Sprite
             offsetX = 0;
@@ -282,7 +283,7 @@ namespace CGTool
                         animeDetail.AnimeFrameInfos[l].Width, animeDetail.AnimeFrameInfos[l].Height),
                     pivot, 1, 1, SpriteMeshType.FullRect);
                 offsetX += animeDetail.AnimeFrameInfos[l].Width;
-                animeFrameInfo.AnimeSprite = sprite;
+                animeFrameInfo.AnimeSprites.Add(paletIndex, sprite);
             }
             
         }

+ 5 - 4
CGTool/AnimePlayer.cs

@@ -127,7 +127,7 @@ namespace CGTool
             _spriteRenderer = GetComponent<SpriteRenderer>();
             _rectTransform = GetComponent<RectTransform>();
             //碰撞盒,仅当需要添加鼠标事件时使用
-            _boxCollider2D = GetComponent<BoxCollider2D>();
+            // _boxCollider2D = GetComponent<BoxCollider2D>();
             
             if(_imageRenderer == null) _imageRenderer = gameObject.AddComponent<Image>();
             if(_spriteRenderer == null) _spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
@@ -315,16 +315,17 @@ namespace CGTool
 
             if (isFrameBatch)
             {
-                Anime.BakeAnimeFrames(animeOption.AnimeDetail);
+                Anime.BakeAnimeFrames(animeOption.AnimeDetail, _paletIndex);
                 //获取动画帧数据
                 for (int i = 0; i < animeOption.AnimeDetail.AnimeFrameInfos.Length; i++)
                 {
-                    if(animeOption.AnimeDetail.AnimeFrameInfos[i].AnimeSprite == null) continue;
+                    if(!animeOption.AnimeDetail.AnimeFrameInfos[i].AnimeSprites.ContainsKey(_paletIndex)) continue;
+                    if(animeOption.AnimeDetail.AnimeFrameInfos[i].AnimeSprites[_paletIndex] == null) continue;
                     //创建帧数据
                     frames[i] = new AnimeFrame();
                     frames[i].Index = i;
                     frames[i].GraphicInfo = animeOption.AnimeDetail.AnimeFrameInfos[i].GraphicInfo;
-                    frames[i].Sprite = animeOption.AnimeDetail.AnimeFrameInfos[i].AnimeSprite;
+                    frames[i].Sprite = animeOption.AnimeDetail.AnimeFrameInfos[i].AnimeSprites[_paletIndex];
                     frames[i].AnimeFrameInfo = animeOption.AnimeDetail.AnimeFrameInfos[i];
                 }
             }

+ 3 - 0
README.md

@@ -221,6 +221,9 @@ player.Stop();
 
 
 ## 4、更新日志
+### v 1.5
+> `UPD` Anime序列帧合批忘了考虑不同调色板的问题,现已增加相关处理
+
 ### v 1.4
 > `ADD` 加入Anime序列帧合批,挂载AnimePlayer后可手动设置是否开启合批(建议开启)