Pewarta Proxy

๐Ÿ“‹ Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

โš™๏ธ Pengaturan Proxy Target

Skip to content
ovskyPublic

About

Ultimate Serializable Array for Unity / C#

Topics

Resources

Stars

23 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TArray Logo

โบ๏ธ TArray โ€“ High-Performance 2D Serializable Arrays for Unity

The ultimate lightweight struct-based array solution for C# / Unity

Stars License Unity Package


โœจ What's TArray?

TArray is an ultra-compact, production-ready 2D array solution for Unity that combines blazing speed with full serialization support. Unlike traditional array wrappers implemented as classes, TArray is a value-type struct (just 180 lines of code) that provides:

  • ๐Ÿš€ Lightning-fast performance โ€“ Struct-based with zero allocation overhead
  • ๐Ÿ“ True 2D access โ€“ Intuitive array[x, y] syntax with bounds checking
  • ๐Ÿ’พ Full serialization โ€“ Works seamlessly with Unity's Inspector and SaveGame systems
  • ๐Ÿ”„ Type-safe casting โ€“ Convert between array types without data loss
  • ๐ŸŽจ Custom Inspector โ€“ Visual grid editor for all serializable types
  • ๐Ÿ”— LINQ integration โ€“ Full support for OrderBy, Select, Where, etc.

Perfect for grids, tile maps, game boards, 2D data structures, and any multidimensional data management.


๐ŸŽฏ Key Features

Multiple Declaration Styles

TArray<int> grid = new TArray<int>(5, 5);          // Classic
TArray<int> grid = new int[5, 5];                  // Array-like
TArray<int> grid = new (5, 5);                     // Modern C#

Intuitive Get/Set Operations

int value = grid[2, 2];                            // Index access
int value = grid.Get(2, 2);                        // Method access
grid[2, 2] = 42;
grid.Set(2, 2, 42);                                // Chainable
grid.Set(2, 2, 42, resize: true);                  // Auto-resize

Type-Free Operations

ITArray flexArray = new TArray<int>(5, 5);
flexArray = flexArray.Cast<string>();             // Type conversion
TArray<string> stringGrid = flexArray;             // Typed retrieval

Full LINQ Support

TArray<Enemy> enemies = new TArray<Enemy>(10, 10);

// Sort by property
var sorted = enemies.Array.OrderBy(e => e.Health).ToArray();

// Filter and transform
var bosses = enemies.Array.Where(e => e.IsBoss).ToArray();

Array Manipulation

grid.Resize(10, 10);                               // Resize with data preservation
grid.AddSize(2, 3);                                // Expand grid
grid.AddRow(newXValues, newYValues);               // Append rows

๐Ÿ“ฆ Installation

Via Unity Package Manager (Recommended)

Method 1: Git URL

Toolbar โ†’ Window/Package Manager โ†’ ๏ผ‹ โ†’ Add package from Git URL
https://github.com/ovsky/TArray.git#upm

Method 2: Manifest Edit

// packages/manifest.json
{
  "dependencies": {
    "com.ovsky.tarray": "https://github.com/ovsky/TArray.git#upm"
  }
}

Method 3: Tarball

# Linux
wget https://github.com/ovsky/TArray/tarball/upm -O ovsky.tarray-upm.tgz

# Windows
start https://github.com/ovsky/TArray/tarball/upm

Then in Package Manager: ๏ผ‹ โ†’ Add package from tarball โ†’ select the .tgz file


๐Ÿš€ Quick Start

Basic Usage

using Extensions;

// Create a 5ร—5 integer grid
TArray<int> grid = new TArray<int>(5, 5);

// Access elements
grid[0, 0] = 100;
int val = grid[2, 3];

// Query and transform with LINQ
var flattened = grid.Array;
var sorted = grid.Array.OrderBy(x => x);

Working with Custom Types

[Serializable]
public class Cell
{
    public int health;
    public bool walkable;
}

TArray<Cell> terrain = new TArray<Cell>(16, 16);
terrain[8, 8].walkable = false;

// Full LINQ support
var walkableCells = terrain.Array
    .Where(c => c.walkable)
    .OrderBy(c => c.health)
    .ToArray();

Inspector Integration

TArray fields appear in the Inspector with a custom grid editor:

  • See all values at a glance
  • Edit directly in the grid
  • Supports integers, booleans, GameObjects, strings, and custom types
  • Auto-resize capability

๐ŸŽจ Editor Preview

Integer Grid TArray Integer Preview

GameObject References TArray GameObject Preview

Boolean Grid TArray Boolean Preview


๐Ÿ“Š Architecture

Core Structure

Packages/
  manifest.json              UPM metadata

Assets/Lab7/
  package.json               Package info (v1.1.0, com.ovsky.tarray)
  TArray/
    Scripts/
      Runtime/
        TArray.cs            โ†’ Core struct (ITArray interface, indexing, operations)
      Editor/
        TArrayDrawer.cs      โ†’ Custom Inspector grid editor

How It Works

TArray uses a flat backing array with intelligent 2D indexing:

// Internal representation: 1D array stored linearly
data = [val[0,0], val[1,0], val[2,0], val[0,1], val[1,1], val[2,1], ...]

// Index calculation (row-major):
index = (width * y) + x

This design gives you:

  • โœ… Single allocation (cache-friendly)
  • โœ… Struct value semantics (stack-allocated, no GC pressure)
  • โœ… Full Unity serialization
  • โœ… LINQ compatibility (via .Array property)

๐Ÿ’ก Use Cases

  • ๐ŸŽฎ Game Boards โ€“ Chess, checkers, turn-based tactics
  • ๐Ÿ—บ๏ธ Tile Maps โ€“ Level layouts, terrain grids, procedural generation
  • ๐Ÿ“ˆ Data Grids โ€“ Spreadsheets, simulation grids, sensor arrays
  • ๐ŸŽฏ Spatial Indexing โ€“ Collision detection, spatial partitioning
  • ๐ŸŽจ Pixel Data โ€“ Image processing, texture manipulation

๐Ÿ”ง API Reference

Properties

Property Description
Size Returns Vector2Int with grid dimensions (width, height)
Length Total number of elements
Array Access underlying 1D array for LINQ operations
Matrix Convert to native C# 2D array T[,]

Methods

Method Description
Get(x, y) Retrieve value with bounds checking
Set(x, y, value) Set value and return for chaining
Set(x, y, value, resize) Set with optional auto-resize
Cast<T1>() Convert to different type
Resize(x, y, force) Change grid dimensions
AddSize(x, y) Expand grid by offset
AddRow(xValues, yValues) Append rows

Operators

TArray<int> grid = new int[5, 5];          // T[] implicit operator
TArray<int> grid = new (5, 5);             // T[,] implicit operator
int[] flat = grid;                         // Implicit to T[]
int[,] matrix = grid;                      // Implicit to T[,]

๐Ÿ›ก๏ธ Safety Features

Built-in Bounds Checking (Development builds):

#if UNITY_EDITOR || DEVELOPMENT_BUILD
if (x < 0 || x >= size.x || y < 0 || y >= size.y)
{
    Debug.LogError($"TArray[{x}, {y}] is out of bounds of size: {size}");
    return default;
}
#endif

Zero-Allocation Indexer (Release builds):

// Optimized path with no safety checks
public T this[int x, int y]
{
    get => data[(size.x * y) + x];
    set => data[(size.x * y) + x] = value;
}

๐Ÿ“ License

Copyright (C) 2023 - Przemysล‚aw Orล‚owski

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR IMPLIED.

Licensed under the MIT License โ€“ see LICENSE file for full text.

๐Ÿ™‹ FAQ

Q: How does TArray compare to native int[,]?
A: TArray serializes natively in Unity (no custom handlers needed), provides a custom Inspector, and has identical performance. The trade-off is minimalโ€”you get Editor tooling for free.

Q: Can I use TArray with nested structures?
A: Yes! Any serializable type worksโ€”custom classes, structs, GameObjects, and even lists (as elements).

Q: What's the memory overhead?
A: Just two fields: Vector2Int size (8 bytes) + reference to T[] data. No wrapper overhead beyond the native array.

Q: Does it work with Save/Load systems?
A: Yes. Full [Serializable] support means it works with Unity's serialization, JSON, and binary formatters.


Made with โค๏ธ by Lab7 Studio

GitHub โ€ข Issues โ€ข Discussions

About

Ultimate Serializable Array for Unity / C#

Topics

Resources

Stars

23 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages