Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.

Commit 48ae313

Browse files
committed
added IsGameObjectTaggedWith
1 parent e972a25 commit 48ae313

7 files changed

Lines changed: 383 additions & 24 deletions

File tree

Assets/MultiTagSystem/Editor/MultiTagEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class MultiTagEditor : Editor
1515
private void OnEnable()
1616
{
1717
UnityTags = InternalEditorUtility.tags;
18-
TagsProp = serializedObject.FindProperty("_tags");
18+
TagsProp = serializedObject.FindProperty("_Tags");
1919
List = new ReorderableList(serializedObject, TagsProp, true, true, true, true);
2020
List.drawHeaderCallback += DrawHeader;
2121
List.drawElementCallback += DrawElement;

Assets/MultiTagSystem/MultiTag.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using UnityEngine;
33
using System.Linq;
4+
using System.ComponentModel;
45

56
namespace MultiTagSystem
67
{
@@ -33,7 +34,7 @@ public static void RebuildDict()
3334
/// <summary>
3435
/// Don't call this unless you know what you're doing.
3536
/// <para>This does not update the current state of the MultiTagComponent.</para>
36-
/// <para>It's best to add a tag from a gameobject's MultiTagComponent.</para>
37+
/// <para>It's best to add multiple tags from a gameobject's MultiTagComponent.</para>
3738
/// </summary>
3839
/// <param name="tags"></param>
3940
/// <param name="gameObject"></param>
@@ -211,7 +212,7 @@ private static List<GameObject> RunQuery(MultiTagFilter multiTagFilter)
211212
/// Gets the list from a key
212213
/// </summary>
213214
/// <param name="tag">Tag</param>
214-
/// <returns>Shallow copy of List. null if false<GameObject></returns>
215+
/// <returns>Shallow copy of List. Null if false</returns>
215216
public static List<GameObject> GetList(string tag)
216217
{
217218
return MtDict.ContainsKey(tag) ? MtDict[tag].ToList() : null;
@@ -231,10 +232,21 @@ public static int GetListCount(string tag)
231232
/// Gets the first gameobject from a tag
232233
/// </summary>
233234
/// <param name="tag">Tag</param>
234-
/// <returns>GameObject if tag exist. null if false</returns>
235+
/// <returns>GameObject if tag exist. Null if false</returns>
235236
public static GameObject GetGameObject(string tag)
236237
{
237238
return MtDict.ContainsKey(tag) ? MtDict[tag].ToArray()[0] : null;
238239
}
240+
241+
/// <summary>
242+
/// Check if gameobject is tagged with a tag
243+
/// </summary>
244+
/// <param name="tag"></param>
245+
/// <param name="gameObject"></param>
246+
/// <returns>Returns false if tag does not exist</returns>
247+
public static bool IsGameObjectTaggedWith(string tag, GameObject gameObject)
248+
{
249+
return MtDict.ContainsKey(tag) && MtDict[tag].Contains(gameObject);
250+
}
239251
}
240252
}

Assets/MultiTagSystem/MultiTagComponent.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace MultiTagSystem
88
public class MultiTagComponent : MonoBehaviour
99
{
1010
[HideInInspector]
11-
public List<string> tags => _tags;
11+
public List<string> Tags => _Tags;
1212

1313
[SerializeField]
14-
private List<string> _tags;
14+
private List<string> _Tags;
1515

1616
private void Awake()
1717
{
@@ -20,28 +20,28 @@ private void Awake()
2020

2121
public void AddDict()
2222
{
23-
MultiTag.MultiTagsAddToDict(_tags.ToArray(), gameObject);
23+
MultiTag.MultiTagsAddToDict(_Tags.ToArray(), gameObject);
2424
}
2525

2626
private void OnDestroy()
2727
{
28-
MultiTag.RemoveToDict(_tags.ToArray(), gameObject);
28+
MultiTag.RemoveToDict(_Tags.ToArray(), gameObject);
2929
}
3030

3131
/// <summary>
3232
/// Adds a Tag from the Set.
3333
/// <para>You cannot create a new Tag.</para>
34-
/// <para>To add a Tag via the Editor and rebuild.</para>
34+
/// <para>To create do it via the Editor and Rebuild.</para>
3535
/// </summary>
3636
/// <param name="tag"></param>
3737
public void AddTag(string tag)
3838
{
39-
if (Tags.Set.Contains(tag))
39+
if (MultiTagSystem.Tags.Set.Contains(tag))
4040
{
41-
var hashSet = new HashSet<string>(_tags);
41+
var hashSet = new HashSet<string>(_Tags);
4242
if (hashSet.Add(tag))
4343
{
44-
_tags = hashSet.ToList();
44+
_Tags = hashSet.ToList();
4545
MultiTag.SingleTagAddToDict(tag, gameObject);
4646
}
4747
}
@@ -53,12 +53,12 @@ public void AddTag(string tag)
5353
/// <param name="tag"></param>
5454
public void RemoveTag(string tag)
5555
{
56-
if (Tags.Set.Contains(tag))
56+
if (MultiTagSystem.Tags.Set.Contains(tag))
5757
{
58-
var hashSet = new HashSet<string>(_tags);
58+
var hashSet = new HashSet<string>(_Tags);
5959
if (hashSet.Remove(tag))
6060
{
61-
_tags = hashSet.ToList();
61+
_Tags = hashSet.ToList();
6262
MultiTag.SingleRemoveFromDict(tag, gameObject);
6363
}
6464
}

Assets/MultiTagSystem/Samples/MultiTagSample.unity

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ MonoBehaviour:
150150
m_Script: {fileID: 11500000, guid: 9c25f50bdd97d544795ec9c3f4fab70b, type: 3}
151151
m_Name:
152152
m_EditorClassIdentifier:
153-
_tags:
153+
_Tags:
154154
- Player
155-
- Untagged
156155
- Finish
156+
- Untagged
157157
--- !u!4 &530882307
158158
Transform:
159159
m_ObjectHideFlags: 0
@@ -289,8 +289,9 @@ MonoBehaviour:
289289
m_Script: {fileID: 11500000, guid: 9c25f50bdd97d544795ec9c3f4fab70b, type: 3}
290290
m_Name:
291291
m_EditorClassIdentifier:
292-
_tags:
292+
_Tags:
293293
- EditorOnly
294+
- Finish
294295
--- !u!4 &826638013
295296
Transform:
296297
m_ObjectHideFlags: 0
@@ -460,7 +461,7 @@ MonoBehaviour:
460461
m_Script: {fileID: 11500000, guid: 9c25f50bdd97d544795ec9c3f4fab70b, type: 3}
461462
m_Name:
462463
m_EditorClassIdentifier:
463-
_tags:
464+
_Tags:
464465
- EditorOnly
465466
- GameController
466467
--- !u!4 &1185620499
@@ -506,7 +507,7 @@ MonoBehaviour:
506507
m_Script: {fileID: 11500000, guid: 9c25f50bdd97d544795ec9c3f4fab70b, type: 3}
507508
m_Name:
508509
m_EditorClassIdentifier:
509-
_tags:
510+
_Tags:
510511
- Player
511512
--- !u!4 &1303800451
512513
Transform:
@@ -565,6 +566,6 @@ MonoBehaviour:
565566
m_Script: {fileID: 11500000, guid: 9c25f50bdd97d544795ec9c3f4fab70b, type: 3}
566567
m_Name:
567568
m_EditorClassIdentifier:
568-
_tags:
569+
_Tags:
569570
- Player
570571
- Finish

Assets/MultiTagSystem/Samples/SampleMono.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private void Start()
1717

1818
foreach (var val in list)
1919
{
20-
Debug.Log($"Query {val.name}");
20+
Debug.Log($"Queried GameObject : {val.name}");
2121

2222
var mtcomp = val.GetComponent<MultiTagComponent>();
2323

@@ -28,7 +28,7 @@ private void Start()
2828

2929
//Getting the first gameObject from a list of gameobjects with Player tag
3030
var gameObject = MultiTag.GetGameObject(Tags.Player);
31-
Debug.Log($"GetGameObject {gameObject.name}");
31+
Debug.Log($"GetGameObject : {gameObject.name}");
3232

3333
//Getting only a GameObject based on query
3434
gameObject = MultiTag.QuerySingle(new MultiTagFilter
@@ -37,6 +37,9 @@ private void Start()
3737
None = new string[] { Tags.Untagged }
3838
});
3939

40-
Debug.Log($"QuerySingleton {gameObject.name}");
40+
Debug.Log($"Queried Singleton : {gameObject.name}");
41+
42+
//Check if gameobject tagged with Finish tag
43+
Debug.Log($"Is GameObect tagged with finish? : {MultiTag.IsGameObjectTaggedWith(Tags.Finish, gameObject)}");
4144
}
4245
}

0 commit comments

Comments
 (0)