Skip to content

Commit

Permalink
add support for animated sprite atlas to be swapped
Browse files Browse the repository at this point in the history
  • Loading branch information
PrashantMohta committed Jun 5, 2022
1 parent 4d04b60 commit ee13a7b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CustomKnight/Skin/Base/SkinManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static class SkinManager{
{SimpleKey.Name,new SimpleKey() },
{"Map",new MAQ("Inventory/Map") },
{"Quill",new MAQ("Inventory/Quill") },
{"MaQ",new MAQ("Inventory/MaQ") },
{"MapQuill",new MAQ("Inventory/MapQuill") },
{RelicBG.Name,new RelicBG() },
{SpellBG.Name,new SpellBG() },
// {"PinsScarab", new Pins()}
Expand Down
4 changes: 2 additions & 2 deletions CustomKnight/Skin/Base/Skinable/MAQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override void SaveDefaultTexture()
case "Inventory/Quill":
ckTex.defaultSprite = eqfsm.GetAction<SetSpriteRendererSprite>("Quill", 1).sprite.Value as Sprite;
break;
case "Inventory/MaQ":
case "Inventory/MapQuill":
ckTex.defaultSprite = eqfsm.GetAction<SetSpriteRendererSprite>("Map and Quill", 1).sprite.Value as Sprite;
break;
default:
Expand All @@ -37,7 +37,7 @@ public override void ApplySprite(Sprite sprite)
case "Inventory/Quill":
eqfsm.GetAction<SetSpriteRendererSprite>("Quill", 1).sprite.Value = sprite;
break;
case "Inventory/MaQ":
case "Inventory/MapQuill":
eqfsm.GetAction<SetSpriteRendererSprite>("Map and Quill", 1).sprite.Value = sprite;
break;
default:
Expand Down
2 changes: 2 additions & 0 deletions CustomKnight/Skin/Swapper/DumpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ internal void dumpSpriteForGo(Scene scene,GameObject go){
// remove the animation component
//GameObject.Destroy(anim);
//go.AddComponent<Animator>();
var tex = sr.sprite.texture;
SaveTextureDump(scene,name, tex);
return;
}
SaveSpriteDump(scene,name, sr.sprite);
Expand Down
14 changes: 14 additions & 0 deletions CustomKnight/Skin/Swapper/SpriteRendererMaterialPropertyBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace CustomKnight{
public class SpriteRendererMaterialPropertyBlock : MonoBehaviour {
public MaterialPropertyBlock mpb;
public SpriteRenderer sr;
public void Update(){
if(sr == null){
sr = GetComponent<SpriteRenderer>();
}
if(mpb != null){
sr.SetPropertyBlock(mpb);
}
}
}
}
9 changes: 7 additions & 2 deletions CustomKnight/Skin/Swapper/SwapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,22 @@ private void SwapSkinForGo(string objectPath,GameObject GO){
} else {
if(anim != null){
//maybe animated things can be replaced with a single sprite
CustomKnight.Instance.Log($"Animation : {anim.name}");
CustomKnight.Instance.Log($"Animation : {anim.name}");
var behaviour = GO.GetAddComponent<SpriteRendererMaterialPropertyBlock>();
MaterialPropertyBlock block = new MaterialPropertyBlock();
block.AddTexture("_MainTex",tex);
behaviour.mpb = block;
//GameObject.Destroy(anim);
//go.AddComponent<Animator>();
// destroyed the animation, possibly add satchel customAnimation later
}
} else {
//currentSkinnedSceneObjs.Add(objectPath); re add sprites for a while
//some sprites are still not perfectly matched
CustomKnight.Instance.Log($"game object : {sr.name} ");
var pivot = new Vector2(0.5f, 0.5f); // this needs offset sometimes
sr.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), pivot ,sr.sprite.pixelsPerUnit);
//Log($"pivot post application {sr.sprite.pivot/new Vector2(tex.width, tex.height)}");
}
}

} else {
Expand Down

0 comments on commit ee13a7b

Please sign in to comment.