2d-extras
2d-extras copied to clipboard
New Feature required
First Question, in my SibblingTile there is a line:
return !other || ((other is SiblingTile));
what does !other mean?
Second Question is about the new feature i want:
the random sprite function needs a new feature.
the sprites is depending on the TileName like
tilemap.GetTile(tile).name = "Door Open";
so if you create a tilemap using script you can assign every tile a name and use a globale RuleTile, it changed depending on the Tile name.
Sry for bad englisch but i hope you understand this.
what does !other mean?
!other checks if other is not null or basically not a Tile (other != null).
so if you create a tilemap using script you can assign every tile a name and use a globale RuleTile, it changed depending on the Tile name.
The name of the Tile will be the same, even though the matching Rule may be different. Perhaps you could try using the name of the Sprite instead?
tilemap.GetSprite(pos).name
Thanks.
tilemap.SetTile(pos, (TileBase)API.FindInResources("Door Open"));
this changes a Tile at position from Door Closed to Door Open (the Sprite changes but the name of the tile is the same so i must do change the name directly like above in my answer).
i think its possible to make it but the idea with the spritename is also good.
can you do this?
Is the name of the Tile the same when you switch the Tile from "Door Closed" to "Door Open"?
I believe you can change the name of the Tile Asset though, which will make identifying them easier.
I have two assets, First the Door Closed Ruletile and second the Door Open RuleTile.
If i change the Tile using my Script it changes only the sprite and rules, but the Name is Not changed and so i have to change the Name to get correct work.
My idea is one Ruletile to create a complette World using Code that changes only the Name of the Tile at a Position and then refresh tilemap
I am not sure that this would work with one RuleTile right now, but using several Tile Assets and tilemap.SetTile(pos, (TileBase)API.FindInResources("Door Open")) by loading different Tile Assets should work.
@superfrantv @ChuanXin-Unity
Can work with one RuleTile but need some small hacking, the key point is use GridInformation to save door opening info and check the info in RuleMatches() not RuleMatch(). And set once DoorOpen or DoorClose rule in anyone neighbor box for a door open/close TilingRule.
public class DoorTile : RuleTile<DoorTile.Rule>
{
public class Rule
{
public const int This = 1;
public const int NotThis = 2;
public const int DoorOpen = 3;
public const int DoorClose = 4;
}
protected override bool RuleMatches(TilingRule rule, Vector3Int position, ITilemap tilemap, ref Matrix4x4 transform)
{
bool isOpenRule = rule.m_Neighbors.Contains(Rule.DoorOpen);
bool isCloseRule = rule.m_Neighbors.Contains(Rule.DoorClose);
if (isOpenRule || isCloseRule)
{
var gridInfo = tilemap.GetComponent<GridInformation>();
bool doorOpen = gridInfo.GetPositionProperty(/* ... */);
if (isOpenRule && !doorOpen)
return false;
else if (isCloseRule && doorOpen)
return false;
}
return base.RuleMatches(rule, position, tilemap, ref transform);
}
}
Yes, you are right! That is certainly possible if you create a new Rule which checks GridInformation!
sry for late answer iam was not at home, I think so, how to do this? And its possible to make a public field of z-Position so every ruletile can have a z-position that never can changed (because the Tile Palette function of z position does reset after reload project) i want to set the z Positions before paint or adding to tile palette.
@superfrantv There has a available DoorTile: https://github.com/johnsoncodehk/rule-tile-extras