Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/range-primitive.git?path=Range-Primitive/Assets/RangePrimitive

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## Installation

Add **Range Primitive** to your Unity project via Package Manager:

1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/range-primitive.git?path=Range-Primitive%2FAssets%2FRangePrimitive
```

[![pkglnk](https://www.pkglnk.dev/badge/range-primitive.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/range-primitive)

README

Range-Primitive-Unity3D

A primitive type for creating ranges of values in Unity.

openupm

Features

  • range primitive type
  • custom Unity property drawer
  • extension methods for various math operations

Currently supports:

int, float, Vector2, Vector2Int, Vector3, Vector3Int

Usage and Examples

Creation

The range constructor takes two arguments:

  • min: The minimum value (lower boundary) of the range
  • max: The maximum value (upper boundary) of the range

Creating a new range object:

Range<int> myRange = new Range<int>(1, 5);

Creating a new range object as a Unity field:

using RangePrimitive;
using UnityEngine;

public class Foo : MonoBehaviour
{
    [SerializeField]
    private Range<int> myRange;
}

Usage Examples

One-dimensional range:

// Generate 5 equally distributed samples between two values
Range<int> range = new Range<int>(12, 168);

for (int i = 0; i <= 4; i++)
{
    Debug.Log(range.Lerp(i / 4f)); // Output: 12, 51, 90, 129, 168
}

// Get the spread of the defined range
Debug.Log(range.Size()); // Output: 156

// Calculate at what point the value 37 lies between the start and end of the range
Debug.Log(range.InverseLerp(37)); // Output: 0.16

Two-dimensional range:

// Generate 3 random points in a defined 2D area
Range<Vector2> range = new Range<Vector2>(new Vector2(-10, -10), new Vector2(10, 10));

for (int i = 0; i < 3; i++)
{
    Debug.Log(range.Random()); // Example output: (2.59, 4.79), (-4.82, 8.09), (8.21, 9.96)
}

// Check whether a point lies within the defined area
Debug.Log(range.Contains(new Vector2(-8.3f, 15f))); // Output: False

Installation

The package can be installed using OpenUPM

  1. Install the OpenUPM CLI
  2. Run the following command in the command line in your project directory:
openupm add com.iristrummer.range-primitive

Comments

No comments yet. Be the first!