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. 27
      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();

27
Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs

@ -13,12 +13,29 @@ 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;
public override void OnEnter() public override void OnEnter()
{ {
foreach (GameObject go in targetObjects) foreach (GameObject go in targetObjects)
{
SetColliderActive(go);
}
GameObject[] taggedObjects = GameObject.FindGameObjectsWithTag(targetTag);
foreach (GameObject go in taggedObjects)
{
SetColliderActive(go);
}
Continue();
}
protected virtual void SetColliderActive(GameObject go)
{ {
if (go != null) if (go != null)
{ {
@ -36,18 +53,18 @@ namespace Fungus
} }
} }
Continue();
}
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