Rule タイルのカスタムルール
寄稿者: johnsoncodehk
このテンプレートスクリプトは、Rule タイルの デフォルトオプション (This および Not This) とは異なるマッチングオプションを含む新しいカスタム製の Rule タイル を作成する場合に使用します。これにより、カスタム Rule タイル の Rule ごとに選択可能なオプションが作成されます。
テンプレートの特徴
- 継承可能な Rule タイル。
- カスタマイズ可能なプロパティ。
- 隣接の Rule タイルとそのタイルの GUI 表示、両方の拡張または書き換え。
- RuleOverrideTile で使用可能。
- テンプレートスクリプトから作成。
- 隣接 Rule のツールチップ。
- 後方互換性。
カスタム Rule タイルスクリプトの作成
カスタム Rule タイルスクリプトを作成するには、Assets > Create > Custom Rule Tile Script の順に選択します。プロンプトが表示されたら、新しく作成されたファイルに名前を付けます。ファイルの作成後、ファイルを編集して、マッチングをテストするための新しいマッチングオプションやカスタムアルゴリズムを追加できます。
例
- カスタムプロパティ
public class MyTile : RuleTile {
public string tileId;
public bool isWater;
}
- カスタムルール
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;
}
}
- 拡張ルール
public class MyTile : RuleTile<MyTile.Neighbor> {
public class Neighbor : RuleTile.TilingRule.Neighbor {
// 0、1、2 は 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);
}
}
- 兄弟タイル 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);
}
}
- 兄弟タイル 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);
}
}