/// <summary> /// copies a specific channel(s) from an image to this image /// </summary> /// <param name="source">source image to copy from</param> /// <param name="channel">channel(s) to copy</param> public void CopyChannel(Texture source, TextureChannelFlags channel) { for (int x = 0; x < _width; x++) { for (int y = 0; y < _height; y++) { float percentX = Convert.ToSingle(x) / Convert.ToSingle(_width); float percentY = Convert.ToSingle(y) / Convert.ToSingle(_height); int sourceX = Convert.ToInt32(MathF.Floor(percentX * source.Width)); int sourceY = Convert.ToInt32(MathF.Floor(percentY * source.Height)); if ((channel & TextureChannelFlags.R) != 0) { this._pixels[(y * _width) + x].R = source.Pixels[(sourceY * source.Width) + sourceX].R; } if ((channel & TextureChannelFlags.G) != 0) { this._pixels[(y * _width) + x].G = source.Pixels[(sourceY * source.Width) + sourceX].G; } if ((channel & TextureChannelFlags.B) != 0) { this._pixels[(y * _width) + x].B = source.Pixels[(sourceY * source.Width) + sourceX].B; } if ((channel & TextureChannelFlags.A) != 0) { this._pixels[(y * _width) + x].A = source.Pixels[(sourceY * source.Width) + sourceX].A; } } } }
private void OnEnable() { _sourceType = EditorPrefsExt.GetEnum(_sourceTypeKey, TextureSourceType.None); _materialId = EditorPrefs.GetInt(_materialIdKey, 0); _propertyName = EditorPrefs.GetString(_propertyNameKey, string.Empty); _filterMode = Mathf.Clamp(EditorPrefs.GetInt(_filterModeKey, 1), 0, 1); _customTexture = EditorPrefsExt.GetAsset <Texture2D>(_customTextureKey); _repeating = EditorPrefs.GetBool(_repeatingKey, false); _color = EditorPrefsExt.GetColor(_colorKey, Color.white); _channelFlag = EditorPrefsExt.GetEnum(_channelFlagKey, TextureChannelFlags.RGBA); }
public static TextureChannelFlags Invert(this TextureChannelFlags state, TextureChannelFlags flag) { return(state ^ flag); }
public static TextureChannelFlags Reset(this TextureChannelFlags state, TextureChannelFlags flag) { return(state & ~flag); }
public static TextureChannelFlags Set(this TextureChannelFlags state, TextureChannelFlags flag) { return(state | flag); }
public static bool Has(this TextureChannelFlags state, TextureChannelFlags flag) { return((state & flag) != TextureChannelFlags.None); }