theembracedone

CustomIfEditor.cs

Apr 4th, 2022
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.01 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. namespace Fungus.EditorUtils {
  5.     [CustomEditor(typeof(CustomIf))]
  6.  
  7.     public class CustomIfEditor : CommandEditor {
  8.         protected SerializedProperty conditionsProp;
  9.         protected SerializedProperty anyOrAllProp;
  10.  
  11.         //protected SerializedProperty callOrJumpProp;
  12.         protected SerializedProperty callOrJumpIfTrueProp;
  13.         protected SerializedProperty callOrJumpIfFalseProp;
  14.  
  15.         protected SerializedProperty jumpToIfTrueProp;
  16.         protected SerializedProperty jumpToIfFalseProp;
  17.         protected SerializedProperty callIfTrueProp;
  18.         protected SerializedProperty callIfFalseProp;
  19.  
  20.         protected SerializedProperty trueTargetFlowchartProp;
  21.         protected SerializedProperty falseTargetFlowchartProp;
  22.  
  23.         public override void OnEnable() {
  24.             base.OnEnable();
  25.             anyOrAllProp = serializedObject.FindProperty("anyOrAll");
  26.             conditionsProp = serializedObject.FindProperty("conditions");
  27.  
  28.             //callOrJumpProp = serializedObject.FindProperty("callOrJump");
  29.             callOrJumpIfTrueProp = serializedObject.FindProperty("callOrJumpIfTrue");
  30.             callOrJumpIfFalseProp = serializedObject.FindProperty("callOrJumpIfFalse");
  31.  
  32.             trueTargetFlowchartProp = serializedObject.FindProperty("targetFlowchartTrue");
  33.             falseTargetFlowchartProp = serializedObject.FindProperty("targetFlowchartFalse");
  34.  
  35.             jumpToIfTrueProp = serializedObject.FindProperty("jumpToIfTrue");
  36.             jumpToIfFalseProp = serializedObject.FindProperty("jumpToIfFalse");
  37.             callIfTrueProp = serializedObject.FindProperty("callIfTrue");
  38.             callIfFalseProp = serializedObject.FindProperty("callIfFalse");
  39.         }
  40.  
  41.         public override void DrawCommandGUI() {
  42.             serializedObject.Update();
  43.  
  44.  
  45.             CustomIf t = target as CustomIf;
  46.  
  47.             EditorGUILayout.PropertyField(anyOrAllProp);
  48.             EditorGUILayout.PropertyField(conditionsProp);
  49.  
  50.             EditorGUILayout.Separator();
  51.  
  52.             EditorGUILayout.PropertyField(callOrJumpIfTrueProp);
  53.             //CALL + CALL IF TRUE
  54.             if (callOrJumpIfTrueProp.enumValueIndex == 1) {
  55.                 EditorGUILayout.PropertyField(trueTargetFlowchartProp);
  56.  
  57.                 Flowchart flowchart = null;
  58.                 if (trueTargetFlowchartProp.objectReferenceValue == null) {
  59.                     flowchart = (Flowchart)t.GetFlowchart();
  60.                     trueTargetFlowchartProp.objectReferenceValue = flowchart;
  61.  
  62.                 } else {
  63.                     flowchart = trueTargetFlowchartProp.objectReferenceValue as Flowchart;
  64.                 }
  65.  
  66.                 if (flowchart != null) {
  67.                     BlockEditor.BlockField(callIfTrueProp,
  68.                                            new GUIContent("Call if True", "Block to call if true"),
  69.                                            new GUIContent("<None>"),
  70.                                            flowchart);
  71.                 }
  72.  
  73.                 //JUMP + CALL IF TRUE
  74.             } else if (callOrJumpIfTrueProp.enumValueIndex == 2) {
  75.                 EditorGUILayout.PropertyField(jumpToIfTrueProp);
  76.             }
  77.  
  78.             GUILayout.Space(10);
  79.  
  80.  
  81.             EditorGUILayout.PropertyField(callOrJumpIfFalseProp);
  82.  
  83.             //CALL + CALL IF FALSE
  84.             if (callOrJumpIfFalseProp.enumValueIndex == 1) {
  85.                 EditorGUILayout.PropertyField(falseTargetFlowchartProp);
  86.  
  87.                 Flowchart flowchart = null;
  88.                 if (falseTargetFlowchartProp.objectReferenceValue == null) {
  89.                     flowchart = (Flowchart)t.GetFlowchart();
  90.                     falseTargetFlowchartProp.objectReferenceValue = flowchart;
  91.  
  92.                 } else {
  93.                     flowchart = falseTargetFlowchartProp.objectReferenceValue as Flowchart;
  94.                 }
  95.  
  96.                 if (flowchart != null) {
  97.                     BlockEditor.BlockField(callIfFalseProp,
  98.                                            new GUIContent("Call if True", "Block to call if true"),
  99.                                            new GUIContent("<None>"),
  100.                                            flowchart);
  101.                 }
  102.  
  103.                 //JUMP + CALL IF FALSE
  104.             } else if (callOrJumpIfFalseProp.enumValueIndex == 2) {
  105.                 EditorGUILayout.PropertyField(jumpToIfFalseProp);
  106.             }
  107.  
  108.             SerializedProperty _jumpLabelProp = serializedObject.FindProperty("jumpLabel");
  109.  
  110.             GUILayout.Space(20);
  111.             EditorGUILayout.LabelField("Jump label for custom IF use", EditorStyles.boldLabel);
  112.             EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  113.             _jumpLabelProp.stringValue = EditorGUILayout.TextField("Jump label", _jumpLabelProp.stringValue);
  114.  
  115.             EditorGUILayout.EndVertical();
  116.  
  117.             serializedObject.ApplyModifiedProperties();
  118.         }
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment