From 84a13a00fa8ee28936081bc7a8d12eb7407e28fe Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Thu, 21 May 2015 16:50:01 +0100 Subject: [PATCH] Add Set Collider command #105 --- .../Fungus/Sprite/Editor/SetColliderEditor.cs | 34 +++++++++++ .../Sprite/Editor/SetColliderEditor.cs.meta | 12 ++++ .../Sprite/Scripts/Commands/SetCollider.cs | 60 +++++++++++++++++++ .../Scripts/Commands/SetCollider.cs.meta | 12 ++++ 4 files changed, 118 insertions(+) create mode 100644 Assets/Fungus/Sprite/Editor/SetColliderEditor.cs create mode 100644 Assets/Fungus/Sprite/Editor/SetColliderEditor.cs.meta create mode 100644 Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs create mode 100644 Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs.meta diff --git a/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs b/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs new file mode 100644 index 00000000..7744ada4 --- /dev/null +++ b/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs @@ -0,0 +1,34 @@ +using UnityEditor; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using Rotorz.ReorderableList; + +namespace Fungus +{ + [CustomEditor (typeof(SetCollider))] + public class SetColliderEditor : CommandEditor + { + protected SerializedProperty targetObjectsProp; + protected SerializedProperty activeStateProp; + + protected virtual void OnEnable() + { + targetObjectsProp = serializedObject.FindProperty("targetObjects"); + activeStateProp = serializedObject.FindProperty("activeState"); + } + + public override void DrawCommandGUI() + { + serializedObject.Update(); + + ReorderableListGUI.Title(new GUIContent("Target Objects", "Objects containing collider components (2D or 3D)")); + ReorderableListGUI.ListField(targetObjectsProp); + + EditorGUILayout.PropertyField(activeStateProp); + + serializedObject.ApplyModifiedProperties(); + } + } + +} diff --git a/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs.meta b/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs.meta new file mode 100644 index 00000000..f0f8604f --- /dev/null +++ b/Assets/Fungus/Sprite/Editor/SetColliderEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 672281668cfa249738d9dbc91f96b88e +timeCreated: 1432222536 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs b/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs new file mode 100644 index 00000000..dcf23401 --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs @@ -0,0 +1,60 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace Fungus +{ + [CommandInfo("Sprite", + "Set Collider", + "Sets all collider (2d or 3d) components on the target objects to be active / inactive")] + [AddComponentMenu("")] + public class SetCollider : Command + { + [Tooltip("A list of gameobjects containing collider components to be set active / inactive")] + public List targetObjects = new List(); + + [Tooltip("Set to true to enable the collider components")] + public BooleanData activeState; + + public override void OnEnter() + { + 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; + } + } + } + + Continue(); + } + + public override string GetSummary() + { + if (activeState.Value) + { + return "Enable " + targetObjects.Count + " collider objects."; + } + else + { + return "Disable " + targetObjects.Count + " collider objects."; + } + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs.meta b/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs.meta new file mode 100644 index 00000000..86799ca1 --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 985454614aca94d16906c0f2bd0b26f6 +timeCreated: 1432220559 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: