Issue #6 - AtomicTags

This commit is contained in:
Adam Ramberg 2018-11-30 23:10:21 +01:00
parent 8907763227
commit dfd70a8944
8 changed files with 107 additions and 23 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ae1b1b89eb6c54f769875a63bcee77d7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
using UnityEngine;
namespace UnityAtoms
{
public class AtomicTags : MonoBehaviour
{
public List<StringConstant> Tags;
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: b97da5e1105ef486696939996e891752 guid: 2afb94fa4090c4d778c5320d91b1da32
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -12,7 +12,7 @@ namespace UnityAtoms.Examples
public override void Do(Collider2D collider) public override void Do(Collider2D collider)
{ {
if (collider.tag == TagPlayer.Value) if (collider.gameObject.HasTag(TagPlayer))
{ {
collider.GetComponent<PlayerHealth>().Health.Value -= 10; collider.GetComponent<PlayerHealth>().Health.Value -= 10;
} }

View File

@ -224,13 +224,25 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e564c43d8cd6f404fbf20034291d3354, type: 3} m_Script: {fileID: 11500000, guid: e564c43d8cd6f404fbf20034291d3354, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Event: {fileID: 0} Event: {fileID: 11400000, guid: 739733ee170564820972eacff604acdc, type: 2}
UnityEventResponse: UnityEventResponse:
m_PersistentCalls: 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, m_TypeName: UnityAtoms.UnityIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null PublicKeyToken=null
GameActionResponses: [] GameActionResponses:
- {fileID: 11400000, guid: 83741e2008cf7481da664e38c37bb9db, type: 2}
--- !u!4 &299553486 --- !u!4 &299553486
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -377,9 +389,10 @@ GameObject:
- component: {fileID: 854994182} - component: {fileID: 854994182}
- component: {fileID: 854994179} - component: {fileID: 854994179}
- component: {fileID: 854994184} - component: {fileID: 854994184}
- component: {fileID: 854994185}
m_Layer: 0 m_Layer: 0
m_Name: Player m_Name: Player
m_TagString: Player m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
@ -511,6 +524,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b994f74f11b564875b8eb8c828ed594e, type: 3} m_Script: {fileID: 11500000, guid: b994f74f11b564875b8eb8c828ed594e, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: 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 --- !u!1 &1067648696
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -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;
}
}
}
}

View 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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b70cb59b7540b43a794791992a68b2f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: