示例#1
0
    private void CreatePreviewView()
    {
        try
        {
            NoesisXaml       xaml = (NoesisXaml)target;
            FrameworkElement root = xaml.Load() as FrameworkElement;
            _viewPreview = Noesis.GUI.CreateView(root);
            _viewPreview.SetFlags(IsGL() ? 0 : RenderFlags.FlipY);

            NoesisRenderer.RegisterView(_viewPreview, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
            _commands.Clear();
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogException(e);
        }
    }
    private void CreatePreviewGUIView()
    {
        try
        {
            NoesisXaml       xaml  = (NoesisXaml)target;
            FrameworkElement root  = xaml.Load() as FrameworkElement;
            View.RenderFlags flags = DeviceIsD3D() ? View.RenderFlags.FlipY : 0;

            if (root != null)
            {
                _viewPreviewGUI = Noesis.GUI.CreateView(root);
                _viewPreviewGUI.SetFlags(flags);
                NoesisRenderer.RegisterView(_viewPreviewGUI);
            }
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogException(e);
        }
    }
示例#3
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;
    }
示例#4
0
    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();
    }
示例#5
0
    private static NoesisXaml ImportXaml(string filename, bool reimport, bool reload, out bool changed)
    {
        changed = false;
        string     path = Path.ChangeExtension(filename, ".asset");
        NoesisXaml xaml = AssetDatabase.LoadAssetAtPath <NoesisXaml>(path);

        if (xaml == null)
        {
            Log("↔ Create " + filename);
            xaml = (NoesisXaml)ScriptableObject.CreateInstance(typeof(NoesisXaml));
            AssetDatabase.CreateAsset(xaml, path);
        }

        // Unify CRLF,LF between Windows and macOS
        String text = File.ReadAllText(filename);

        text = text.Replace("\r\n", "\n");
        byte[] content = System.Text.Encoding.UTF8.GetBytes(text);

        if (reimport || xaml.content == null || !xaml.content.SequenceEqual(content) || xaml.source != filename)
        {
            Log("→ ImportXaml " + filename);
            changed = true;

            xaml.source  = filename;
            xaml.content = content;

            List <NoesisFont> fonts;
            List <Texture>    textures;
            List <AudioClip>  audios;
            List <NoesisXaml> xamls;
            xaml.UnregisterDependencies();
            ScanDependencies(filename, out fonts, out textures, out audios, out xamls);

            xaml.xamls    = xamls.ToArray();
            xaml.textures = textures.Select(t => new NoesisXaml.Texture {
                uri = AssetDatabase.GetAssetPath(t), texture = t
            }).ToArray();
            xaml.audios = audios.Select(t => new NoesisXaml.Audio {
                uri = AssetDatabase.GetAssetPath(t), audio = t
            }).ToArray();
            xaml.fonts = fonts.ToArray();
            xaml.RegisterDependencies();

            EditorUtility.SetDirty(xaml);
            AssetDatabase.SaveAssets();
            Log("← ImportXaml");
        }
        else
        {
            // XAML didn't change, let's continue scanning its dependencies
            foreach (var dep in xaml.xamls)
            {
                if (dep && File.Exists(dep.source))
                {
                    bool changed_;
                    ImportXaml(dep.source, false, false, out changed_);
                    changed = changed || changed_;
                }
            }

            foreach (var dep in xaml.fonts)
            {
                if (dep && File.Exists(dep.source))
                {
                    ImportFont(dep.source, false, false);
                }
            }
        }

        if (reimport)
        {
            // Show parsing errors in the console
            try
            {
                xaml.Load();

                if (reload)
                {
                    ReloadXaml(xaml.source);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e, xaml);
            }
        }

        return(xaml);
    }
示例#6
0
        void OnSamplesSelectionChanged(object oldValue, object newValue)
        {
#else
        void OnSamplesSelectionChanged(object sender, RoutedPropertyChangedEventArgs <object> args)
        {
            object newValue = args.NewValue;
#endif
            TreeViewItem tvi = (TreeViewItem)newValue;
            if (tvi != null && !tvi.HasItems)
            {
                string sampleName = (string)tvi.Tag;
                if (_lastSample != sampleName)
                {
                    LoadSample(sampleName);
                    _lastSample = sampleName;
                }
            }
        }

        void LoadSample(string sampleName)
        {
            _sampleSelector.IsEnabled = false;

            UIElement sample = (UIElement)LoadXaml(sampleName);

            if (_sampleContainer1.Child == null)
            {
                // Show container 1
                _sampleContainer1.Child    = sample;
                _showContainer1.Completed += OnShowSampleCompleted;
                _showContainer1.Begin();
            }
            else
            {
                // Show container 2
                _sampleContainer2.Child    = sample;
                _showContainer2.Completed += OnShowSampleCompleted;
                _showContainer2.Begin();
            }
        }

        object LoadXaml(string xaml)
        {
#if NOESIS
            NoesisXaml xamlUnity = (NoesisXaml)UnityEngine.Resources.Load(xaml, typeof(NoesisXaml));
            return(xamlUnity.Load());
#else
            string path = "/ControlGallery;component/Assets/NoesisGUI/Samples/ControlGallery/Resources/" + xaml + ".xaml";
            return(Application.LoadComponent(new Uri(path, UriKind.RelativeOrAbsolute)));
#endif
        }

#if NOESIS
        void OnShowSampleCompleted(object sender, TimelineEventArgs e)
#else
        void OnShowSampleCompleted(object sender, EventArgs e)
#endif
        {
            if (_sampleContainer1.Visibility == Visibility.Visible)
            {
                // Container 1 shown
                _showContainer1.Completed -= OnShowSampleCompleted;
                _sampleContainer2.Child    = null;
            }
            else
            {
                // Container 2 shown
                _showContainer2.Completed -= OnShowSampleCompleted;
                _sampleContainer1.Child    = null;
            }

            _sampleSelector.IsEnabled = true;
        }

        void OnSizeChanged(object sender, SizeChangedEventArgs e)
        {
            Size newSize = e.NewSize;

            if (newSize.Width > newSize.Height)
            {
                // Landscape
                _selectorTopContainer.Child  = null;
                _selectorLeftContainer.Child = _selector;
                _selectorTop.Visibility      = Visibility.Collapsed;
                _selectorLeft.Visibility     = Visibility.Visible;
                _selectorTopExpand.IsChecked = false;
                _itemHeight.Height           = newSize.Width * 0.05f;
            }
            else
            {
                // Portrait
                _selectorLeftContainer.Child  = null;
                _selectorTopContainer.Child   = _selector;
                _selectorLeft.Visibility      = Visibility.Collapsed;
                _selectorTop.Visibility       = Visibility.Visible;
                _selectorLeftExpand.IsChecked = false;
                _itemHeight.Height            = newSize.Height * 0.05f;
            }
        }

        void OnSampleOverlayMouseDown(object sender, MouseButtonEventArgs e)
        {
            _selectorLeftExpand.IsChecked = false;
            _selectorTopExpand.IsChecked  = false;
        }

        #region Private members
        ComboBox _styleSelector;
        ResourceDictionary _noesisStyleResources;
        ResourceDictionary _simpleStyleResources;
        ResourceDictionary _windowsStyleResources;

        Grid _selector;
        TreeView _sampleSelector;
        string _lastSample;

        Viewbox _sampleContainer;
        Border _sampleContainer1;
        Border _sampleContainer2;
        Grid _sampleOverlay;

        Storyboard _showContainer1;
        Storyboard _showContainer2;

        Border _selectorTopContainer;
        StackPanel _selectorTop;
        ToggleButton _selectorTopExpand;

        Border _selectorLeftContainer;
        StackPanel _selectorLeft;
        ToggleButton _selectorLeftExpand;

        Decorator _itemHeight;
        #endregion
    }