You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.7 KiB
47 lines
1.7 KiB
using System;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.VFX;
|
|
//using Direction = UnityEditor.VFX.Direction;
|
|
|
|
namespace UnityEditor.VFX
|
|
{
|
|
[VFXInfo(type = typeof(DirectionType))]
|
|
class VFXSlotDirection : VFXSlotEncapsulated
|
|
{
|
|
sealed public override VFXValue DefaultExpression(VFXValue.Mode mode)
|
|
{
|
|
return new VFXValue<Vector3>(Vector3.forward, mode);
|
|
}
|
|
|
|
sealed protected override bool CanConvertFrom(Type type)
|
|
{
|
|
return base.CanConvertFrom(type)
|
|
|| type == typeof(Vector4)
|
|
|| type == typeof(Vector3)
|
|
|| type == typeof(Vector);
|
|
//Doesn't expose cast from float/uint (scalar) due to the automatic normalization
|
|
}
|
|
|
|
sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot)
|
|
{
|
|
if (sourceSlot != null)
|
|
{
|
|
if (sourceSlot.GetType() == typeof(VFXSlotDirection))
|
|
return expression; //avoid multiple normalization
|
|
if (sourceSlot.property.attributes.Is(VFXPropertyAttributes.Type.Normalized))
|
|
return expression; //avoid multiple normalization from Normalize attribute (rarely used for output slot)
|
|
}
|
|
|
|
if (expression.valueType == VFXValueType.Float4)
|
|
expression = VFXOperatorUtility.CastFloat(expression, VFXValueType.Float3);
|
|
|
|
return ApplyPatchExpression(expression);
|
|
}
|
|
|
|
protected override VFXExpression ApplyPatchExpression(VFXExpression expression)
|
|
{
|
|
return VFXOperatorUtility.Normalize(expression);
|
|
}
|
|
}
|
|
}
|