mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-21 23:58:49 -05:00
Issue #6 - AtomicTags
This commit is contained in:
parent
8907763227
commit
dfd70a8944
8
Assets/UnityAtoms/AtomicTags.meta
Normal file
8
Assets/UnityAtoms/AtomicTags.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae1b1b89eb6c54f769875a63bcee77d7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/UnityAtoms/AtomicTags/AtomicTags.cs
Normal file
10
Assets/UnityAtoms/AtomicTags/AtomicTags.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityAtoms
|
||||
{
|
||||
public class AtomicTags : MonoBehaviour
|
||||
{
|
||||
public List<StringConstant> Tags;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b97da5e1105ef486696939996e891752
|
||||
guid: 2afb94fa4090c4d778c5320d91b1da32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@ -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<PlayerHealth>().Health.Value -= 10;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<PlayerHealth>().Health.Value -= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
46
Assets/UnityAtoms/Extensions/GameObjectExtensions.cs
Normal file
46
Assets/UnityAtoms/Extensions/GameObjectExtensions.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityAtoms
|
||||
{
|
||||
public static class GameObjectExtensions
|
||||
{
|
||||
public static List<StringConstant> GetTags(this GameObject go)
|
||||
{
|
||||
return go.GetComponent<AtomicTags>() ? go.GetComponent<AtomicTags>().Tags : null;
|
||||
}
|
||||
|
||||
public static bool HasTag(this GameObject go, string str)
|
||||
{
|
||||
var tags = go.GetComponent<AtomicTags>() ? go.GetComponent<AtomicTags>().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<StringConstant> stringConstants)
|
||||
{
|
||||
for (int i = 0; stringConstants != null && i < stringConstants.Count; ++i)
|
||||
{
|
||||
if (go.HasTag(stringConstants[i].Value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/UnityAtoms/Extensions/GameObjectExtensions.cs.meta
Normal file
11
Assets/UnityAtoms/Extensions/GameObjectExtensions.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b70cb59b7540b43a794791992a68b2f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user