diff --git a/Assets/UnityAtoms/AtomicTags.meta b/Assets/UnityAtoms/AtomicTags.meta new file mode 100644 index 00000000..196dee38 --- /dev/null +++ b/Assets/UnityAtoms/AtomicTags.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ae1b1b89eb6c54f769875a63bcee77d7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UnityAtoms/AtomicTags/AtomicTags.cs b/Assets/UnityAtoms/AtomicTags/AtomicTags.cs new file mode 100644 index 00000000..49276c85 --- /dev/null +++ b/Assets/UnityAtoms/AtomicTags/AtomicTags.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace UnityAtoms +{ + public class AtomicTags : MonoBehaviour + { + public List Tags; + } +} diff --git a/Assets/UnityAtoms/Examples/Intro/Scripts/Harmful.cs.meta b/Assets/UnityAtoms/AtomicTags/AtomicTags.cs.meta similarity index 83% rename from Assets/UnityAtoms/Examples/Intro/Scripts/Harmful.cs.meta rename to Assets/UnityAtoms/AtomicTags/AtomicTags.cs.meta index 016380c5..d75b7cde 100644 --- a/Assets/UnityAtoms/Examples/Intro/Scripts/Harmful.cs.meta +++ b/Assets/UnityAtoms/AtomicTags/AtomicTags.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b97da5e1105ef486696939996e891752 +guid: 2afb94fa4090c4d778c5320d91b1da32 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/UnityAtoms/Examples/Intro/GameObjects/Harmful/DecreasePlayersHealth.cs b/Assets/UnityAtoms/Examples/Intro/GameObjects/Harmful/DecreasePlayersHealth.cs index 83bc2d5f..a9812585 100644 --- a/Assets/UnityAtoms/Examples/Intro/GameObjects/Harmful/DecreasePlayersHealth.cs +++ b/Assets/UnityAtoms/Examples/Intro/GameObjects/Harmful/DecreasePlayersHealth.cs @@ -12,7 +12,7 @@ namespace UnityAtoms.Examples public override void Do(Collider2D collider) { - if (collider.tag == TagPlayer.Value) + if (collider.gameObject.HasTag(TagPlayer)) { collider.GetComponent().Health.Value -= 10; } diff --git a/Assets/UnityAtoms/Examples/Intro/Scenes/Intro.unity b/Assets/UnityAtoms/Examples/Intro/Scenes/Intro.unity index ea8f3177..4bdf35f4 100644 --- a/Assets/UnityAtoms/Examples/Intro/Scenes/Intro.unity +++ b/Assets/UnityAtoms/Examples/Intro/Scenes/Intro.unity @@ -224,13 +224,25 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e564c43d8cd6f404fbf20034291d3354, type: 3} m_Name: m_EditorClassIdentifier: - Event: {fileID: 0} + Event: {fileID: 11400000, guid: 739733ee170564820972eacff604acdc, type: 2} UnityEventResponse: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 145633448} + m_MethodName: HealthChanged + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_TypeName: UnityAtoms.UnityIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - GameActionResponses: [] + GameActionResponses: + - {fileID: 11400000, guid: 83741e2008cf7481da664e38c37bb9db, type: 2} --- !u!4 &299553486 Transform: m_ObjectHideFlags: 0 @@ -377,9 +389,10 @@ GameObject: - component: {fileID: 854994182} - component: {fileID: 854994179} - component: {fileID: 854994184} + - component: {fileID: 854994185} m_Layer: 0 m_Name: Player - m_TagString: Player + m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -511,6 +524,19 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b994f74f11b564875b8eb8c828ed594e, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &854994185 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 854994178} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2afb94fa4090c4d778c5320d91b1da32, type: 3} + m_Name: + m_EditorClassIdentifier: + Tags: + - {fileID: 11400000, guid: 7f6f1e5f624af4653a66e0fc3ede9c78, type: 2} --- !u!1 &1067648696 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/UnityAtoms/Examples/Intro/Scripts/Harmful.cs b/Assets/UnityAtoms/Examples/Intro/Scripts/Harmful.cs deleted file mode 100644 index 99f6c2ec..00000000 --- a/Assets/UnityAtoms/Examples/Intro/Scripts/Harmful.cs +++ /dev/null @@ -1,17 +0,0 @@ -using UnityEngine; -using UnityEngine.UI; -using UnityAtoms; - -namespace UnityAtoms.Examples -{ - public class Harmful : MonoBehaviour - { - void OnTriggerEnter2D(Collider2D collider) - { - if (collider.tag == "Player") - { - collider.GetComponent().Health.Value -= 10; - } - } - } -} \ No newline at end of file diff --git a/Assets/UnityAtoms/Extensions/GameObjectExtensions.cs b/Assets/UnityAtoms/Extensions/GameObjectExtensions.cs new file mode 100644 index 00000000..d2a3582a --- /dev/null +++ b/Assets/UnityAtoms/Extensions/GameObjectExtensions.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace UnityAtoms +{ + public static class GameObjectExtensions + { + public static List GetTags(this GameObject go) + { + return go.GetComponent() ? go.GetComponent().Tags : null; + } + + public static bool HasTag(this GameObject go, string str) + { + var tags = go.GetComponent() ? go.GetComponent().Tags : null; + + for (int i = 0; tags != null && i < tags.Count; ++i) + { + if (tags[i].Value == str) + { + return true; + } + } + + return false; + } + + public static bool HasTag(this GameObject go, StringConstant stringConstant) + { + return go.HasTag(stringConstant.Value); + } + + public static bool HasAnyTag(this GameObject go, List stringConstants) + { + for (int i = 0; stringConstants != null && i < stringConstants.Count; ++i) + { + if (go.HasTag(stringConstants[i].Value)) + { + return true; + } + } + + return false; + } + } +} \ No newline at end of file diff --git a/Assets/UnityAtoms/Extensions/GameObjectExtensions.cs.meta b/Assets/UnityAtoms/Extensions/GameObjectExtensions.cs.meta new file mode 100644 index 00000000..7c783cc9 --- /dev/null +++ b/Assets/UnityAtoms/Extensions/GameObjectExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b70cb59b7540b43a794791992a68b2f2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: