Exemple #1
0
        public static bool GetClipboardObject <T>(out T obj)
        {
            string clipboardStr = GUIUtility.systemCopyBuffer;

            obj = default(T);
            if (clipboardStr.StartsWith("/\\nd/\\") && clipboardStr.EndsWith("/\\nd/\\"))
            {
                try
                {
                    clipboardStr = clipboardStr.Substring(6, clipboardStr.Length - 12);
                    IFormatter   formatter = new BinaryFormatter();
                    byte[]       buffer    = Convert.FromBase64String(clipboardStr);
                    MemoryStream stream    = new MemoryStream(buffer);
                    obj = (T)formatter.Deserialize(stream);
                    stream.Flush();
                    stream.Close();
                    return(true);
                }
                catch (Exception e)
                {
                    BarrageProject.LogError(string.Format("Deserialize to object fail , {0}", e.Message));
                    return(false);
                }
            }
            return(false);
        }
 private void OnDebugSpellCardHandler()
 {
     if (_curSelectedNode == null)
     {
         BarrageProject.LogError("Debug fail!Please select a node first");
         return;
     }
     // 当前选择的节点必须是defineSpellCard
     if (_curSelectedNode.GetNodeType() != NodeType.DefineSpellCard)
     {
         BarrageProject.LogError("Debug fail!Please select a node with type define spell card");
         return;
     }
     BarrageProject.SetDebugSpellCardNode(_curSelectedNode);
     OnPackClickHandler();
     BarrageProject.ClearDebugSpellCardMode();
 }
        public void OnPasteClickHandler()
        {
            if (_curSelectedNode == null)
            {
                BarrageProject.LogWarning("Paste fail!Please select a node first");
                return;
            }
            NodeData nd = default(NodeData);

            if (!Clipboard.GetClipboardObject <NodeData>(out nd))
            {
                return;
            }
            if (nd == null)
            {
                BarrageProject.LogWarning("Paste fail!There is no data in clipboard");
                return;
            }
            BaseNode parent;
            int      insertIndex;

            GetParentNodeAndInsertIndexByInsertMode(_curInsertMode, _curSelectedNode, out parent, out insertIndex);
            NodeType childType = (NodeType)nd.type;

            if (!parent.CheckCanInsertChildNode(childType))
            {
                string msg = string.Format("can not insert {0} as child of {1}", childType, parent.GetNodeType());
                BarrageProject.LogError(msg);
                return;
            }
            BaseNode childNode = NodeManager.CreateNodesByNodeDatas(nd);

            if (parent.InsertChildNode(childNode, insertIndex))
            {
                parent.Expand(true);
                childNode.OnSelected(true);
                OpPasteHM hm = new OpPasteHM
                {
                    parentIndex   = NodeManager.GetNodeIndex(parent),
                    childIndex    = parent.GetChildIndex(childNode),
                    pasteNodeData = nd,
                };
                Undo.AddToUndoTask(hm);
            }
        }
        private void TryInsertNode(NodeType nodeType)
        {
            //if (!BarrageProject.IsProjectLoaded())
            //{
            //    BarrageProject.LogError("Please load a project before you want to insert");
            //    return;
            //}
            if (_curSelectedNode == null)
            {
                BarrageProject.LogError("Please select a node before you want to insert");
                return;
            }
            BaseNode parentNode  = null;
            BaseNode newNode     = null;
            int      insertIndex = -1;

            GetParentNodeAndInsertIndexByInsertMode(_curInsertMode, _curSelectedNode, out parentNode, out insertIndex);
            if (parentNode != null)
            {
                // 先判断是否可以插入子节点
                if (!parentNode.CheckCanInsertChildNode(nodeType))
                {
                    string msg = string.Format("can not insert {0} as child of {1}", nodeType, parentNode.GetNodeType());
                    BarrageProject.LogError(msg);
                    return;
                }
                // 插入子节点
                newNode = NodeManager.CreateNode(nodeType);
                newNode.SetAttrsDefaultValues();
                parentNode.InsertChildNode(newNode, insertIndex);
                // 设置操作记录
                OpInsertHM hm = new OpInsertHM
                {
                    parentIndex    = NodeManager.GetNodeIndex(parentNode),
                    childIndex     = parentNode.GetChildIndex(newNode),
                    insertNodeData = NodeManager.SaveAsNodeData(newNode, true),
                };
                Undo.AddToUndoTask(hm);
                // 展开父节点
                parentNode.Expand(true);
                newNode.OnSelected(true);
                SetContentToNode(newNode);
            }
        }
        private void OnDebugStageHandler()
        {
            if (_curSelectedNode == null)
            {
                BarrageProject.LogError("Debug fail!Please select a node first");
                return;
            }
            // 当前选择节点的父节点必须是stage
            BaseNode parentNode = _curSelectedNode.GetParentNode();

            if (parentNode == null || parentNode.GetNodeType() != NodeType.Stage)
            {
                BarrageProject.LogError("Debug fail!Please select a node which is direct child of stage");
                return;
            }
            BarrageProject.SetDebugStageNode(parentNode, _curSelectedNode);
            OnPackClickHandler();
            BarrageProject.ClearDebugStageNode();
        }
Exemple #6
0
 public static bool CopyToClipboard(object obj)
 {
     try
     {
         IFormatter   formatter = new BinaryFormatter();
         MemoryStream stream    = new MemoryStream();
         formatter.Serialize(stream, obj);
         stream.Position = 0;
         byte[] buffer = new byte[stream.Length];
         stream.Read(buffer, 0, buffer.Length);
         stream.Flush();
         stream.Close();
         string str = Convert.ToBase64String(buffer);
         str = "/\\nd/\\" + str + "/\\nd/\\";
         GUIUtility.systemCopyBuffer = str;
         return(true);
     }
     catch (Exception e)
     {
         BarrageProject.LogError(string.Format("Serialize object fail , {0}", e.Message));
         return(false);
     }
 }