public void PasteDisplayObjects()
    {
        if (GlobalData.CurrentCopyDisplayObjects.Count == 0)
        {
            return;
        }
        List <Element> sourceList = GlobalData.CurrentCopyDisplayObjects;
        Vector2        leftTop    = DisplayObjectUtil.GetCopyDisplayObjectsLeftTop(sourceList);
        Vector2        mousePos   = Vector2.zero;

        if (Utils.IsPointOverGameObject(containerScrollView))
        {
            mousePos = Utils.GetRealPosition(Input.mousePosition);
        }
        Vector2        delta          = mousePos - leftTop;
        int            count          = sourceList.Count;
        string         moduleName     = GlobalData.CurrentModule;
        List <Element> copiedElements = new List <Element>();

        for (int idx = 0; idx < count; ++idx)
        {
            Element sourceElement = sourceList[idx];
            string  imageUrl      = DisplayObjectUtil.GetImageUrl(moduleName, sourceElement.Name);
            string  elementName   = DisplayObjectUtil.GetCanUseElementName(sourceElement.Name, imageUrl);
            Vector2 pos           = new Vector2(sourceElement.X + delta.x, sourceElement.Y + delta.y);
            Vector2 size          = new Vector2(sourceElement.Width, sourceElement.Height);
            Element element       = new Element {
                Name    = elementName,
                X       = pos.x,
                Y       = pos.y,
                Width   = size.x,
                Height  = size.y,
                Visible = true
            };
            DisplayObjectUtil.AddDisplayObjectBehavior(moduleName, element, imageUrl);
            copiedElements.Add(element);
        }

        HistoryManager.Do(BehaviorFactory.GetCopyDisplayObjectsBehavior(moduleName, copiedElements), true);
    }
Exemple #2
0
    public static Behavior GetAddDisplayObjectBehavior(string moduleName,
                                                       string elementName,
                                                       string imageUrl,
                                                       Vector2 pos,
                                                       Vector2 size,
                                                       CombineType combineType = CombineType.Independent)
    {
        Element element = new Element {
            Name    = elementName,
            X       = Element.ConvertX(pos.x),
            Y       = Element.ConvertY(pos.y),
            Width   = size.x,
            Height  = size.y,
            Visible = true
        };

        return(new Behavior(isRedo => DisplayObjectUtil.AddDisplayObjectBehavior(moduleName, element, imageUrl),
                            isReUndo => DisplayObjectUtil.RemoveDisplayObjectBehavior(moduleName, element.Name),
                            BehaviorType.AddDisplayObject,
                            true,
                            combineType));
    }