コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】C# 7.0 新機能の分解(Deconstruction)を Unity のいくつかの型で使用できるようにするパッケージ「Uni Deconstruction」を GitHub に公開しました

はじめに

C# 7.0 新機能の分解(Deconstruction)を
Unity のいくつかの型で使用できるようにするパッケージ
「Uni Deconstruction」を GitHub に公開しました

バージョン

  • Unity 2018.3.11f1

インストール

"com.baba_s.uni_deconstruction": "https://github.com/baba-s/uni-deconstruction.git"

manifest.json に上記の記述を追加します

使用例

KeyValuePair

var table = new Dictionary<int, string>();

foreach ( var ( key, value ) in table )
{
}

Vector2

var ( x, y ) = new Vector2( 1, 2 );

Vector2Int

var ( x, y ) = new Vector2Int( 1, 2 );

Vector3

var ( x, y ) = new Vector3( 1, 2, 3 );
var ( x, y, z ) = new Vector3( 1, 2, 3 );

Vector3Int

var ( x, y, z ) = new Vector3Int( 1, 2, 3 );

Vector4

var ( x, y ) = new Vector4( 1, 2, 3, 4 );
var ( x, y, z ) = new Vector4( 1, 2, 3, 4 );
var ( x, y, z, w ) = new Vector4( 1, 2, 3, 4 );

Color

var ( r, g, b ) = new Color( 1, 0.75f, 0.5f, 0.25f );
var ( r, g, b, a ) = new Color( 1, 0.75f, 0.5f, 0.25f );

Color32

var ( r, g, b ) = new Color32( 255, 192, 128, 64 );
var ( r, g, b, a ) = new Color32( 255, 192, 128, 64 );

Rect

var ( x, y, width, height ) = new Rect( 1, 2, 3, 4 );
var ( position, size ) = new Rect( 1, 2, 3, 4 );

DateTime

var ( year, month, day ) = new DateTime( 2019, 1, 2, 3, 4, 5 );
var ( year, month, day, hour, minute, second ) = new DateTime( 2019, 1, 2, 3, 4, 5 );

null 許容型

var ( hasValue, value ) = new int?();
var ( hasValue, value ) = new int?( 25 );