Dynamically fill ResourceDictionary in Unity
Posted: 15 Jul 2017, 15:05
Hello, I've just started using Noesis in the past week and have had some success and a few hangups.
I'm trying to load a lot of ImageBrush resources into a ResourceDictionary from a cs class. I'd load them manually, but it's around a thousand images.
I've got this working in VS just fine with the following
The equivalent of loading the Bitmap is what's got me confused on the Noesis side. I've seen references to TextureSource, haven't had any success with that though. I'd like to be able to load the pngs from a uri relative to the script if possible.
Thanks!
I'm trying to load a lot of ImageBrush resources into a ResourceDictionary from a cs class. I'd load them manually, but it's around a thousand images.
I've got this working in VS just fine with the following
Code: Select all
#if UNITY_5_3_OR_NEWER
#define NOESIS
#endif
#if NOESIS
using Noesis;
#else
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
#endif
namespace UIResources
{
public partial class Icons : ResourceDictionary
{
private const float _scale = .156f;
public Icons()
{
InitializeComponent();
int count = 500;
for (int file = 1; file < 35; file++)
{
for (int col = 0; col < 6; col++)
{
for (int row = 0; row < 6; row++)
{
#if NOESIS
#else
ImageBrush newBrush = new ImageBrush();
newBrush.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox;
newBrush.Stretch = Stretch.Fill;
newBrush.ImageSource = new BitmapImage(new Uri(String.Format("../../Assets/Resources/icons/dragitem{0}.png", file), UriKind.RelativeOrAbsolute));
newBrush.Viewbox = new Rect(col * _scale, row * _scale, _scale, _scale);
Add("icon" + (int)(count), newBrush);
count++;
#endif
}
}
}
;
}
#if NOESIS
private void InitializeComponent()
{
Noesis.GUI.LoadComponent(this, "Assets/NoesisGUI/Interface/Resources/Icons.xaml");
}
#endif
}
}
Thanks!