Unity-Technologies / 2d-extras

Fun 2D Stuff that we'd like to share!
Other
1.54k stars 342 forks source link

CustomRule? #144

Open superfrantv opened 4 years ago

superfrantv commented 4 years ago

Hallo, seit dem neuen Update geht bei mir gar nichts mehr.. die Regeln spinnen total rum, es rotiert die Tiles nicht mehr richtig und vieles mehr.

Ich möchte meinen eigenen Script der prüft wenn das aktuelle Tile neben einen speziellen ist, dann soll es anders Aussehen, wie nutze ich RuleMatch ohne ints sondern mit Sprites?

johnsoncodehk commented 4 years ago

Originally posted by @superfrantv in https://github.com/Unity-Technologies/2d-extras/issues/141#issuecomment-547098268

Continue to follow up on your issue here. Sorry, I don't understand your situation. Can you provide some screenshots or send Tile assets to me?

superfrantv commented 4 years ago

Screenshot (91)

I want a "RoomTile" with a Wall that is 3 Tiles (High/Big) and in the Middle a Ground (as Basic Sprite from Wall 1). Aditional there should be Doors and Windows (4x4 Tiles or 2x6 tiles) but they can be as they own.

johnsoncodehk commented 4 years ago

Sorry if I understand what you mean wrong. If you want to merge first, second, third walls into a single tile, you need a rule setting greater than 3x3. This feature is supported in https://github.com/Unity-Technologies/2d-extras/pull/140. Since it has not been merged, you currently need to change git url to my branch to use.

"com.unity.2d.tilemap.extras": "https://github.com/johnsoncodehk/2d-extras.git#rule-tile-5x5",
superfrantv commented 4 years ago

@johnsoncodehk

i changed my manifest.json under Packages Folder and changed the link but it does nothing? Where can i use the 5x5?

johnsoncodehk commented 4 years ago

Rule list Is there a Extend Neighbor toggle?

superfrantv commented 4 years ago

Rule list Is there a Extend Neighbor toggle?

No should i restart my unity project or add both Links?

johnsoncodehk commented 4 years ago

No you don't need. Please show me your Packages/manifest.json file.

superfrantv commented 4 years ago

@johnsoncodehk

{ "dependencies": { "com.unity.2d.sprite": "1.0.0", "com.unity.2d.tilemap": "1.0.0", "com.unity.2d.tilemap.extras": "https://github.com/johnsoncodehk/2d-extras.git#rule-tile-5x5", "com.unity.ads": "2.0.8", "com.unity.analytics": "3.3.2", "com.unity.ide.vscode": "1.1.2", "com.unity.package-manager-ui": "2.2.0", "com.unity.postprocessing": "2.1.7", "com.unity.purchasing": "2.0.6", "com.unity.ugui": "1.0.0", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", "com.unity.modules.assetbundle": "1.0.0", "com.unity.modules.audio": "1.0.0", "com.unity.modules.cloth": "1.0.0", "com.unity.modules.director": "1.0.0", "com.unity.modules.imageconversion": "1.0.0", "com.unity.modules.imgui": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0", "com.unity.modules.particlesystem": "1.0.0", "com.unity.modules.physics": "1.0.0", "com.unity.modules.physics2d": "1.0.0", "com.unity.modules.screencapture": "1.0.0", "com.unity.modules.terrain": "1.0.0", "com.unity.modules.terrainphysics": "1.0.0", "com.unity.modules.tilemap": "1.0.0", "com.unity.modules.ui": "1.0.0", "com.unity.modules.uielements": "1.0.0", "com.unity.modules.umbra": "1.0.0", "com.unity.modules.unityanalytics": "1.0.0", "com.unity.modules.unitywebrequest": "1.0.0", "com.unity.modules.unitywebrequestassetbundle": "1.0.0", "com.unity.modules.unitywebrequestaudio": "1.0.0", "com.unity.modules.unitywebrequesttexture": "1.0.0", "com.unity.modules.unitywebrequestwww": "1.0.0", "com.unity.modules.vehicles": "1.0.0", "com.unity.modules.video": "1.0.0", "com.unity.modules.vr": "1.0.0", "com.unity.modules.wind": "1.0.0", "com.unity.modules.xr": "1.0.0" } }

johnsoncodehk commented 4 years ago

No lock attribute? If there is, you should delete it. Also try to delete your Library folder.

superfrantv commented 4 years ago

What do you mean with Lock attribute?

if i delete my library folder some settings will be lost?

johnsoncodehk commented 4 years ago

I tried the above two points without affecting. Try doing this:

  1. Delete the "com.unity.2d.tilemap.extras": /* ... */ line.
  2. Switch to Unity, and the PackageManager will reload.
  3. Make sure the 2d-extras package is removed
  4. Add "com.unity.2d.tilemap.extras": /* ... */ line again.
johnsoncodehk commented 4 years ago

I may have misunderstood. Do you want to use 3 RuleOverrideTiles instead of merging into one RuleTile? For the SiblingTile, SiblingGroup will appear in RuleOverrideTile. Different SiblingGroup is equivalent to OverrideSelf enable. Same SiblingGroup is equivalent to OverrideSelf disable.

superfrantv commented 4 years ago

i deleted the library folder, not working, in my packages folder there is a folder named: "com.unity.2d.tilemap.extras" with the master files i downloaded here.

and a manifest.json with the line included, if i delete the line and reload the packagemanager, nothing changed.

So the package things not working right (typical unity things), how can i manual include the 5x5, which scripts i must change?

johnsoncodehk commented 4 years ago

You need to change these scripts: https://github.com/Unity-Technologies/2d-extras/pull/140/files?file-filters%5B%5D=

And click this button to view the file. image

superfrantv commented 4 years ago

Screenshot (92)

Updated Manual worked like a charm. but i don't know how i should setup my rules.

in the picture you see the red marked things, this is not rotated right (but why is it only on the left and bottom side) all other works but the rotation works not.

blue sprites are Tile 1 (RuleTile) and green sprites are Tile 2 (RuleOverrideTile from Tile 1 with same rules).

superfrantv commented 4 years ago

If you want to reproduce it you need 7 sprites And 1 rule Tile with my settings on picture and one ruleoverridetile where the rule Tile is the Base and only other Sprites are assign.

1 ground sprite (middle) 2 differend Wall Sprites and 2 differend inside and outside Sprites.

I dont know about hangouts

superfrantv commented 4 years ago

The Problem is on the RuleMatch Function:

now: if any other tile is on the side where a green arrow rule is -> true or 1

before the new changes:

if any other tile is on the side where a green arrow rule is -> false or 0

i think this is it, but how to change it?

please reproduce (shown on my picture there are the rule setup with your 5x5 rule tile), simple create 2 rule tiles with the same setup and place the first one in the middle (6x6 fields) and the second one arround the first one.

can this be changed from any project settings?

johnsoncodehk commented 4 years ago
public class CustomTile : RuleTile<CustomTile.Neighbor>
{

    public class Neighbor : TilingRule.Neighbor
    {
        public const int OtherTile = 3;
        public const int WallOrNoting = 4;
    }

    public bool isWall;

    public override bool RuleMatch(int neighbor, TileBase other)
    {
        if (other is RuleOverrideTile)
            other = (other as RuleOverrideTile).m_InstanceTile;

        switch (neighbor)
        {
            case Neighbor.OtherTile:
                return other != this && other != null;
            case Neighbor.WallOrNoting:
                return !other || ((other is CustomTile) && (other as CustomTile).isWall);
        }

        return base.RuleMatch(neighbor, other);
    }
}

image image image

superfrantv commented 4 years ago

Thank You very very much, thats Do it :)