Prefer using SetPixels32() over SetPixels()

Rule ND3207 API Usage / Unity

Color uses floating point [0.0,1.0] per component; Color32 uses a byte [0,255]: 4 times less memory and much faster to work with.

How to fix

If 32bit-RGBA is compatible with your scenario, use SetPixels32() instead.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Prefer using SetPixels32() over SetPixels()</Name>
// <Id>ND3207:PreferUsingSetPixels32OverSetPixels</Id>
warnif count > 0 

let setPixelMethods = Types.WithFullName("UnityEngine.Texture2D")
  .ChildMethods().WithSimpleNameIn("SetPixel","SetPixels").ToHashSetEx()

from m in Application.Methods.UsingAny(setPixelMethods)
let shouldntCall = m.MethodsCalled.Intersect(setPixelMethods)

select new { 
  m, 
  shouldntCall,
  Debt = 15.ToMinutes().ToDebt(),
  Severity = Severity.Major
 }

//<Expl>
// The *{0}* shouldn't call *{1}* but instead 
// should call *SetPixels32()* for performance reasons.
//</Expl>

//<Desc>
// *Color* uses floating point [0.0,1.0] per component; *Color32* uses a
// byte [0,255]: 4 times less memory and much faster to work with.
//</Desc>

//<HowToFix>
// If 32bit-RGBA is compatible with your scenario, use 
// *SetPixels32()* instead.
//</HowToFix>

API Usage / Unity: all 9 items