CangJie/Assets/Plugins/Fungus/Scripts/Editor/SetVariableEditor.cs
Roman 787b285227 任务:新建项目 导入必要的插件
1.导入URP
2.配置了URP
3.导入Dotween
4.导入Odin
5.导入了InputSystem
6.设置项目为新旧输入系统并用
7.导入了FunGus
8.创建了一些空文件夹

我是每日提醒上班小助手,今天你上班了吗?😺
2022-03-10 22:49:14 +08:00

87 lines
3.6 KiB
C#

// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
namespace Fungus.EditorUtils
{
[CustomEditor (typeof(SetVariable))]
public class SetVariableEditor : CommandEditor
{
protected SerializedProperty anyVarProp;
protected SerializedProperty setOperatorProp;
public override void OnEnable()
{
base.OnEnable();
anyVarProp = serializedObject.FindProperty("anyVar");
setOperatorProp = serializedObject.FindProperty("setOperator");
}
public override void DrawCommandGUI()
{
serializedObject.Update();
SetVariable t = target as SetVariable;
var flowchart = (Flowchart)t.GetFlowchart();
if (flowchart == null)
{
return;
}
// Select Variable
EditorGUILayout.PropertyField(anyVarProp, true);
//fetching every draw to ensure we don't have stale data based on types that have changed by user selection,
// without us noticing.
// Get selected variable
Variable selectedVariable = anyVarProp.FindPropertyRelative("variable").objectReferenceValue as Variable;
List<GUIContent> operatorsList = new List<GUIContent>();
if (selectedVariable != null)
{
if(selectedVariable.IsArithmeticSupported(SetOperator.Assign))
operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Assign)));
if (selectedVariable.IsArithmeticSupported(SetOperator.Negate))
operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Negate)));
if (selectedVariable.IsArithmeticSupported(SetOperator.Add))
operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Add)));
if (selectedVariable.IsArithmeticSupported(SetOperator.Subtract))
operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Subtract)));
if (selectedVariable.IsArithmeticSupported(SetOperator.Multiply))
operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Multiply)));
if (selectedVariable.IsArithmeticSupported(SetOperator.Divide))
operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Divide)));
}
else
{
operatorsList.Add(VariableConditionEditor.None);
}
// Get previously selected operator
int selectedIndex = (int) t._SetOperator;
if (selectedIndex < 0)
{
// Default to first index if the operator is not found in the available operators list
// This can occur when changing between variable types
selectedIndex = 0;
}
// Get next selected operator
selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());
if (selectedVariable != null)
{
setOperatorProp.enumValueIndex = selectedIndex;
}
serializedObject.ApplyModifiedProperties();
}
}
}