コガネブログ

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

【C#】配列やリストの分解代入を可能にする Deconstruct

ソースコード using System.Collections.Generic; using System.Linq; public static class IListExt { public static void Deconstruct<T> ( this IList<T> self, out T first, out IList<T> rest ) { first = self.Count > 0 ? self[ 0 ] : default; rest = self.Sk</t></t></t>…

【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…

【C#】Dictionary を foreach で使う時の記述を簡略化する Deconstruction

ソースコード using System.Collections.Generic; public static class KeyValuePairExt { public static void Deconstruct<TKey, TValue> ( this KeyValuePair<TKey, TValue> self, out TKey key, out TValue value ) { key = self.Key; value = self.Value; } } 使用例 通常 foreach ( </tkey,></tkey,>…

【C#】Vector2 の代入を簡略化する Deconstruction

ソースコード using UnityEngine; public static class Vector2Ext { public static void Deconstruct ( this Vector2 self, out float x, out float y ) { x = self.x; y = self.y; } } 使用例 通常 var vec = new Vector2( 1, 2 ); Deconstruction var ( x…

【C#】Vector2Int の代入を簡略化する Deconstruction

ソースコード using UnityEngine; public static class Vector2IntExt { public static void Deconstruct ( this Vector2Int self, out int x, out int y ) { x = self.x; y = self.y; } } 使用例 通常 var vec = new Vector2Int( 1, 2 ); Deconstruction va…

【C#】Vector3 の代入を簡略化する Deconstruction

ソースコード using UnityEngine; public static class Vector3Ext { public static void Deconstruct ( this Vector3 self, out float x, out float y, out float z ) { x = self.x; y = self.y; z = self.z; } } 使用例 通常 var vec = new Vector3( 1, 2,…

【C#】Vector3Int の代入を簡略化する Deconstruction

ソースコード using UnityEngine; public static class Vector3IntExt { public static void Deconstruct ( this Vector3Int self, out int x, out int y, out int z ) { x = self.x; y = self.y; z = self.z; } } 使用例 通常 var vec = new Vector3Int( 1,…

【C#】Vector4 の代入を簡略化する Deconstruction

ソースコード using UnityEngine; public static class Vector4Ext { public static void Deconstruct ( this Vector4 self, out float x, out float y, out float z, out float w ) { x = self.x; y = self.y; z = self.z; w = self.w; } } 使用例 通常 var…

【C#】DateTime を代入する時の記述を簡略化する Deconstruction

ソースコード using System; public static class DateTimeExt { public static void Deconstruct ( this DateTime self, out int year, out int month, out int day ) { year = self.Year; month = self.Month; day = self.Day; } } 使用例 通常 var dt = D…

【C#】Color の代入を簡略化する Deconstruction

ソースコード using UnityEngine; public static class ColorExt { public static void Deconstruct ( this Color self, out float r, out float g, out float b ) { r = self.r; g = self.g; b = self.b; } public static void Deconstruct ( this Color se…

【C#】Color32 の代入を簡略化する Deconstruction

ソースコード using UnityEngine; public static class Color32Ext { public static void Deconstruct ( this Color32 self, out byte r, out byte g, out byte b ) { r = self.r; g = self.g; b = self.b; } public static void Deconstruct ( this Color32…

【C#】Rect の代入を簡略化する Deconstruction

ソースコード using UnityEngine; public static class RectExt { public static void Deconstruct ( this Rect self, out Vector2 position, out Vector2 size ) { position = self.position; size = self.size; } public static void Deconstruct ( this R…

【C#】null 許容型を代入する時の記述を簡略化する Deconstruction

ソースコード public static class NullableExt { public static void Deconstruct<T> ( this T? self, out bool hasValue, out T value ) where T : struct { hasValue = self.HasValue; value = self ?? default; } } 使用例 var now = DateTime.Now; var ( h</t>…