public override void drawOnImage(ref Image image, BoundingBox boundingBox) { BitmapDecal decal; if (!BitmapDecalCache.Instance.decals.TryGetValue(_url, out decal)) return; Image decalImage = new Image(decal.image); Color32 color = new Color32(_red, _green, _blue, _alpha); decalImage.recolor(Global.Black32, color, false, true); decalImage.rotateImage(_rotation); if (_mirror) decalImage.flipHorizontally(); image.blendImage(decalImage, _blendMethod, _position, _alphaOption, _textureAlpha, boundingBox); }
public override void drawRight(TextureEditGUI gui) { if (BitmapDecalCache.Instance.monoSheets.Count == 0) return; Color contentColor = GUI.contentColor; GUI.backgroundColor = Global.BackgroundColor; _scrollPos = GUILayout.BeginScrollView(_scrollPos, GUI.skin.box, GUILayout.MinWidth(250), GUILayout.ExpandHeight(true)); GUILayout.Label("Decal Sheets"); GUILayout.Space(3); int oldSelectedSheet = _selectedSheet; for (int i = 0; i < BitmapDecalCache.Instance.monoSheets.Count; ++i) { if (i == _selectedSheet) GUI.contentColor = Global.SelectedColor; else GUI.contentColor = Global.NotSelectedColor; if (GUILayout.Button(BitmapDecalCache.Instance.monoSheets[i].displayName, GUILayout.ExpandWidth(true))) _selectedSheet = i; } if (_selectedSheet != oldSelectedSheet) { if (_textures != null) { for (int i = 0; i < _textures.Count; ++i) { UnityEngine.Object.Destroy(_textures[i]); } _textures = null; } if (_selectedDecal >= BitmapDecalCache.Instance.monoSheets[_selectedSheet].decals.Count) _selectedDecal = 0; } GUILayout.Space(10); GUILayout.Label("Decals"); GUILayout.Space(3); if (_textures == null) { _textures = new List<Texture2D>(); for (int i = 0; i < BitmapDecalCache.Instance.monoSheets[_selectedSheet].decals.Count; ++i) { Image image = new Image(BitmapDecalCache.Instance.monoSheets[_selectedSheet].decals[i].image); image.recolor(Global.Black32, Global.White32, false, false); Texture2D texture = new Texture2D(image.width, image.height, TextureFormat.ARGB32, false); texture.SetPixels32(image.pixels); texture.Apply(); _textures.Add(texture); } } int oldSelectedDecal = _selectedDecal; int x = 0; GUILayout.BeginHorizontal(); for (int i = 0; i < _textures.Count; ++i) { if (i == _selectedDecal) { GUI.backgroundColor = Color.yellow; if (GUILayout.Button(_textures[i], GUILayout.Width(_textures[i].width + 4), GUILayout.Height(_textures[i].height + 4))) _selectedDecal = i; GUI.backgroundColor = Global.BackgroundColor; } else { if (GUILayout.Button(_textures[i], GUILayout.Width(_textures[i].width + 4), GUILayout.Height(_textures[i].height + 4))) _selectedDecal = i; } x += _textures[i].width + 5; if (i < (_textures.Count - 1)) { if (x > 0 && (x + _textures[i+1].width) > 200) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); x = 0; } } } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); GUI.contentColor = contentColor; if (oldSelectedSheet != _selectedSheet || oldSelectedDecal != _selectedDecal) { _imBitmapMonoDecal._url = BitmapDecalCache.Instance.monoSheets[_selectedSheet].decals[_selectedDecal].url; gui.setRemakePreview(); } }
protected void drawDecalOnImage(ref Image image, ref Image normalMap, string _url, BoundingBox boundingBox) { BitmapDecal decal; if (!BitmapDecalCache.Instance.decals.TryGetValue(_url, out decal)) return; drawOnImage(ref image, boundingBox); if (_normalOption == NormalOption.USE_BACKGROUND) return; Image backgroundImage = new Image(normalMap.width, normalMap.height); Color32 backgroudColor = new Color32(127, 127, 127, 0); backgroundImage.fill(backgroudColor); Color32 color = Global.Gray32; if (_normalOption == NormalOption.RAISE_TEXT) color = Global.White32; if (_normalOption == NormalOption.LOWER_TEXT) color = Global.Black32; Image decalImage = new Image(decal.image); decalImage.recolor(Global.Black32, color, false, true); decalImage.rotateImage(_rotation); if (_mirror) decalImage.flipHorizontally(); backgroundImage.blendImage(decalImage, BlendMethod.PIXEL, _position, AlphaOption.OVERWRITE, 255, boundingBox); Image normalMapImage = backgroundImage.createNormalMap(_normalScale); if (image.width == normalMap.width && image.height == normalMap.height) normalMap.rescale(image.width, image.height); normalMap.overlay(normalMapImage, backgroundImage, 128, boundingBox); }