Comments (4)
i guess all possibilitie combinations can be covered with 3 bools
uv[index + 0] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
uv[index + 1] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
uv[index + 2] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
uv[index + 3] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
if (rotate)
{
var temp0 = uv[index + 0];
var temp1 = uv[index + 1];
var temp2 = uv[index + 2];
var temp3 = uv[index + 3];
uv[index + 0] = temp2;
uv[index + 1] = temp0;
uv[index + 2] = temp3;
uv[index + 3] = temp1;
}
if (flipH)
{
var temp0 = uv[index + 0];
var temp1 = uv[index + 1];
var temp2 = uv[index + 2];
var temp3 = uv[index + 3];
uv[index + 0] = temp1;
uv[index + 1] = temp0;
uv[index + 2] = temp3;
uv[index + 3] = temp2;
}
if (flipV)
{
var temp0 = uv[index + 0];
var temp1 = uv[index + 1];
var temp2 = uv[index + 2];
var temp3 = uv[index + 3];
uv[index + 0] = temp2;
uv[index + 1] = temp3;
uv[index + 2] = temp0;
uv[index + 3] = temp1;
}
a little simpler at least but prob not optimal
from unitytilemap.
Sorry I missed this. Seems like I'm not getting notification emails.
Is this something you wont to add to TileMeshQuadGridBehaviour.cs
? If so, could you create a pull request for it?
from unitytilemap.
sorry mine has diverged too far from this one
- cannot use the editor with 4096 tiles (102x1024 sheet & 16x16 tiles) because too slow
- everything but quad grid seems useless to me why setPixel when you can not
- passing a sprite in is not really needed... just the texture the rect can be calculated from the id
i did try to make this work with the example in your code but gave up after a while trying to remove sprite parameter and thread all rotatation and flip parameters throgh inheritance
for example to get stairs flipping in showcase
but here is my code for that function if anyone else would like to try or use
public int TextureIndex(Vector2 p)
{
return TextureIndex((int)p.x, (int)p.y);
}
public int TextureIndex(int x, int y)
{
float s = Texture.width / TileSize;
return (y * (int)s) + x;
}
public Vector2 TexturePosition(int index)
{
int s = Texture.width / TileSize;
int y = index / s;
int x = index - (s * y);
return new Vector2(x, y);
}
public void SetTileFlags(int x, int y, bool flipH, bool flipV, bool rotate)
{
SetTile(x, y, GetTile(x, y), flipH, flipV, rotate);
}
public void SetTile(int x, int y, int id, bool flipH = false, bool flipV = false, bool rotate = false)
{
SetTile(TileIndex(x, y), id, flipH, flipV, rotate);
}
public void SetTile(int index, int id, bool flipH = false, bool flipV = false, bool rotate = false)
{
if (id == -1) id = 4096;
_data[index] = id;
var tp = TexturePosition(id);
tp = new Vector2(tp.x * TileSize, tp.y * TileSize);
tp.y = Texture.height - tp.y - TileSize;
var tr = new Rect(tp.x, tp.y, TileSize, TileSize);
var uv = _meshFilter.sharedMesh.uv;
index *= 4;
uv[index + 0] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
uv[index + 1] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
uv[index + 2] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
uv[index + 3] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
if (rotate)
{
var temp0 = uv[index + 0];
var temp1 = uv[index + 1];
var temp2 = uv[index + 2];
var temp3 = uv[index + 3];
uv[index + 0] = temp2;
uv[index + 1] = temp0;
uv[index + 2] = temp3;
uv[index + 3] = temp1;
}
if (flipH)
{
var temp0 = uv[index + 0];
var temp1 = uv[index + 1];
var temp2 = uv[index + 2];
var temp3 = uv[index + 3];
uv[index + 0] = temp1;
uv[index + 1] = temp0;
uv[index + 2] = temp3;
uv[index + 3] = temp2;
}
if (flipV)
{
var temp0 = uv[index + 0];
var temp1 = uv[index + 1];
var temp2 = uv[index + 2];
var temp3 = uv[index + 3];
uv[index + 0] = temp2;
uv[index + 1] = temp3;
uv[index + 2] = temp0;
uv[index + 3] = temp1;
}
_meshFilter.sharedMesh.uv = uv;
}
and here is a simple tile animation system i got working in mine to complete the transition from 2dtoolkit
for example if you had a water or wall torch tile with a couple frames of animation
public void SetAnimation(int index, int[] frames, float fps)
{
StartCoroutine(Animation(index, new int[][] { frames }, fps));
}
public void SetAnimation(int index, int[][] frames, float fps)
{
StartCoroutine(Animation(index, frames, fps));
}
private IEnumerator Animation(int index, int[][] frames, float fps)
{
var time = 1f / fps;
var animationIndex = 0;
var frameIndex = 0;
while (true)
{
if (animationIndex >= frames.Length) animationIndex = 0;
if (frameIndex >= frames[animationIndex].Length)
{
animationIndex = Utility.Random(frames.Length);
frameIndex = 0;
}
SetTile(index, frames[animationIndex][frameIndex]);
frameIndex++;
yield return new WaitForSeconds(time);
}
}
i guess i could add the functions to quad grid but i cannot see how to make Showcase use it
thanks
from unitytilemap.
The editor inside Unity will probably be removed and replaced with Tiled coupled with some kind if importing script. Closing this for now, if someone wants to pick up and continue the work feel free to reopen.
from unitytilemap.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unitytilemap.