public static void CompileToXML(ProjectFormat projectFormat, List <GraphItem> locatedItemList, IComparer <GraphItem> comparer) { locatedItemList.Sort(comparer); XMLProject project = new XMLProject(); foreach (GraphItem node in locatedItemList) { if (node.GetNodeType == NodeType.SWITCH) { SwitchBranchItem switchNode = node as SwitchBranchItem; project.AddNode(switchNode.GetXMLSwitchData()); } else if (node.GetNodeType == NodeType.VARIABLE) { VariableItem variableNode = node as VariableItem; project.AddNode(variableNode.GetXMLVariableData()); } else if (node.GetNodeType == NodeType.IF) { IFBranchItem ifNode = node as IFBranchItem; project.AddNode(ifNode.GetXMLIFData()); } else { project.AddNode(node.GetXMLNormalData()); } } XMLSerialize <XMLProject>(project, Application.dataPath + "/Data/TestProject.xml"); }
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); }
private void OnDisable() { content.sizeDelta = new Vector2(content.sizeDelta.x, defaultHeight); scrollRect.verticalScrollbar.value = 1f; nodeTitleInput.onValueChanged.RemoveAllListeners(); switchTypeDropdown.onValueChanged.RemoveAllListeners(); foreach (CaseBlock block in caseBlocks) { block.RemoveAllListeners(); } switchNode = null; }
public void AddNodeItem(GameObject itemPrefab, GraphItem node, Vector3 nodePos, int blockID) { // Create Block on to block pane. GameObject newObj = Instantiate(itemPrefab); RectTransform rectTransform = newObj.GetComponent <RectTransform>(); rectTransform.SetParent(blockPane); rectTransform.position = nodePos; rectTransform.localScale = Vector3.one; GraphItem graphItem = newObj.GetComponent <GraphItem>(); graphItem.BlockID = blockID; graphItem.SetBlockTitle(node.GetBlockTitle); graphItem.SetItemData(node.GetItemData()); if (node.GetNodeType == NodeType.SWITCH) { SwitchBranchItem switchNode = graphItem as SwitchBranchItem; SwitchBranchItem givenSwitchNode = node as SwitchBranchItem; switchNode.SetBlockCount(givenSwitchNode.GetBlockCount); switchNode.SetSwitchType(givenSwitchNode.GetSwitchType); switchNode.SetSwitchName(givenSwitchNode.GetSwitchName); for (int ix = 1; ix < givenSwitchNode.GetBlockCount + 1; ++ix) { if (switchNode.executePoints[ix] is ExecuteCasePoint) { ExecuteCasePoint casePoint = switchNode.executePoints[ix] as ExecuteCasePoint; casePoint.CaseValue = (givenSwitchNode.executePoints[ix] as ExecuteCasePoint).CaseValue; } } } else if (node.GetNodeType == NodeType.VARIABLE) { VariableItem variableNode = graphItem as VariableItem; VariableItem givenVariableNode = node as VariableItem; variableNode.SetBlockName(givenVariableNode.GetBlockName); variableNode.SetOperatorType(givenVariableNode.GetOperatorType); } // Add Block Information to Block Diagram Manager. WorkspaceManager.Instance.AddBlock(graphItem); }
public void ShowProperty(GraphItem node) { gameObject.SetActive(true); nodeTitleInput.text = node.GetBlockTitle; switchNode = node as SwitchBranchItem; nodeTitleInput.onValueChanged.AddListener(switchNode.SetBlockTitle); nodeTypeText.text = node.GetNodeType.ToString(); nodeIDText.text = node.BlockID.ToString(); switchTypeDropdown.value = (int)switchNode.GetSwitchType; switchTypeDropdown.onValueChanged.AddListener(switchNode.SetSwitchType); TurnOffAll(); int blockCount = (node as SwitchBranchItem).GetBlockCount; TurnOnWithCount(blockCount); scrollRect.content.sizeDelta = new Vector2(content.sizeDelta.x, defaultHeight + blockCount * itemHeight * 3); scrollRect.verticalScrollbar.value = 1f; // 0번은 ExecutePointLeft. // ExecutePointRight에 대해서만 처리하면 되기 때문에 index 1번 부터 순회. for (int ix = 0; ix < blockCount; ++ix) { ExecutePoint point = node.executePoints[ix + 1]; int nextID = point.GetLineData != null ? point.GetLineData.GetRightExecutePointInfo.blockID : -1; if (point is ExecuteCasePoint) { ExecuteCasePoint casePoint = point as ExecuteCasePoint; caseBlocks[ix].SetProperty(casePoint.CaseValue, nextID.ToString()); caseBlocks[ix].valueInput.onValueChanged.AddListener(casePoint.SetCaseValue); } } ExecuteDefaultPoint defaultPoint = node.executePoints[node.executePoints.Length - 1] as ExecuteDefaultPoint; int defaultNextID = defaultPoint.GetLineData != null ? defaultPoint.GetLineData.GetRightExecutePointInfo.blockID : -1; defaultBlock.SetProperty(defaultNextID.ToString()); }
public override void ShowPopup(GraphItem targetItem = null) { base.ShowPopup(targetItem); switchItem = targetItem as SwitchBranchItem; if (switchItem) { BranchCondition[] conditionData = switchItem.GetConditionData(); for (int ix = 0; ix < conditionData.Length; ++ix) { if (ix < 2) { switchBlocks[ix].SetDataToComponent(conditionData[ix]); continue; } InsertBlock(conditionData[ix]); } } }
private void CreateLines(LineBlockArray lineData) { if (lineData.Length == -1) { return; } for (int ix = 0; ix < lineData.Length; ++ix) { GraphItem leftItem = GetGraphItem(lineData[ix].left.blockID); GraphItem rightItem = GetGraphItem(lineData[ix].right.blockID); if (leftItem.GetNodeType == NodeType.SWITCH) { if (switchCounts.Count == 0) { switchCounts.Add(new SwitchCount() { nodeID = leftItem.BlockID, count = 1 }); } else if (switchCounts.Count == 1 && !switchCounts[0].nodeID.Equals(leftItem.BlockID)) { switchCounts.Add(new SwitchCount() { nodeID = leftItem.BlockID, count = 1 }); } else { bool isProcessed = false; foreach (SwitchCount item in switchCounts) { if (item.nodeID.Equals(leftItem.BlockID)) { item.count++; isProcessed = true; break; } } if (!isProcessed) { switchCounts.Add(new SwitchCount() { nodeID = leftItem.BlockID, count = 1 }); } } } ExecutePoint leftPoint = null; ExecutePoint rightPoint = null; if (leftItem != null) { leftPoint = leftItem.GetExecutePoint(ExecutePoint.PointPosition.ExecutePoint_Right, lineData[ix].left.executePointID); } if (rightItem != null) { rightPoint = rightItem.GetExecutePoint(ExecutePoint.PointPosition.ExecutePoint_Left); } if (leftItem != null && rightItem != null && leftPoint != null && rightPoint != null) { GraphLine newLine = leftPoint.SetLineData(rightPoint); } } //Debug.Log("switchCount: " + switchCounts.Count); foreach (SwitchCount item in switchCounts) { GraphItem node = GetGraphItem(item.nodeID); SwitchBranchItem switchNode = node as SwitchBranchItem; switchNode.SetBlockCount(item.count - 1); } }
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); }