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.
 
 
 
 
 

72 lines
2.9 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UnityEditor.VFX.Operator
{
[VFXHelpURL("Operator-GetTextureDimensions")]
[VFXInfo(name = "Get Texture Dimensions", category = "Sampling")]
class TextureDimensions : VFXOperatorDynamicType
{
protected override IEnumerable<VFXPropertyWithValue> inputProperties
{
get
{
yield return new VFXPropertyWithValue(new VFXProperty(GetOperandType(), "tex", new TooltipAttribute("Sets the texture to get dimensions from.")));
}
}
protected override IEnumerable<VFXPropertyWithValue> outputProperties
{
get
{
yield return new VFXPropertyWithValue(new VFXProperty(typeof(uint), "width", new TooltipAttribute("Outputs the width of the texture.")));
yield return new VFXPropertyWithValue(new VFXProperty(typeof(uint), "height", new TooltipAttribute("Outputs the height of the texture.")));
if (GetOperandType() == typeof(Texture3D))
yield return new VFXPropertyWithValue(new VFXProperty(typeof(uint), "depth", new TooltipAttribute("Outputs the depth of the texture.")));
else if (GetOperandType() == typeof(Texture2DArray) || GetOperandType() == typeof(CubemapArray))
yield return new VFXPropertyWithValue(new VFXProperty(typeof(uint), "count", new TooltipAttribute("Outputs the texture count of the texture array.")));
}
}
public override string name => "Get " + GetOperandType().Name + " Dimensions";
public override IEnumerable<Type> validTypes => new[]
{
typeof(Texture2D),
typeof(Texture3D),
typeof(Texture2DArray),
typeof(Cubemap),
typeof(CubemapArray)
};
protected override Type defaultValueType => typeof(Texture2D);
public override IEnumerable<int> staticSlotIndex => Enumerable.Empty<int>();
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
{
if (GetOperandType() == typeof(Texture3D)
|| GetOperandType() == typeof(Texture2DArray)
|| GetOperandType() == typeof(CubemapArray))
{
return new VFXExpression[]
{
new VFXExpressionTextureWidth(inputExpression[0]),
new VFXExpressionTextureHeight(inputExpression[0]),
new VFXExpressionTextureDepth(inputExpression[0]),
};
}
else
{
return new VFXExpression[]
{
new VFXExpressionTextureWidth(inputExpression[0]),
new VFXExpressionTextureHeight(inputExpression[0]),
};
}
}
}
}