Absolute#
Math / Absolute
Can Read
Cannot Write
Description#
Removes the sign of every component of a vector, making them all positive
Parameters#
| Name | Description |
|---|---|
| Vector | The vector whose components lose their sign |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Absolute")]
[Category("Math/Absolute")]
[Description("Removes the sign of every component of a vector, making them all positive")]
[Image(typeof(IconAbsolute), ColorTheme.Type.Yellow)]
[Parameter("Vector", "The vector whose components lose their sign")]
[Keywords("Vector", "Positive", "Sign", "Magnitude", "Abs")]
[Serializable]
public class TypeVector3MathAbsolute : TypeVector3
{
[SerializeField] private GetVector3 m_Vector = new GetVector3();
public override Vector3 GetPreview(GameObject source) => Absolute(this.m_Vector.GetPreview(source));
public override Vector3 Get(Args args) => Absolute(this.m_Vector.Get(args));
private static Vector3 Absolute(Vector3 vector)
{
return new Vector3(Mathf.Abs(vector.x), Mathf.Abs(vector.y), Mathf.Abs(vector.z));
}
public override string ToString()
{
return $"Abs({this.m_Vector})";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}