private static void ScanFont(string uri, ref List <NoesisFont> fonts) { int index = uri.IndexOf('#'); if (index != -1) { string folder = uri.Substring(0, index); if (Directory.Exists(folder)) { string family = uri.Substring(index + 1); var files = Directory.GetFiles(folder).Where(s => IsFont(s)); foreach (var font in files) { bool hasFamily = false; using (FileStream file = File.Open(font, FileMode.Open, FileAccess.Read)) { hasFamily = NoesisUnity.HasFamily(file, family); } if (hasFamily) { fonts.Add(ImportFont(font, false, false)); } } } } }
private static void FindFamilyNames(string directory, string family, HashSet <NoesisFont> fonts) { try { var files = Directory.GetFiles(directory) .Where(s => s.EndsWith(".ttf", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".otf", StringComparison.OrdinalIgnoreCase)); foreach (var filename in files) { using (FileStream file = File.Open(filename, FileMode.Open)) { if (NoesisUnity.HasFamily(file, family)) { string uri = Path.ChangeExtension(NormalizePath(filename), ".asset"); string guid = AssetDatabase.AssetPathToGUID(uri); if (!String.IsNullOrEmpty(guid)) { NoesisFont f = AssetDatabase.LoadAssetAtPath <NoesisFont>(uri); if (f != null) { fonts.Add(f); } } } } } } catch (System.Exception) {} }
public void RegisterFont() { if (target != null) { NoesisFont font = (NoesisFont)target; if (font.source != null) { NoesisUnity.Init(); using (MemoryStream stream = new MemoryStream(font.content)) { _index = 0; _faces.Clear(); Noesis.GUI.EnumFontFaces(stream, (index_, family_, weight_, style_, stretch_) => { _faces.Add(new Face() { index = index_, family = family_, weight = weight_, style = style_, stretch = stretch_ }); }); } if (_faces.Count > 0) { NoesisFontProvider.instance.Register(font); } } } }
private static void ReloadXaml(string uri) { Log("ReloadXaml" + uri); NoesisUnity.MuteLog(); NoesisXamlProvider.instance.ReloadXaml(uri); NoesisUnity.UnmuteLog(); }
public void RegisterDependencies() { if (!_registered && CanLoad()) { NoesisUnity.Init(); _RegisterDependencies(); _registered = true; } }
public void RegisterFont() { if (target != null) { NoesisFont font = (NoesisFont)target; if (font.source != null) { NoesisUnity.Init(); RegisterFont(font); } } }
public static NoesisSettings Get() { if (_settings == null) { // Theme loading tries to load Noesis library and this is a bad point to allow that _noesisEnabled = false; _settings = Resources.Load <NoesisSettings>("NoesisSettings"); #if UNITY_EDITOR if (_settings == null) { if (Directory.GetFiles(Application.dataPath, "NoesisSettings.asset", SearchOption.AllDirectories).Length != 0) { // In rare situations (for example when upgrading the project to a new version of Unity), // NoesisSettings exists but Unity doesn't load it because it is not registered yet. // In this case, we return a default instance without caching it return((NoesisSettings)ScriptableObject.CreateInstance(typeof(NoesisSettings))); } _settings = (NoesisSettings)ScriptableObject.CreateInstance(typeof(NoesisSettings)); _settings.applicationResources = UnityEditor.AssetDatabase.LoadAssetAtPath <NoesisXaml>("Assets/NoesisGUI/Theme/NoesisTheme.DarkBlue.asset"); _settings.defaultFont = UnityEditor.AssetDatabase.LoadAssetAtPath <NoesisFont>("Assets/NoesisGUI/Theme/Fonts/PT Root UI_Regular.asset"); Directory.CreateDirectory(Application.dataPath + "/Resources"); UnityEditor.AssetDatabase.CreateAsset(_settings, "Assets/Resources/NoesisSettings.asset"); UnityEditor.AssetDatabase.SaveAssets(); Debug.Log("A new settings file was created in 'Assets/Resources/NoesisSettings.assets'. Please move it to a different 'Resources' folder if needed"); } else { NoesisUnity.SetLicense(_settings.licenseName, _settings.licenseKey); } #endif _noesisEnabled = true; } return(_settings); }
private static void ImportXaml(string filename) { NoesisUnity.Init(); string path = Path.ChangeExtension(filename, ".asset"); var xaml = AssetDatabase.LoadAssetAtPath <NoesisXaml>(path); using (FileStream file = File.Open(filename, FileMode.Open)) { string directory = Path.GetDirectoryName(filename); ImportXaml(xaml, directory, file); } // The following steps (updating thumbnail and loading XAML for logging errors) must be // done after all XAMLs are imported to avoid dependency order issues. It is also a good // idea doing this outside OnPostprocessAllAssets to avoid continuously crashing Unity if // Load() raises an unexception exception. That is the reason we use a deferred call. EditorApplication.CallbackFunction d = null; d = () => { // TODO: if Unity is compiling scripts (EditorApplication.isCompiling) we should wait EditorApplication.update -= d; try { xaml.Load(); EditorUtility.SetDirty(xaml); } catch (Exception e) { UnityEngine.Debug.LogError(e.Message, xaml); } }; EditorApplication.update += d; }
private static void ImportXaml(string filename) { NoesisUnity.Init(); string path = Path.ChangeExtension(filename, ".asset"); NoesisXaml xaml = AssetDatabase.LoadAssetAtPath <NoesisXaml>(path); xaml.source = filename; using (FileStream file = File.Open(filename, FileMode.Open)) { string directory = Path.GetDirectoryName(filename); ImportXaml(xaml, directory, file); } // It is important to show XAML error messages at the time the user is editing. // We force here a Load() with that purpose. We do it deferred though to avoid continuously // crashing Unity if Load() raises an unexception exception EditorApplication.CallbackFunction d = null; d = () => { EditorApplication.update -= d; try { xaml.Load(); } catch (Exception e) { UnityEngine.Debug.LogError("<b>" + filename + "</b>: " + e.Message, xaml); } // Update thumbnail EditorUtility.SetDirty(xaml); }; EditorApplication.update += d; }
private void CreatePreviewGUIView() { // Avoid logging parse errors twice by muting them when generating thumbnails NoesisUnity.MuteLog(); try { NoesisXaml xaml = (NoesisXaml)target; FrameworkElement root = xaml.Load() as FrameworkElement; _viewPreviewGUI = Noesis.GUI.CreateView(root); _viewPreviewGUI.SetFlags(IsGL() ? 0 : RenderFlags.FlipY); NoesisRenderer.RegisterView(_viewPreviewGUI, _commands); Graphics.ExecuteCommandBuffer(_commands); _commands.Clear(); } catch (System.Exception e) { UnityEngine.Debug.LogException(e); } NoesisUnity.UnmuteLog(); }
private static void ImportAssets(string[] assets, bool reload, UpdateProgress d) { int numFonts = assets.Count(asset => asset.StartsWith("Assets/") && IsFont(asset)); int numXamls = assets.Count(asset => asset.StartsWith("Assets/") && IsXaml(asset)); int numAssets = numFonts + numXamls; if (numAssets > 0) { Log("→ Import assets (XAMLs: " + numXamls + " Fonts: " + numFonts + ")"); float delta = 1.0f / numAssets; float progress = 0.0f; if (numXamls > 0) { NoesisUnity.Init(); // Theme NoesisXaml theme = NoesisSettings.Get().applicationResources; if (theme != null) { Log("Scanning for theme changes..."); bool changed; ImportXaml(theme.source, false, false, out changed); if (changed) { Log("↔ Reload ApplicationResources"); NoesisUnity.LoadApplicationResources(); } } } foreach (var asset in assets) { // Make sure read-only folders from Package Manager are not processed if (asset.StartsWith("Assets/")) { try { if (IsFont(asset)) { ImportFont(asset, true, reload); } else if (IsXaml(asset)) { ImportXaml(asset, true, reload); } } catch (Exception e) { Debug.LogException(e); } if (d != null && (IsFont(asset) || IsXaml(asset))) { d(progress, asset); progress += delta; } } } Log("← Import assets"); } }
private void InitializeComponent() { NoesisUnity.LoadComponent(this); }
public void OnSave() { NoesisUnity.SetLicense(licenseName, licenseKey); }