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);
                }
            }
        }
    }
Beispiel #2
0
 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);
         }
     }
 }
    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;
    }
Beispiel #5
0
    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;
    }
Beispiel #6
0
    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");
        }
    }