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

Customizable RuleTile #37

Closed

Conversation

johnsoncodehk
Copy link
Contributor

@johnsoncodehk johnsoncodehk commented Jun 16, 2018

Code changes after this pull request: #36

This solution can customize RuleTile without writing Editor code.
This solution may need more changes, if you have any ideas welcome to join the discussion.
Issue: #27

Features

  • Inheritable RuleTile
  • Customizable attributes
  • Can expand or rewrite neighbor rules and GUI display
  • Can be used by RuleOverrideTile
  • Template script (Menu: Assets/Create/Custom Rule Tile Script)
  • Neighbor rules tooltip
  • Backward compatible

Usage

  • Custom Attributes:
public class MyTile : RuleTile {
	public string tileId;
	public bool isWater;
}
  • Custom Rules:
public class MyTile : RuleTile<MyTile.Neighbor> {
	public class Neighbor {
		public const int MyRule1 = 0;
		public const int MyRule2 = 1;
	}
	public override bool RuleMatch(int neighbor, TileBase tile) {
		switch (neighbor) {
			case Neighbor.MyRule1: return false;
			case Neighbor.MyRule2: return true;
		}
		return true;
	}
}
  • Expansion Rules
public class MyTile : RuleTile<MyTile.Neighbor> {
	public class Neighbor : RuleTile.TilingRule.Neighbor {
		// 0, 1, 2 is using in RuleTile.TilingRule.Neighbor
		public const int MyRule1 = 3;
		public const int MyRule2 = 4;
	}
	public override bool RuleMatch(int neighbor, TileBase tile) {
		switch (neighbor) {
			case Neighbor.MyRule1: return false;
			case Neighbor.MyRule2: return true;
		}
		return base.RuleMatch(neighbor, tile);
	}
}
  • Siblings Tile 1
public class MyTile : RuleTile<MyTile.Neighbor> {
	public List<TileBase> sibings = new List<TileBase>();
	public class Neighbor : RuleTile.TilingRule.Neighbor {
		public const int Sibing = 3;
	}
	public override bool RuleMatch(int neighbor, TileBase tile) {
		switch (neighbor) {
			case Neighbor.Sibing: return sibings.Contains(tile);
		}
		return base.RuleMatch(neighbor, tile);
	}
}
  • Siblings Tile 2
public class MyTile : RuleTile<MyTile.Neighbor> {
	public int siblingGroup;
	public class Neighbor : RuleTile.TilingRule.Neighbor {
		public const int Sibing = 3;
	}
	public override bool RuleMatch(int neighbor, TileBase tile) {
		MyTile myTile = tile as MyTile;
		switch (neighbor) {
			case Neighbor.Sibing: return myTile && myTile.siblingGroup == siblingGroup;
		}
		return base.RuleMatch(neighbor, tile);
	}
}

@johnsoncodehk johnsoncodehk reopened this Jun 22, 2018
@johnsoncodehk johnsoncodehk deleted the rule-tile-extend branch June 22, 2018 08:40
@johnsoncodehk johnsoncodehk restored the rule-tile-extend branch June 22, 2018 08:52
@johnsoncodehk
Copy link
Contributor Author

johnsoncodehk commented Jun 22, 2018

Closed due to merge conflict, resubmitted pull request:
#38

@johnsoncodehk johnsoncodehk deleted the rule-tile-extend branch October 19, 2019 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant