Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct transform of exported nodes, change directory path #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Exporter.cs
Corrected atlas region in texture, flipH and flipV in Sprite now match flipX and flipY of Unity SpriteRenderer
  • Loading branch information
pilorenzo authored Sep 22, 2023
commit 0f52e5fb9d5ce22460d0dd3d2424975525bc9a53
18 changes: 12 additions & 6 deletions Exporter/Exporter.cs
Original file line number Diff line number Diff line change
@@ -139,6 +139,7 @@ Node ExtractNodeBranch(GameObject go)
Script script = null;
Dictionary<string, object> scriptVariables = null;


foreach(var cmp in components)
{
Node node = null;
@@ -155,6 +156,8 @@ Node ExtractNodeBranch(GameObject go)
{
dst.texture = Util.Cast<Texture>(ConvertUnityAsset(src.sprite));
rescale2d = src.sprite.pixelsPerUnit;
dst.flipH = src.flipX;
dst.flipV = src.flipY;
}
}
else if(cmp is Rigidbody2D)
@@ -248,22 +251,22 @@ Node ExtractNodeBranch(GameObject go)

node2d.position = go.transform.localPosition * rescale2d;
node2d.position.y *= -1f;
// TODO Invert Y properly
// TODO Select pivot
//node2d.position.y = Screen.height - node2d.position.y;


node2d.scale = go.transform.localScale;
SpriteRenderer goSprite = go.GetComponent<SpriteRenderer>();
if(goSprite)
{
if(goSprite.flipX) node2d.scale.x *= -1f;
if(goSprite.flipY) node2d.scale.y *= -1f;
// if(goSprite.flipX) node2d.scale.x *= -1f;
// if(goSprite.flipY) node2d.scale.y *= -1f;
node2d.zIndex = goSprite.sortingOrder;
}

node2d.rotation = -go.transform.localRotation.eulerAngles.z * Mathf.Deg2Rad;

node2d.visible = go.activeSelf;


rootNode = node2d;
}
else if(rootCategory == NodeCategory.Control)
@@ -317,6 +320,8 @@ Node ExtractNodeBranch(GameObject go)
return rootNode;
}



NodeCategory DetectCategory(Component[] components)
{
int filteredCount = 0;
@@ -440,7 +445,8 @@ Resource ConvertSpriteAsset(UnityEngine.Sprite sprite)
var at = new AtlasTexture();
at.resourcePath = relPath;
at.atlas = atlas;
at.region = sprite.textureRect;
// at.region = sprite.textureRect;
at.region = new Rect(0, 0, sprite.texture.width, sprite.texture.height);

// Invert Y
at.region.y = sprite.texture.height - at.region.y - at.region.height;