Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- namespace Fungus.EditorUtils {
- [CustomEditor(typeof(CustomIf))]
- public class CustomIfEditor : CommandEditor {
- protected SerializedProperty conditionsProp;
- protected SerializedProperty anyOrAllProp;
- //protected SerializedProperty callOrJumpProp;
- protected SerializedProperty callOrJumpIfTrueProp;
- protected SerializedProperty callOrJumpIfFalseProp;
- protected SerializedProperty jumpToIfTrueProp;
- protected SerializedProperty jumpToIfFalseProp;
- protected SerializedProperty callIfTrueProp;
- protected SerializedProperty callIfFalseProp;
- protected SerializedProperty trueTargetFlowchartProp;
- protected SerializedProperty falseTargetFlowchartProp;
- public override void OnEnable() {
- base.OnEnable();
- anyOrAllProp = serializedObject.FindProperty("anyOrAll");
- conditionsProp = serializedObject.FindProperty("conditions");
- //callOrJumpProp = serializedObject.FindProperty("callOrJump");
- callOrJumpIfTrueProp = serializedObject.FindProperty("callOrJumpIfTrue");
- callOrJumpIfFalseProp = serializedObject.FindProperty("callOrJumpIfFalse");
- trueTargetFlowchartProp = serializedObject.FindProperty("targetFlowchartTrue");
- falseTargetFlowchartProp = serializedObject.FindProperty("targetFlowchartFalse");
- jumpToIfTrueProp = serializedObject.FindProperty("jumpToIfTrue");
- jumpToIfFalseProp = serializedObject.FindProperty("jumpToIfFalse");
- callIfTrueProp = serializedObject.FindProperty("callIfTrue");
- callIfFalseProp = serializedObject.FindProperty("callIfFalse");
- }
- public override void DrawCommandGUI() {
- serializedObject.Update();
- CustomIf t = target as CustomIf;
- EditorGUILayout.PropertyField(anyOrAllProp);
- EditorGUILayout.PropertyField(conditionsProp);
- EditorGUILayout.Separator();
- EditorGUILayout.PropertyField(callOrJumpIfTrueProp);
- //CALL + CALL IF TRUE
- if (callOrJumpIfTrueProp.enumValueIndex == 1) {
- EditorGUILayout.PropertyField(trueTargetFlowchartProp);
- Flowchart flowchart = null;
- if (trueTargetFlowchartProp.objectReferenceValue == null) {
- flowchart = (Flowchart)t.GetFlowchart();
- trueTargetFlowchartProp.objectReferenceValue = flowchart;
- } else {
- flowchart = trueTargetFlowchartProp.objectReferenceValue as Flowchart;
- }
- if (flowchart != null) {
- BlockEditor.BlockField(callIfTrueProp,
- new GUIContent("Call if True", "Block to call if true"),
- new GUIContent("<None>"),
- flowchart);
- }
- //JUMP + CALL IF TRUE
- } else if (callOrJumpIfTrueProp.enumValueIndex == 2) {
- EditorGUILayout.PropertyField(jumpToIfTrueProp);
- }
- GUILayout.Space(10);
- EditorGUILayout.PropertyField(callOrJumpIfFalseProp);
- //CALL + CALL IF FALSE
- if (callOrJumpIfFalseProp.enumValueIndex == 1) {
- EditorGUILayout.PropertyField(falseTargetFlowchartProp);
- Flowchart flowchart = null;
- if (falseTargetFlowchartProp.objectReferenceValue == null) {
- flowchart = (Flowchart)t.GetFlowchart();
- falseTargetFlowchartProp.objectReferenceValue = flowchart;
- } else {
- flowchart = falseTargetFlowchartProp.objectReferenceValue as Flowchart;
- }
- if (flowchart != null) {
- BlockEditor.BlockField(callIfFalseProp,
- new GUIContent("Call if True", "Block to call if true"),
- new GUIContent("<None>"),
- flowchart);
- }
- //JUMP + CALL IF FALSE
- } else if (callOrJumpIfFalseProp.enumValueIndex == 2) {
- EditorGUILayout.PropertyField(jumpToIfFalseProp);
- }
- SerializedProperty _jumpLabelProp = serializedObject.FindProperty("jumpLabel");
- GUILayout.Space(20);
- EditorGUILayout.LabelField("Jump label for custom IF use", EditorStyles.boldLabel);
- EditorGUILayout.BeginVertical(EditorStyles.helpBox);
- _jumpLabelProp.stringValue = EditorGUILayout.TextField("Jump label", _jumpLabelProp.stringValue);
- EditorGUILayout.EndVertical();
- serializedObject.ApplyModifiedProperties();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment