Browse Source

Added target tag property to Set Collider #105

master
chrisgregan 10 years ago
parent
commit
e44c1332d6
  1. 3
      Assets/Fungus/Sprite/Editor/SetColliderEditor.cs
  2. 49
      Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs

3
Assets/Fungus/Sprite/Editor/SetColliderEditor.cs

@ -10,11 +10,13 @@ namespace Fungus
public class SetColliderEditor : CommandEditor public class SetColliderEditor : CommandEditor
{ {
protected SerializedProperty targetObjectsProp; protected SerializedProperty targetObjectsProp;
protected SerializedProperty targetTagProp;
protected SerializedProperty activeStateProp; protected SerializedProperty activeStateProp;
protected virtual void OnEnable() protected virtual void OnEnable()
{ {
targetObjectsProp = serializedObject.FindProperty("targetObjects"); targetObjectsProp = serializedObject.FindProperty("targetObjects");
targetTagProp = serializedObject.FindProperty("targetTag");
activeStateProp = serializedObject.FindProperty("activeState"); activeStateProp = serializedObject.FindProperty("activeState");
} }
@ -25,6 +27,7 @@ namespace Fungus
ReorderableListGUI.Title(new GUIContent("Target Objects", "Objects containing collider components (2D or 3D)")); ReorderableListGUI.Title(new GUIContent("Target Objects", "Objects containing collider components (2D or 3D)"));
ReorderableListGUI.ListField(targetObjectsProp); ReorderableListGUI.ListField(targetObjectsProp);
EditorGUILayout.PropertyField(targetTagProp);
EditorGUILayout.PropertyField(activeStateProp); EditorGUILayout.PropertyField(activeStateProp);
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();

49
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")] [Tooltip("A list of gameobjects containing collider components to be set active / inactive")]
public List<GameObject> targetObjects = new List<GameObject>(); public List<GameObject> targetObjects = new List<GameObject>();
[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")] [Tooltip("Set to true to enable the collider components")]
public BooleanData activeState; public BooleanData activeState;
@ -20,34 +23,48 @@ namespace Fungus
{ {
foreach (GameObject go in targetObjects) foreach (GameObject go in targetObjects)
{ {
if (go != null) SetColliderActive(go);
{ }
// 3D objects
foreach (Collider c in go.GetComponentsInChildren<Collider>()) GameObject[] taggedObjects = GameObject.FindGameObjectsWithTag(targetTag);
{ foreach (GameObject go in taggedObjects)
c.enabled = activeState.Value; {
} SetColliderActive(go);
// 2D objects
foreach (Collider2D c in go.GetComponentsInChildren<Collider2D>())
{
c.enabled = activeState.Value;
}
}
} }
Continue(); Continue();
} }
protected virtual void SetColliderActive(GameObject go)
{
if (go != null)
{
// 3D objects
foreach (Collider c in go.GetComponentsInChildren<Collider>())
{
c.enabled = activeState.Value;
}
// 2D objects
foreach (Collider2D c in go.GetComponentsInChildren<Collider2D>())
{
c.enabled = activeState.Value;
}
}
}
public override string GetSummary() public override string GetSummary()
{ {
int count = targetObjects.Count;
count += GameObject.FindGameObjectsWithTag(targetTag).Length;
if (activeState.Value) if (activeState.Value)
{ {
return "Enable " + targetObjects.Count + " collider objects."; return "Enable " + count + " collider objects.";
} }
else else
{ {
return "Disable " + targetObjects.Count + " collider objects."; return "Disable " + count + " collider objects.";
} }
} }

Loading…
Cancel
Save