コガネブログ

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

【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 self,
        out  byte    r,
        out  byte    g,
        out  byte    b,
        out  byte    a
    )
    {
        r = self.r;
        g = self.g;
        b = self.b;
        a = self.a;
    }
}

使用例

通常

var col = new Color32( 255, 192, 128, 64 );

Deconstruction

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