Tagger


Table of Contents

Introduction        4

The way it works        4

Structure        4

Script        4

Data        4

Some useful information and limitations.        4

Quickstart Guide        4

Manage Groups and Tags        6

Context menu        6

Change the color of the tag        6

Move tag        6

Remove group        6

Remove tag        6

User Interface Overview        7

Overall        7

Preferences Window        7

Show tags in the inspector        7

Show always add button        7

Show group in tags label.        7

Enable order tags alphabetically.        7

Order attached tags alphabetically.        7

Ignore groups.        7

Order the tags alphabetically in groups.        7

Order the groups alphabetically.        7

Scripting        8

Introduction        8

Tag Functions        9

Add tags        9

Get tags        9

Has tags        9

Has any tags        9

Remove tags        10

Set tags        10

Search Functions        11

Simple search        11

Modes        11

And        11

Example:        11

Or        11

Example:        11

Not        11

Example:        11

String search        12

Advanced search        13

Step 1 - Create Classes        13

Step 2 – Setup search logic        14

Step 3 – Search        14

TaggerFilter class        15

Include        15

Exclude        15

Matching        15

TaggerIdAttribute        15

Support        15

by Email        15

by Forum        15


Introduction

Thank you for the purchase of Tagger. 

Probably, you have found Tagger, because you have the same problem as me. 

You want more than just one tag on a GameObject. Besides, you want to search for GameObject with specific tags. Moreover, you want the search being performant. Now, here comes the Solution: Tagger.

Multi-Tagging, Group of Tags, Fast, Easy to use, Efficiency.

The way it works

  1. Structure

  1. Script

GameObject has its Monobehavior attached aka TaggerScript.

The Script holds only one thing: The Identification Number of your attached tags to this GameObject.

  1. Data

In your Projects lays a ScriptableObject aka TaggerData.

The TaggerData store the logical connections (also which ID has which tags).

  1. Some useful information and limitations.

You can not use the same tag name in different groups. Groups are only a help for you to organize your tags. Technically, groups don’t affect the Tagger-System. You can search with groups, but you can not have like “Size.A” and “Level.A” because both tags are not “Size.A” and “Level.A”, they are “A” and “A”.


Quickstart Guide

  1. Of course, first, import the Tagger from the Asset Store.
  2. Add the Tagger Script Component (The Tag GameObject Inspector is currently unavailable due to a bug The normal Component Inspector of Tagger Script must be used. )
    Create a new GameObject and click on the small + button between Transform and HeaderC:\Users\Heia Samahi\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Unbenannt.png
  3. You can now add groups and tags to the tagger system. Now you can click on tags to add these tags to the current GameObject. Only tags that have not already been added to the GameObject are visible here. C:\Users\Heia Samahi\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Unbenannt.png
  4. You have now added a bunch of tags to the GameObject. This also works on prefabs. C:\Users\Heia Samahi\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Unbenannt.png
  5. The GameObject is now findable under the selected tags. To find this GameObject, you can use the method TaggerSystem.FindGameObjectsWithTags(TaggerSearchMode mode, params string[] tag). The method returns a HashSet<GameObject> with the result. For advanced searches use the class TaggerAdvancedSearch.

Manage Groups and Tags

  1. Context menu

To open the context menu, click right on a tag or group. In the context menu, it is possible to move the tag in another group, change the color of the tag or delete it, as well to rename tags and groups.

  1. Change the color of the tag

You can change the color of a tag in the context menu or by script.

  1. Move tag

You can move a tag to another group. This can be done by script or in the context menu.

  1. Remove group

If you remove a group, you can choose between deleting its tags or move the tags to ungrouped. This can be done by script or in the context menu.

  1. Remove tag

All Prefabs and Scene objects lose this tag. Moreover, even you add this tag later, it will not return. This can be done by script or in the context menu.


User Interface Overview

  1. Overall

There is not much to say. At least that is what I hope. If you have any questions, please do not hesitate to contact me! However, here are a few small tips that may not be directly apparent.

  • Right-clicking on a label opens a small menu to change the group or color.
  • You can disable the top menu of Tagger in the GameObject inspector in the preferences. (Currently unavailable)
  • You can turn off the “Group.” prefix of the label in the preferences.
  1. Preferences Window

In the preferences window in Unity, you find the “Tagger” tab.

  1. Show tags in the inspector

This setting shows you the tags bar in the GameObject inspector. Note: If other assets use a customs inspector for GameObjects, this might be overridden or override other assets inspectors. (The Tag GameObject Inspector is currently unavailable due to a bug The normal Component Inspector of Tagger Script must be used. )

  1. Show always add button

Always show the tagger menu, even there is no tagger script assigned. It does this automatically if you add a tag over the add menu.

  1. Show group in tags label.

This setting shows the group prefix in tags on GameObjects. Like: Group.Tag

  1. Enable order tags alphabetically.

This setting enables the ordering of tags and groups. Customizable with the following settings. This setting only affects visual and does not change the data order in the lists and arrays.

  1. Order attached tags alphabetically.

This setting orders the tags that are attached to the GameObjects alphabetically.

  1.                 Ignore groups.

Ignore groups when ordering the tags on GameObjects.

  1.         Order the tags alphabetically in groups.

As the title says, order the tags alphabetically in groups.

  1.          Order the groups alphabetically.

As the title says, order groups alphabetically.


Scripting

  1. Introduction

First of all, read this note:

DO NOT USE METHOD / FIELDS WITH INTERNAL PREFIX!

IT COULD BREAK THE TAGGERSYSTEM.

It is that easy.

Second, the source code has been thoroughly documented. If something is not understandable, please get in touch with me.

You can access the Tagger over the static class TaggerSystem.

Here you find all functions of the Tagger. For data specific method access the current TaggerData over the TaggerSystem.Data property.

The TaggerSystem class is used to search and manage tags of GameObjects.

The TaggerData class is used to store all tag information. Tags, Groups, Color, IDs.

You possibly can have multiple TaggerData. However, it is not recommended because of the IDs. If you use the wrong TaggerData to identify prefabs they are created with another TaggerData, it is possible to mess up the IDs of the instanced prefabs and you probably will not find it with the search because their IDs pointed to other tags as you expected.

The ITaggerDataLoader interface is used to create a custom Tagger data loader. The TaggerDataLoaderDefault cannot be used to save at runtime. It only loads the in-editor time created TaggerData.  If you want to use your own custom Tagger data loader, just implement the interface ITaggerDataLoader to your class and set the property TaggerSystem.DataLoader. Don’t forget to do this in editor time too. So make sure that your runtime save & load system is compatible with the editor time changes.

The link helps you to run code in editor time.

https://docs.unity3d.com/Manual/RunningEditorCodeOnLaunch.html


  1. Tag Functions

  2. The following methods are accessible on every GameObject
  3. Add tags

  4. Adds a tag to a GameObject.
  5. void AddTag(string tag)
  6. void AddTag(params string[] tags) //New in v1.5.1
  7. Add the tags of a group to the GameObject.
  8. void AddTagsOfGroup(this GameObject gameObject, string group) //New in v1.7
  9. void AddTagsOfGroup(this GameObject gameObject, TaggerGroup group) //New in v1.7
  10. Get tags

  11. Get all tags on a GameObject
  12. HashSet<string> GetTags(this GameObject gameObject)
  13. Has tags

  14. Checks if a tag is present on a GameObject
  15. bool HasTag(string tag)
  16. Checks if all tags is present on a GameObject
  17. bool HasTag(params string[] tag) //New in v1.5.1
  18. Checks if all tags of a group are present on a GameObject
  19. bool HasTagsOfGroup(this GameObject gameObject, string group) //New in v1.7
  20. bool HasTagsOfGroup(this GameObject gameObject, TaggerGroup group) //New in v1.7
  21. Has any tags

  22. Checks if any tag is present on a GameObject
  23. bool HasAnyTag(params string[] tag) //New in v1.5.1
  24. Checks if any tags of a group are present on a GameObject
  25. bool HasAnyTagsOfGroup(this GameObject gameObject, string group) //New in v1.7
  26. bool HasAnyTagsOfGroup(this GameObject gameObject, TaggerGroup group) //New in v1.7

  1. Remove tags

  2. Remove one or more tags from a GameObject.
  3. void RemoveTag(string tag)
  4. void RemoveTag(params string[] tags) //New in v1.5.1
  5. Remove all tags of a group from a GameObject.
  6. void RemoveAllTagsOfGroup(this GameObject gameObject, string group) //New in v1.7
  7. void RemoveAllTagsOfGroup(this GameObject gameObject, TaggerGroup group)//New in v1.7
  8. Set tags

  9. This replaces the tags on the GameObject.
  10. void SetTag(string tag)
  11. void SetTag(params string[] tags)//New in v1.5.1
  12. This replaces the tags on the GameObject with the tags of a group.
  13. void SetTagsOfGroup(this GameObject gameObject, string group) //New in v1.7
  14. void SetTagsOfGroup(this GameObject gameObject, TaggerGroup group) //New in v1.7


  1. Search Functions

  1. Simple search

Over the following methods found in the static class TaggerSystem….

GameObject FindGameObjectWithTag(string tag)

HashSet<GameObject> FindGameObjectsWithTag(string tag)

HashSet<GameObject> FindGameObjectsWithTags(TaggerSearchMode mode, params string[] tag)

…it’s possible to search for tagged GameObjects in a simple way.

  1. Modes

Example tags used in follow scenarios: Blue, Big, Cube

  1. And

The mode and means, the searched GameObjects needs every specified tag.

  1. Example:

Returns only GameObjects which have the tags Blue AND Big AND Cube.

  1. Or

The mode or means, the searched GameObjects must have at least one of the specified tags.

  1. Example:

Returns only GameObjects which have the tags Blue OR Big OR Cube OR combination of these tags.

  1. Not

The mode not means, the searched GameObjects may not have the specified tags.

  1. Example:

Returns Only GameObjects which have NOT the tags Blue OR Big OR Cube OR combination of these tags.


String search

The following method is the easy one of the complex searches.

You enter a pattern, and this method creates for you the TaggerAdvancedSearch.

You must follow a couple of rules:

  1. Your pattern must start with a tag.
  2. Your pattern must end with a tag.
  3. Use multiple tags with “,” (comma)
  4. Every new operator makes an invisible bracket. (Lock at the example below)

Valid Pattern:

TAG OPERATOR TAG

TAG, TAG OPERATOR TAG OPERATOR TAG

Now with infill…

Red & Blue | Cube

You also can use brackets for clarity, but the logic ignores the brackets.

(Red & (Blue | Cube))


  1. Advanced search

I am strongly recommended to view the example file: Plugins\HeiKyu\Tagger\Examples\AdvancedSearchExample.cs

The following is just an additional explanation for the example file.

With the class TaggerAdvancedSearch, you can do complex searches. However, there is a current existing limitation. Every TaggerAdvancedSearch can only have one child search. Through this, you can only create a nested search instead of multiple logic.

For clearance, an example:

As a programmer, you write in logic

A & B & C …  or … A | B & C … or …  A & (B | C ) & D

The last one is not directly possible. Because A cannot have AND (B | C) AND D. You must reorder the logic to A & D & (B | C). If you have trouble to understand this, follow the simple rule:

Every logic has its brackets!

(A & (D & (B | C)))

For the other examples:

(A & (B & C))

(A | (B & C))

I hope this makes this a little bit better to understand this currently existing limitation.

  1. Step 1 - Create Classes

You can either start with one created class for every command like this:

TaggerAdvancedSearch red = new TaggerAdvancedSearch();

TaggerAdvancedSearch small = new TaggerAdvancedSearch();

TaggerAdvancedSearch large = new TaggerAdvancedSearch();

TaggerAdvancedSearch blue = new TaggerAdvancedSearch();

red.SetTags("Red");

small.SetTags("Small");

large.SetTags("Large");

blue.SetTags("Blue");

Or you can start with only one class and work with these. On the first class you set the first tag.

TaggerAdvancedSearch search = new TaggerAdvancedSearch();

search.SetTags("Red");

In the constructor of the TaggerAdvancedSearch you can set if the first tag as include (also and) or excluded (also not) work.


  1. Step 2 – Setup search logic

You can choose between different ways to build up your logic.

(red & (small | large & blue));

red.And(small.Or(large.And(blue)));

Or when you choose to work with only one class…

search.And("Small").Or("Large").And("Blue");

If you want, then call void Research();

This complete internal processing. The method is automatically called if it needed by the Tagger itself.

If you change the search or create/delete/move tags or groups the search, it becomes dirty, and it calls this method self.

The only reason why this method is public is, you can save a couple of milliseconds before the actual search started.

  1. Step 3 – Search

Now you have built up a search that can search as many you need.

Now you can call the method HashSet<GameObject> MatchedGameObjects(). This will search for the GameObjects returns them.

The search is designed to be as fast as possible. “Just” a dictionary access and list accumulation.

Every time you call this method, it returns the current registered tagger GameObjects by the TaggerManager.


  1. TaggerFilter class

TaggerFilter makes it possible to define a set of tags via the inspector (or via C# API) and then to query via a method whether a GameObject matches this set of tags.

  1. Include

  2. Specify which tags the GameObject must have.
  1. Exclude

  2. Specify which tags the GameObject must not have.
  1. Matching

  2. The matching method returns true if the GameObject matches the filter. If no tags are specified in the filter, this method returns true.

TaggerIdAttribute

Decorate any serialized field with this attribute to make a list of tags that can be edited from the inspector. This TagId can then be used further with the TaggerSystem.

Support

  1. by Email

support@heikyu.com

  1. by Forum

If there is a need for a community, it will be added in the future. Currently not planned but in mind.

Online Documentation - always new - Version 1.7