IndieGame/client/Assets/Scripts/ThridParty/NodeCanvasExtension/ActionTask/SetOperation.cs

88 lines
3.0 KiB
C#
Raw Normal View History

2024-10-11 10:12:15 +08:00
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions
{
public enum ValueType
{
Float,
Int,
Vector3
}
[Category("扩展/设置值的运算修改")]
[Description("设置值的运算修改")]
[Name("设置值的运算")]
public class SetOperation : ActionTask
{
[BlackboardOnly]
//结果
public ValueType valueType;
[ShowIf("valueType", (int)ValueType.Float)]
public BBParameter<float> floatValue;
[ShowIf("valueType", (int)ValueType.Int)]
public BBParameter<int> intValue;
[ShowIf("valueType", (int)ValueType.Vector3)]
public BBParameter<Vector3> vectorValue;
public OperationMethod operation;
//参数1
public ValueType param1Type;
[ShowIf("param1Type", (int)ValueType.Float)]
public BBParameter<float> floatParam1;
[ShowIf("param1Type", (int)ValueType.Int)]
public BBParameter<int> intParam1;
[ShowIf("param1Type", (int)ValueType.Vector3)]
public BBParameter<Vector3> vectorParam1;
public ValueType param2Type;
[ShowIf("param2Type", (int)ValueType.Float)]
public BBParameter<float> floatParam2;
[ShowIf("param2Type", (int)ValueType.Int)]
public BBParameter<int> intParam2;
[ShowIf("param2Type", (int)ValueType.Vector3)]
public BBParameter<Vector3> vectorParam2;
protected override string info
{
get
{
switch (valueType)
{
case ValueType.Float:
return string.Format("{0}={1}{2}{3}", floatValue, floatParam1, OperationTools.GetOperationSingleString(operation), floatParam2);
case ValueType.Int:
return string.Format("{0}={1}{2}{3}", intValue, intParam1, OperationTools.GetOperationSingleString(operation), intParam2);
case ValueType.Vector3:
return string.Format("{0}={1}{2}{3}", vectorValue, vectorParam1, OperationTools.GetOperationSingleString(operation), vectorParam2);
default:
return "Error";
}
}
}
protected override void OnExecute()
{
switch (valueType)
{
case ValueType.Float:
floatValue.value = OperationTools.Operate(floatParam1.value, floatParam2.value, operation);
break;
case ValueType.Int:
intValue.value = OperationTools.Operate(intParam1.value, intParam2.value, operation);
break;
case ValueType.Vector3:
vectorValue.value = OperationTools.Operate(vectorParam1.value, vectorParam2.value, operation);
break;
}
EndAction();
}
}
}