From e44c1332d6e4440f98f997926c39fff931194eef Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 22 May 2015 15:25:04 +0100 Subject: [PATCH] Added target tag property to Set Collider #105 --- .../Fungus/Sprite/Editor/SetColliderEditor.cs | 3 ++ .../Sprite/Scripts/Commands/SetCollider.cs | 49 +++++++++++++------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs b/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs index 7744ada4..d2b65a31 100644 --- a/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs +++ b/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs @@ -10,11 +10,13 @@ namespace Fungus public class SetColliderEditor : CommandEditor { protected SerializedProperty targetObjectsProp; + protected SerializedProperty targetTagProp; protected SerializedProperty activeStateProp; protected virtual void OnEnable() { targetObjectsProp = serializedObject.FindProperty("targetObjects"); + targetTagProp = serializedObject.FindProperty("targetTag"); activeStateProp = serializedObject.FindProperty("activeState"); } @@ -25,6 +27,7 @@ namespace Fungus ReorderableListGUI.Title(new GUIContent("Target Objects", "Objects containing collider components (2D or 3D)")); ReorderableListGUI.ListField(targetObjectsProp); + EditorGUILayout.PropertyField(targetTagProp); EditorGUILayout.PropertyField(activeStateProp); serializedObject.ApplyModifiedProperties(); diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs b/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs index dcf23401..485733aa 100644 --- a/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs @@ -13,6 +13,9 @@ namespace Fungus [Tooltip("A list of gameobjects containing collider components to be set active / inactive")] public List targetObjects = new List(); + [Tooltip("All objects with this tag will have their collider set active / inactive")] + public string targetTag; + [Tooltip("Set to true to enable the collider components")] public BooleanData activeState; @@ -20,34 +23,48 @@ namespace Fungus { foreach (GameObject go in targetObjects) { - if (go != null) - { - // 3D objects - foreach (Collider c in go.GetComponentsInChildren()) - { - c.enabled = activeState.Value; - } - - // 2D objects - foreach (Collider2D c in go.GetComponentsInChildren()) - { - c.enabled = activeState.Value; - } - } + SetColliderActive(go); + } + + GameObject[] taggedObjects = GameObject.FindGameObjectsWithTag(targetTag); + foreach (GameObject go in taggedObjects) + { + SetColliderActive(go); } Continue(); } + + protected virtual void SetColliderActive(GameObject go) + { + if (go != null) + { + // 3D objects + foreach (Collider c in go.GetComponentsInChildren()) + { + c.enabled = activeState.Value; + } + + // 2D objects + foreach (Collider2D c in go.GetComponentsInChildren()) + { + c.enabled = activeState.Value; + } + } + } public override string GetSummary() { + int count = targetObjects.Count; + count += GameObject.FindGameObjectsWithTag(targetTag).Length; + if (activeState.Value) { - return "Enable " + targetObjects.Count + " collider objects."; + return "Enable " + count + " collider objects."; } else { - return "Disable " + targetObjects.Count + " collider objects."; + return "Disable " + count + " collider objects."; } }