Пример #1
0
        internal static void DeserializeSnippet(string data, AIUI targetUI, Vector2 mousePos, bool regenIds)
        {
            var root        = SerializationMaster.Deserialize(data);
            var snippetType = root.AttributeValue <string>(AttributeName.SnippetType);
            var aiElements  = root.Element(ElementName.AIPart).Elements().ToArray();

            if (snippetType == ElementName.ViewSnippet)
            {
                var uiPart       = root.Element(ElementName.UIPart);
                var referencePos = uiPart.ValueOrDefault(ElementName.ReferencePosition, Vector2.zero);

                var newViews = new List <TopLevelView>(uiPart.Items().Count());

                using (targetUI.undoRedo.bulkOperation)
                {
                    //Deserialize links first so that connections are not lost
                    var linkElements = uiPart.Elements(ElementName.AILinkView).ToArray();
                    DeserializeAILinkViews(linkElements, targetUI, referencePos, mousePos, newViews);

                    var selectorElements = uiPart.Elements(ElementName.SelectorView).ToArray();
                    DeserializeSelectorViews(aiElements, selectorElements, targetUI, referencePos, mousePos, newViews, regenIds);
                }

                targetUI.MultiSelectViews(newViews);
                return;
            }

            var viewElement = root.Element(ElementName.UIPart).Elements().First();

            if (snippetType == ElementName.QualifierSnippet)
            {
                DeserializeQualifier(aiElements[0], viewElement, targetUI);
            }
            else if (snippetType == ElementName.ActionSnippet)
            {
                DeserializeAction(aiElements[0], viewElement, targetUI);
            }
        }
Пример #2
0
        private static void AddSharedItems(GenericMenu menu, AIUI ui, bool allowDelete, Vector2 mousePos)
        {
            if (menu.GetItemCount() > 0)
            {
                menu.AddSeparator(string.Empty);
            }

            if (ui.undoRedo.canUndo)
            {
                menu.AddItem(new GUIContent(string.Concat("Undo (", ctrlOrCmd, " + Shift + Z)")), false, () => ui.undoRedo.Undo());
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(string.Concat("Undo (", ctrlOrCmd, " + Shift + Z)")));
            }

            if (ui.undoRedo.canRedo)
            {
                menu.AddItem(new GUIContent(string.Concat("Redo (", ctrlOrCmd, " + Shift + Y)")), false, () => ui.undoRedo.Redo());
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(string.Concat("Redo (", ctrlOrCmd, " + Shift + Y)")));
            }

            menu.AddSeparator(string.Empty);
            var hasSelection = ui.selectedViews.Count > 0 || ui.currentAction != null || ui.currentQualifier != null || ui.currentSelector != null;

            if (hasSelection)
            {
                menu.AddItem(new GUIContent(string.Concat("Cut (", ctrlOrCmd, " + X)")), false, () => ClipboardService.CutToClipboard(ui));
                menu.AddItem(new GUIContent(string.Concat("Copy (", ctrlOrCmd, " + C)")), false, () => ClipboardService.CopyToClipboard(ui));
                menu.AddItem(new GUIContent(string.Concat("Duplicate (", ctrlOrCmd, " + D)")), false, () => ClipboardService.Duplicate(ui, mousePos));
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(string.Concat("Cut (", ctrlOrCmd, " + X)")));
                menu.AddDisabledItem(new GUIContent(string.Concat("Copy (", ctrlOrCmd, " + C)")));
                menu.AddDisabledItem(new GUIContent(string.Concat("Duplicate (", ctrlOrCmd, " + D)")));
            }

            if (!string.IsNullOrEmpty(EditorGUIUtility.systemCopyBuffer))
            {
                menu.AddItem(new GUIContent(string.Concat("Paste (", ctrlOrCmd, " + V)")), false, () => ClipboardService.PasteFromClipboard(ui, mousePos));
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(string.Concat("Paste (", ctrlOrCmd, " + V)")));
            }

            menu.AddSeparator(string.Empty);
            menu.AddItem(new GUIContent(string.Concat("Select All (", ctrlOrCmd, " + A)")), false, () => ui.MultiSelectViews(ui.canvas.views));

            if (allowDelete)
            {
                menu.AddSeparator(string.Empty);
                if (hasSelection)
                {
                    menu.AddItem(new GUIContent("Delete (Del)"), false, () => ui.RemoveSelected());
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Delete (Del)"));
                }
            }

            menu.ShowAsContext();
        }