浏览代码

Behaviour Toggle Action

/main
Thomas ICHÉ 5 年前
当前提交
0f3b42b0
共有 5 个文件被更改,包括 104 次插入0 次删除
  1. 1
      CHANGELOG.md
  2. 29
      Editor/PropertyDrawers/BehaviourTogglePropertyDrawer.cs
  3. 11
      Editor/PropertyDrawers/BehaviourTogglePropertyDrawer.cs.meta
  4. 52
      Runtime/LevelScripting/Actions/ToggleBehaviourAction.cs
  5. 11
      Runtime/LevelScripting/Actions/ToggleBehaviourAction.cs.meta

1
CHANGELOG.md


#### Added
* **Call Tree Explorer**: Added Category for Erroneous Calls
* Added **ToggleBehaviourAction** working the same as ToggleGameObjectAction, but for behaviour components instead.
#### Fixed

29
Editor/PropertyDrawers/BehaviourTogglePropertyDrawer.cs


using UnityEngine;
using UnityEditor;
namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(Actions.ToggleBehaviourAction.BehaviourToggle))]
public class BehaviourTogglePropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var toggle = property.FindPropertyRelative("State");
var bhv = property.FindPropertyRelative("Behaviour");
var toggleRect = new Rect(position);
toggleRect.xMin = toggleRect.xMax - 80;
var objRect = new Rect(position);
objRect.xMax -= 80;
toggle.intValue = EditorGUI.IntPopup(toggleRect, toggle.intValue, labels, values);
bhv.objectReferenceValue = EditorGUI.ObjectField(objRect, bhv.objectReferenceValue, typeof(Behaviour), true);
}
static GUIContent[] labels = { new GUIContent("Disable"), new GUIContent("Enable"), new GUIContent("Toggle") };
static int[] values = { 0, 1, 2 };
}
}

11
Editor/PropertyDrawers/BehaviourTogglePropertyDrawer.cs.meta


fileFormatVersion: 2
guid: f9cc2708038acf742980191ecb1fa105
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

52
Runtime/LevelScripting/Actions/ToggleBehaviourAction.cs


using NaughtyAttributes;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public class ToggleBehaviourAction : ActionBase
{
[ReorderableList]
public BehaviourToggle[] Targets;
public override void Execute(GameObject instigator = null)
{
foreach (var target in Targets)
{
if (target.Behaviour == null)
{
Debug.Log("Target is null, ignoring");
}
else
{
switch (target.State)
{
case BehaviourToggle.BehaviourToggleState.Disable:
target.Behaviour.enabled = false;
break;
case BehaviourToggle.BehaviourToggleState.Enable:
target.Behaviour.enabled = true;
break;
case BehaviourToggle.BehaviourToggleState.Toggle:
target.Behaviour.enabled = !target.Behaviour.enabled;
break;
}
}
}
}
[System.Serializable]
public struct BehaviourToggle
{
[System.Serializable]
public enum BehaviourToggleState
{
Disable = 0,
Enable = 1,
Toggle = 2
}
public Behaviour Behaviour;
public BehaviourToggleState State;
}
}
}

11
Runtime/LevelScripting/Actions/ToggleBehaviourAction.cs.meta


fileFormatVersion: 2
guid: 756d008da58a19e4dbc02fa1e3c84852
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 225c53326635b1748868c470ea1bccce, type: 3}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存