Inside Bounds#
Random / Inside Bounds
Can Read
Cannot Write
Description#
A random point placed anywhere inside a box defined by a center and a size
Parameters#
| Name | Description |
|---|---|
| Center | The position at the middle of the box |
| Size | How wide, tall and deep the box is |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
using Random = UnityEngine.Random;
namespace VisualScript.Runtime
{
[Get]
[Title("Inside Bounds")]
[Category("Random/Inside Bounds")]
[Description("A random point placed anywhere inside a box defined by a center and a size")]
[Image(typeof(IconDice), ColorTheme.Type.Yellow, typeof(BadgeCubeSolid))]
[Parameter("Center", "The position at the middle of the box")]
[Parameter("Size", "How wide, tall and deep the box is")]
[Keywords("Dice", "Vector", "Point", "Position", "Box", "Area", "Volume", "Spawn")]
[Serializable]
public class TypeVector3RandomInsideBounds : TypeVector3
{
[SerializeField] private GetVector3 m_Center = new GetVector3();
[SerializeField] private GetVector3 m_Size = new GetVector3(Vector3.one);
public override Vector3 Get(Args args)
{
Vector3 center = this.m_Center.Get(args);
Vector3 extents = this.m_Size.Get(args) * 0.5f;
return new Vector3(
center.x + Random.Range(-extents.x, extents.x),
center.y + Random.Range(-extents.y, extents.y),
center.z + Random.Range(-extents.z, extents.z)
);
}
public override string ToString()
{
return $"Inside Bounds ({this.m_Center}, {this.m_Size})";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnUpdate;
}
}