forked from IntoTheDev/MultiTag-System-for-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTagExtensions.cs
62 lines (49 loc) · 1.31 KB
/
TagExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using UnityEngine;
namespace ToolBox.Tags
{
public static class TagExtensions
{
public static void AddTag(this GameObject entity, Tag tag) =>
tag.Add(entity.GetHashCode());
public static void RemoveTag(this GameObject entity, Tag tag) =>
tag.Remove(entity.GetHashCode());
public static bool HasTag(this GameObject entity, Tag tag) =>
tag.HasEntity(entity.GetHashCode());
public static void AddTags(this GameObject entity, Tag[] tags)
{
int hash = entity.GetHashCode();
for (int i = 0; i < tags.Length; i++)
tags[i].Add(hash);
}
public static void RemoveTags(this GameObject entity, Tag[] tags)
{
int hash = entity.GetHashCode();
for (int i = 0; i < tags.Length; i++)
tags[i].Remove(hash);
}
public static bool HasTags(this GameObject entity, Tag[] tags, bool allRequired)
{
int hash = entity.GetHashCode();
if (allRequired)
{
for (int i = 0; i < tags.Length; i++)
{
if (!tags[i].HasEntity(hash))
return false;
}
return true;
}
else
{
for (int i = 0; i < tags.Length; i++)
{
if (tags[i].HasEntity(hash))
return true;
}
return false;
}
}
public static bool HasTags(this GameObject entity, TagsContainer tagsContainer, bool allRequired) =>
tagsContainer.HasEntity(entity, allRequired);
}
}