chrisgregan
10 years ago
4 changed files with 118 additions and 0 deletions
@ -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(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 672281668cfa249738d9dbc91f96b88e |
||||
timeCreated: 1432222536 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -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<GameObject> targetObjects = new List<GameObject>(); |
||||
|
||||
[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<Collider>()) |
||||
{ |
||||
c.enabled = activeState.Value; |
||||
} |
||||
|
||||
// 2D objects |
||||
foreach (Collider2D c in go.GetComponentsInChildren<Collider2D>()) |
||||
{ |
||||
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); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 985454614aca94d16906c0f2bd0b26f6 |
||||
timeCreated: 1432220559 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Loading…
Reference in new issue