示例#1
0
    public static void Init()
    {
        if (!_initialized)
        {
            _initialized = true;

            // Cache this because Unity is crashing internally if we access NoesisSettings from C++ callbacks
            _settings = NoesisSettings.Get();

            Noesis.GUI.Init();
            SetLicense(_settings.licenseName, _settings.licenseKey);

            RegisterLog();
            RegisterError();
            RegisterProviders();

            SetFontFallback();

            LoadApplicationResources();

            Noesis.GUI.SetSoftwareKeyboardCallback(SoftwareKeyboard);
            Noesis.GUI.SetCursorCallback(UpdateCursor);
            Noesis.GUI.SetOpenUrlCallback(OpenUrl);
            Noesis.GUI.SetPlayAudioCallback(PlayAudio);
        }
    }
示例#2
0
    public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
    {
        if (CanRender())
        {
            if (_viewPreviewGUI == null)
            {
                CreatePreviewGUIView();
            }

            if (_viewPreviewGUI != null && _viewPreviewGUI.Content != null)
            {
                if (NoesisSettings.Get().debugImporter)
                {
                    Debug.Log("↔ RenderStaticPreview " + assetPath);
                }

                RenderTexture rt = RenderPreview(_viewPreviewGUI, width, height);

                if (rt != null)
                {
                    RenderTexture prev = RenderTexture.active;
                    RenderTexture.active = rt;

                    Texture2D tex = new Texture2D(width, height);
                    tex.ReadPixels(new UnityEngine.Rect(0, 0, width, height), 0, 0);
                    tex.Apply(true);

                    RenderTexture.active = prev;
                    return(tex);
                }
            }
        }

        return(null);
    }
示例#3
0
    private bool CanRender()
    {
        NoesisXaml xaml = (NoesisXaml)target;

        return(xaml != null && xaml.CanLoad() && NoesisSettings.Get().previewEnabled&&
               !UnityEditorInternal.InternalEditorUtility.inBatchMode);
    }
示例#4
0
 private static void Log(string message)
 {
     if (NoesisSettings.Get().debugImporter)
     {
         Debug.Log(message);
     }
 }
示例#5
0
    void SetRenderSettings()
    {
        NoesisSettings settings = NoesisSettings.Get();

        bool linearRendering = QualitySettings.activeColorSpace == ColorSpace.Linear;

        int offscreenWidth  = (int)settings.offscreenTextureSize.x;
        int offscreenHeight = (int)settings.offscreenTextureSize.y;
        int sampleCount     = QualitySettings.antiAliasing;

        uint offscreenDefaultNumSurfaces = settings.offscreenInitSurfaces;
        uint offscreenMaxNumSurfaces     = settings.offscreenMaxSurfaces;
        uint glyphCacheMeshThreshold     = settings.glyphMeshThreshold;

        int glyphCacheTextureWidth  = 1024;
        int glyphCacheTextureHeight = 1024;

        switch (settings.glyphTextureSize)
        {
        case NoesisSettings.TextureSize._256x256:
        {
            glyphCacheTextureWidth  = 256;
            glyphCacheTextureHeight = 256;
            break;
        }

        case NoesisSettings.TextureSize._512x512:
        {
            glyphCacheTextureWidth  = 512;
            glyphCacheTextureHeight = 512;
            break;
        }

        case NoesisSettings.TextureSize._1024x1024:
        {
            glyphCacheTextureWidth  = 1024;
            glyphCacheTextureHeight = 1024;
            break;
        }

        case NoesisSettings.TextureSize._2048x2048:
        {
            glyphCacheTextureWidth  = 2048;
            glyphCacheTextureHeight = 2048;
            break;
        }

        case NoesisSettings.TextureSize._4096x4096:
        {
            glyphCacheTextureWidth  = 4096;
            glyphCacheTextureHeight = 4096;
            break;
        }
        }

        Noesis_RendererSettings(linearRendering, offscreenWidth, offscreenHeight, sampleCount,
                                offscreenDefaultNumSurfaces, offscreenMaxNumSurfaces, glyphCacheTextureWidth,
                                glyphCacheTextureHeight, glyphCacheMeshThreshold);
    }
    public static void Init()
    {
        if (!_initialized)
        {
            _initialized = true;

            Noesis.GUI.Init();

            // Cache this because Unity is crashing internally if we access NoesisSettings from C++ callbacks
            _settings = NoesisSettings.Get();

            Noesis.GUI.SoftwareKeyboard = new UnitySoftwareKeyboard();
            RegisterProviders();
            RegisterLog();
            LoadApplicationResources();
        }
    }
示例#7
0
    private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        if (UnityEditorInternal.InternalEditorUtility.inBatchMode)
        {
            return;
        }

        if (NoesisSettings.Get().postprocessorEnabled)
        {
            List <string> assets = new List <string>();
            assets.AddRange(importedAssets);
            assets.AddRange(movedAssets);

            // Do fonts first because XAML depends on the generated .asset
            foreach (var asset in assets)
            {
                if (HasExtension(asset, ".ttf") || HasExtension(asset, ".otf"))
                {
                    ImportFont(asset);
                }
            }

            // First, create all .asset resources to allow dependencies between XAMLs
            foreach (var asset in importedAssets)
            {
                if (HasExtension(asset, ".xaml"))
                {
                    CreateXamlAsset(asset);
                }
            }

            // And now, fully import each XAML
            foreach (var asset in importedAssets)
            {
                if (HasExtension(asset, ".xaml"))
                {
                    ImportXaml(asset);
                }
            }

            AssetDatabase.SaveAssets();
        }
    }
    private IEnumerator UpdateVersion()
    {
        GoogleAnalyticsHelper.LogEvent("Install", version_, 0);
        progress_ = 0.10f;

        state_ = "Upgrading project";
        yield return(null);

        Upgrade(localVersion_);
        progress_ = 0.20f;

        state_ = "Updating version";
        yield return(null);

        NoesisVersion.SetCached(version_);
        progress_ = 0.35f;

        state_ = "Creating default settings";
        yield return(null);

        NoesisSettings.Get();
        progress_ = 0.40f;

        state_ = "Extracting documentation...\n";
        yield return(null);

        ExtractDocumentation();
        progress_ = 0.60f;

        state_ = "Importing assets...\n";
        yield return(null);

        NoesisPostprocessor.ImportAllAssets();
        progress_ = 0.90f;

        state_ = "Opening Welcome Window...\n";
        yield return(null);

        EditorWindow.GetWindow(typeof(NoesisWelcome), true, "Welcome to NoesisGUI!");
        progress_ = 1.0f;

        Debug.Log("NoesisGUI v" + version_ + " successfully installed");
    }
示例#9
0
    private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        if (NoesisSettings.IsNoesisEnabled())
        {
            EditorApplication.CallbackFunction d = null;

            // Delay the import process to have all texture assets ready
            d = () =>
            {
                EditorApplication.update -= d;

                string[] assets = importedAssets.Concat(movedAssets).ToArray();
                ImportAssets(assets, NoesisSettings.Get().hotReloading, (progress, asset) =>
                             EditorUtility.DisplayProgressBar("Import XAMLs", asset, progress));
                EditorUtility.ClearProgressBar();
            };

            EditorApplication.update += d;
        }
    }
    public static SettingsProvider CreateNoesisSettingsProvider()
    {
        var provider = new SettingsProvider("Project/NoesisSettings", SettingsScope.Project)
        {
            label      = "NoesisGUI",
            guiHandler = (searchContext) =>
            {
                OnInspectorGUI(new SerializedObject(NoesisSettings.Get()));
            },

            keywords = new HashSet <string>(new[] { "License Name", "License Key", "Application Resources",
                                                    "Default Font", "Default Font Size", "Default Font Weight", "Default Font Stretch", "Default Font Style",
                                                    "Glyph Texture Size", "Offscreen Sample Count", "Offscreen Init Surfaces", "Offscreen Max Surfaces",
                                                    "Linear Rendering", "Preview Enabled", "Hot Reloading", "Debug Importer", "Log Verbosity",
                                                    "AppStarting", "Arrow", "ArrowCD", "Cross", "Hand", "Help", "IBeam", "No", "None", "Pen", "ScrollAll",
                                                    "ScrollE", "ScrollN", "ScrollNE", "ScrollNS", "ScrollNW", "ScrollS", "ScrollSE", "ScrollSW",
                                                    "ScrollW", "ScrollWE", "SizeAll", "SizeNESW", "SizeNS", "SizeNWSE", "SizeWE", "UpArrow", "Wait" })
        };

        return(provider);
    }
示例#11
0
    private void OnPostprocessTexture(Texture2D texture)
    {
        // Although our samples use the label 'Noesis' it seems to be ignored by Unity when the package is being imported
        if (AssetDatabase.GetLabels(assetImporter).Contains("Noesis") || assetPath.StartsWith("Assets/NoesisGUI/Samples"))
        {
            Color[] c = texture.GetPixels(0);

            // NoesisGUI needs premultipled alpha
            if (QualitySettings.activeColorSpace == ColorSpace.Linear)
            {
                for (int i = 0; i < c.Length; i++)
                {
                    c[i].r = Mathf.LinearToGammaSpace(Mathf.GammaToLinearSpace(c[i].r) * c[i].a);
                    c[i].g = Mathf.LinearToGammaSpace(Mathf.GammaToLinearSpace(c[i].g) * c[i].a);
                    c[i].b = Mathf.LinearToGammaSpace(Mathf.GammaToLinearSpace(c[i].b) * c[i].a);
                }
            }
            else
            {
                for (int i = 0; i < c.Length; i++)
                {
                    c[i].r = c[i].r * c[i].a;
                    c[i].g = c[i].g * c[i].a;
                    c[i].b = c[i].b * c[i].a;
                }
            }

            // Set new content and make the texture unreadable at runtime
            texture.SetPixels(c, 0);
            texture.Apply(true, true);
        }

        // Hot reloading of texture
        if (NoesisUnity.Initialized && NoesisSettings.Get().hotReloading)
        {
            ReloadTexture(assetPath, texture);
        }
    }
示例#12
0
    void SetRenderSettings()
    {
        NoesisSettings settings = NoesisSettings.Get();

        bool linearRendering = false;

        switch (settings.linearRendering)
        {
        case NoesisSettings.LinearRendering._SamesAsUnity:
        {
            linearRendering = QualitySettings.activeColorSpace == ColorSpace.Linear;
            break;
        }

        case NoesisSettings.LinearRendering._Enabled:
        {
            linearRendering = true;
            break;
        }

        case NoesisSettings.LinearRendering._Disabled:
        {
            linearRendering = false;
            break;
        }
        }

        int sampleCount = 1;

        switch (settings.offscreenSampleCount)
        {
        case NoesisSettings.OffscreenSampleCount._SameAsUnity:
        {
            sampleCount = QualitySettings.antiAliasing;
            break;
        }

        case NoesisSettings.OffscreenSampleCount._1x:
        {
            sampleCount = 1;
            break;
        }

        case NoesisSettings.OffscreenSampleCount._2x:
        {
            sampleCount = 2;
            break;
        }

        case NoesisSettings.OffscreenSampleCount._4x:
        {
            sampleCount = 4;
            break;
        }

        case NoesisSettings.OffscreenSampleCount._8x:
        {
            sampleCount = 8;
            break;
        }
        }

        uint offscreenDefaultNumSurfaces = settings.offscreenInitSurfaces;
        uint offscreenMaxNumSurfaces     = settings.offscreenMaxSurfaces;
        uint glyphCacheMeshThreshold     = settings.glyphMeshThreshold;

        int glyphCacheTextureWidth  = 1024;
        int glyphCacheTextureHeight = 1024;

        switch (settings.glyphTextureSize)
        {
        case NoesisSettings.TextureSize._256x256:
        {
            glyphCacheTextureWidth  = 256;
            glyphCacheTextureHeight = 256;
            break;
        }

        case NoesisSettings.TextureSize._512x512:
        {
            glyphCacheTextureWidth  = 512;
            glyphCacheTextureHeight = 512;
            break;
        }

        case NoesisSettings.TextureSize._1024x1024:
        {
            glyphCacheTextureWidth  = 1024;
            glyphCacheTextureHeight = 1024;
            break;
        }

        case NoesisSettings.TextureSize._2048x2048:
        {
            glyphCacheTextureWidth  = 2048;
            glyphCacheTextureHeight = 2048;
            break;
        }

        case NoesisSettings.TextureSize._4096x4096:
        {
            glyphCacheTextureWidth  = 4096;
            glyphCacheTextureHeight = 4096;
            break;
        }
        }

        int colorGlyphCacheTextureWidth  = 0;
        int colorGlyphCacheTextureHeight = 0;

        switch (settings.colorGlyphTextureSize)
        {
        case NoesisSettings.ColorTextureSize._Auto:
        {
            colorGlyphCacheTextureWidth  = 0;
            colorGlyphCacheTextureHeight = 0;
            break;
        }

        case NoesisSettings.ColorTextureSize._256x256:
        {
            colorGlyphCacheTextureWidth  = 256;
            colorGlyphCacheTextureHeight = 256;
            break;
        }

        case NoesisSettings.ColorTextureSize._512x512:
        {
            colorGlyphCacheTextureWidth  = 512;
            colorGlyphCacheTextureHeight = 512;
            break;
        }

        case NoesisSettings.ColorTextureSize._1024x1024:
        {
            colorGlyphCacheTextureWidth  = 1024;
            colorGlyphCacheTextureHeight = 1024;
            break;
        }

        case NoesisSettings.ColorTextureSize._2048x2048:
        {
            colorGlyphCacheTextureWidth  = 2048;
            colorGlyphCacheTextureHeight = 2048;
            break;
        }

        case NoesisSettings.ColorTextureSize._4096x4096:
        {
            colorGlyphCacheTextureWidth  = 4096;
            colorGlyphCacheTextureHeight = 4096;
            break;
        }
        }

        Noesis_RendererSettings(linearRendering, sampleCount, offscreenDefaultNumSurfaces,
                                offscreenMaxNumSurfaces, glyphCacheTextureWidth, glyphCacheTextureHeight,
                                colorGlyphCacheTextureWidth, colorGlyphCacheTextureHeight, glyphCacheMeshThreshold);
    }
示例#13
0
    private bool CanRender()
    {
        NoesisXaml xaml = (NoesisXaml)target;

        return(NoesisSettings.IsNoesisEnabled() && xaml != null && xaml.CanLoad() && NoesisSettings.Get().previewEnabled);
    }
示例#14
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");
        }
    }
示例#15
0
 static void OpenSettings()
 {
     Selection.activeObject = NoesisSettings.Get();
 }
    private static void UpdateCursor(View view, Noesis.Cursor cursor)
    {
        NoesisSettings settings = NoesisSettings.Get();

        switch (cursor)
        {
        case Noesis.Cursor.AppStarting:
            UnityEngine.Cursor.SetCursor(settings.AppStarting.Texture, settings.AppStarting.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.Arrow:
            UnityEngine.Cursor.SetCursor(settings.Arrow.Texture, settings.Arrow.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ArrowCD:
            UnityEngine.Cursor.SetCursor(settings.ArrowCD.Texture, settings.ArrowCD.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.Cross:
            UnityEngine.Cursor.SetCursor(settings.Cross.Texture, settings.Cross.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.Hand:
            UnityEngine.Cursor.SetCursor(settings.Hand.Texture, settings.Hand.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.Help:
            UnityEngine.Cursor.SetCursor(settings.Help.Texture, settings.Help.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.IBeam:
            UnityEngine.Cursor.SetCursor(settings.IBeam.Texture, settings.IBeam.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.No:
            UnityEngine.Cursor.SetCursor(settings.No.Texture, settings.No.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.None:
            UnityEngine.Cursor.SetCursor(settings.None.Texture, settings.None.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.Pen:
            UnityEngine.Cursor.SetCursor(settings.Pen.Texture, settings.Pen.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollAll:
            UnityEngine.Cursor.SetCursor(settings.ScrollAll.Texture, settings.ScrollAll.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollE:
            UnityEngine.Cursor.SetCursor(settings.ScrollE.Texture, settings.ScrollE.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollN:
            UnityEngine.Cursor.SetCursor(settings.ScrollN.Texture, settings.ScrollN.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollNE:
            UnityEngine.Cursor.SetCursor(settings.ScrollNE.Texture, settings.ScrollNE.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollNS:
            UnityEngine.Cursor.SetCursor(settings.ScrollNS.Texture, settings.ScrollNS.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollNW:
            UnityEngine.Cursor.SetCursor(settings.ScrollNW.Texture, settings.ScrollNW.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollS:
            UnityEngine.Cursor.SetCursor(settings.ScrollS.Texture, settings.ScrollS.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollSE:
            UnityEngine.Cursor.SetCursor(settings.ScrollSE.Texture, settings.ScrollSE.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollSW:
            UnityEngine.Cursor.SetCursor(settings.ScrollSW.Texture, settings.ScrollSW.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollW:
            UnityEngine.Cursor.SetCursor(settings.ScrollW.Texture, settings.ScrollW.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.ScrollWE:
            UnityEngine.Cursor.SetCursor(settings.ScrollWE.Texture, settings.ScrollWE.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.SizeAll:
            UnityEngine.Cursor.SetCursor(settings.SizeAll.Texture, settings.SizeAll.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.SizeNESW:
            UnityEngine.Cursor.SetCursor(settings.SizeNESW.Texture, settings.SizeNESW.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.SizeNS:
            UnityEngine.Cursor.SetCursor(settings.SizeNS.Texture, settings.SizeNS.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.SizeNWSE:
            UnityEngine.Cursor.SetCursor(settings.SizeNWSE.Texture, settings.SizeNWSE.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.SizeWE:
            UnityEngine.Cursor.SetCursor(settings.SizeWE.Texture, settings.SizeWE.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.UpArrow:
            UnityEngine.Cursor.SetCursor(settings.UpArrow.Texture, settings.UpArrow.HotSpot, CursorMode.Auto);
            break;

        case Noesis.Cursor.Wait:
            UnityEngine.Cursor.SetCursor(settings.Wait.Texture, settings.Wait.HotSpot, CursorMode.Auto);
            break;
        }
    }
 private bool CanRender()
 {
     return(NoesisSettings.IsNoesisEnabled() && NoesisSettings.Get().previewEnabled&& _faces.Count > 0);
 }
示例#18
0
    private static void CheckVersion()
    {
        EditorApplication.update -= CheckVersion;

        if (!UnityEditorInternal.InternalEditorUtility.inBatchMode)
        {
            string localVersion = NoesisVersion.GetCached();
            string version      = NoesisVersion.Get();

            // Remove the file that indicates Noesis package is being installed
            AssetDatabase.DeleteAsset("Assets/NoesisGUI/Plugins/Editor/installing");

            // Detect if /Library is being recreated
            string noesisFile             = Path.Combine(Application.dataPath, "../Library/noesis");
            bool   libraryFolderRecreated = !File.Exists(noesisFile);
            if (libraryFolderRecreated)
            {
                File.Create(noesisFile).Dispose();
            }

            if (localVersion != version && version != "0.0.0")
            {
                if (NoesisVersion.RestartNeeded())
                {
                    Debug.LogWarning("Please restart Unity to reload NoesisGUI native plugin! " +
                                     "If error persists remove 'Assets/NoesisGUI/Plugins' and reimport again.");
                    return;
                }

                string title;

                if (localVersion != "")
                {
                    title = "Upgrading NoesisGUI " + localVersion + " -> " + version;
                }
                else
                {
                    title = "Installing NoesisGUI " + version;
                }

                EditorUtility.DisplayProgressBar(title, "", 0.0f);
                GoogleAnalyticsHelper.LogEvent("Install", version, 0);

                EditorUtility.DisplayProgressBar(title, "Upgrading project", 0.10f);
                Upgrade(localVersion);

                EditorUtility.DisplayProgressBar(title, "Updating version", 0.20f);
                NoesisVersion.SetCached(version);

                EditorUtility.DisplayProgressBar(title, "Creating default settings", 0.35f);
                NoesisSettings.Get();

                EditorUtility.DisplayProgressBar(title, "Extracting documentation...", 0.40f);
                ExtractTar("NoesisGUI/Doc.tar", "/../NoesisDoc", "/../NoesisDoc");

                EditorUtility.DisplayProgressBar(title, "Extracting blend samples...", 0.55f);
                ExtractTar("NoesisGUI/Samples/Samples-blend.tar", "/..", "/../Blend");

                NoesisPostprocessor.ImportAllAssets((progress, asset) =>
                {
                    EditorUtility.DisplayProgressBar(title, asset, 0.60f + progress * 0.40f);
                });

                EditorApplication.update += ShowWelcomeWindow;
                EditorUtility.ClearProgressBar();

                Debug.Log("NoesisGUI v" + version + " successfully installed");
            }
            else if (libraryFolderRecreated)
            {
                NoesisPostprocessor.ImportAllAssets();
            }
        }
    }