Esempio n. 1
0
        public void RemoveAt(int index)
        {
            if (nodeData == null)
            {
                return;
            }
            if (nodeData.Length == 1)
            {
                nodeData = null;
                return;
            }

            NodeBlock[] tempArray = new NodeBlock[nodeData.Length - 1];
            int         idx       = 0;

            for (int ix = 0; ix < nodeData.Length; ++ix)
            {
                if (ix == index)
                {
                    continue;
                }
                tempArray[idx] = nodeData[ix];
                ++idx;
            }

            nodeData = new NodeBlock[tempArray.Length];
            for (int ix = 0; ix < nodeData.Length; ++ix)
            {
                nodeData[ix] = tempArray[ix];
            }
        }
Esempio n. 2
0
        public void Remove(NodeBlock block)
        {
            int index = 0;

            while (!nodeData[index].id.Equals(block.id))
            {
                ++index;
            }

            RemoveAt(index);
        }
Esempio n. 3
0
        public void AddNodeItem(GameObject itemPrefab, NodeBlock nodeData)
        {
            // Create Block on to block pane.
            GameObject    newObj        = Instantiate(itemPrefab);
            RectTransform rectTransform = newObj.GetComponent <RectTransform>();

            rectTransform.SetParent(blockPane);
            rectTransform.position   = nodeData.position;
            rectTransform.localScale = Vector3.one;
            GraphItem graphItem = newObj.GetComponent <GraphItem>();

            graphItem.BlockID = nodeData.id;
            graphItem.SetBlockTitle(nodeData.title);
            graphItem.SetItemData(nodeData.value);

            if (nodeData.nodeType == NodeType.SWITCH)
            {
                SwitchBranchItem switchNode = graphItem as SwitchBranchItem;
                switchNode.SetSwitchName(nodeData.name);
                switchNode.SetBlockCount(nodeData.switchBlockCount);

                for (int ix = 1; ix < nodeData.switchBlockCount + 1; ++ix)
                {
                    if (switchNode.executePoints[ix] is ExecuteCasePoint)
                    {
                        ExecuteCasePoint casePoint = switchNode.executePoints[ix] as ExecuteCasePoint;
                        casePoint.CaseValue = nodeData.switchBlockValues[ix - 1];
                    }
                }
            }

            else if (nodeData.nodeType == NodeType.VARIABLE)
            {
                VariableItem variableNode = graphItem as VariableItem;
                variableNode.SetBlockName(nodeData.name);
                variableNode.SetBlockName(nodeData.name);
                variableNode.SetOperatorType(nodeData.variableOperator);
            }

            else if (nodeData.nodeType == NodeType.IF)
            {
                IFBranchItem ifNode = graphItem as IFBranchItem;
                ifNode.SetBlockName(nodeData.name);
                ifNode.SetOpParamType((int)ifNode.GetOpTypeFromString(nodeData.variableOperator));
                ifNode.SetRParamValue(nodeData.value);
                ifNode.SetLParamType((int)nodeData.ifBranchType);
            }

            // Add Block Information to Block Diagram Manager.
            WorkspaceManager.Instance.AddBlock(graphItem);
        }
Esempio n. 4
0
        public void Add(NodeBlock block)
        {
            if (nodeData == null)
            {
                nodeData    = new NodeBlock[1];
                nodeData[0] = block;
                return;
            }

            NodeBlock[] tempArray = new NodeBlock[nodeData.Length];
            for (int ix = 0; ix < tempArray.Length; ++ix)
            {
                tempArray[ix] = nodeData[ix];
            }

            nodeData = new NodeBlock[nodeData.Length + 1];
            for (int ix = 0; ix < tempArray.Length; ++ix)
            {
                nodeData[ix] = tempArray[ix];
            }

            nodeData[tempArray.Length] = block;
        }
Esempio n. 5
0
 public void BlockRemove(NodeBlock block)
 {
     blockArray.Remove(block);
 }
Esempio n. 6
0
 // Wrapper Functions for block array.
 public void BlockAdd(NodeBlock block)
 {
     blockArray.Add(block);
 }
Esempio n. 7
0
        public static ProjectFormat GetSaveFormat(List <GraphItem> locatedItemList, List <GraphLine> locatedLineList, string projectName = "")
        {
            ProjectFormat project = new ProjectFormat();

            project.projectName = projectName;

            project.blockArray = new NodeBlockArray();
            for (int ix = 0; ix < locatedItemList.Count; ++ix)
            {
                NodeBlock block = new NodeBlock();
                block.nodeType = locatedItemList[ix].GetNodeType;
                block.id       = locatedItemList[ix].BlockID;
                block.title    = locatedItemList[ix].GetBlockTitle;
                block.value    = locatedItemList[ix].GetItemData() as string;
                block.position = locatedItemList[ix].GetComponent <RectTransform>().position;

                NodeType nodeType = locatedItemList[ix].GetNodeType;

                if (nodeType == NodeType.SWITCH)
                {
                    SwitchBranchItem switchNode = locatedItemList[ix] as SwitchBranchItem;
                    block.switchBlockCount = switchNode.GetBlockCount;
                    block.switchBranchType = switchNode.GetSwitchType;
                    block.name             = switchNode.GetSwitchName;
                    for (int jx = 0; jx < switchNode.GetBlockCount; ++jx)
                    {
                        ExecuteCasePoint casePoint = switchNode.executePoints[jx + 1] as ExecuteCasePoint;
                        block.switchBlockValues.Add(casePoint.CaseValue);
                    }
                }

                else if (nodeType == NodeType.VARIABLE)
                {
                    VariableItem variableNode = locatedItemList[ix] as VariableItem;
                    block.variableOperator = variableNode.GetOperatorType.ToString();
                    block.name             = variableNode.GetBlockName;
                }

                else if (nodeType == NodeType.IF)
                {
                    IFBranchItem    ifNode = locatedItemList[ix] as IFBranchItem;
                    BranchCondition data   = ifNode.GetIFBranchData();
                    block.name             = data.nameField;
                    block.value            = data.rParameter;
                    block.ifBranchType     = data.lParamType;
                    block.variableOperator = ifNode.GetStringFromOpType(data.opParameter);
                }

                project.BlockAdd(block);
            }

            project.lineArray = new LineBlockArray();
            for (int ix = 0; ix < locatedLineList.Count; ++ix)
            {
                int leftBlockID        = locatedLineList[ix].GetLeftExecutePointInfo.blockID;
                int leftExecutePointID = locatedLineList[ix].GetLeftExecutePointInfo.executePointID;
                int rightBlockID       = locatedLineList[ix].GetRightExecutePointInfo.blockID;

                LineBlock line = new LineBlock(leftBlockID, leftExecutePointID, rightBlockID);
                project.LineAdd(line);
            }

            return(project);
        }