/// <summary> /// Function for generating condition code /// </summary> /// <param name="node"></param> /// <param name="contents">The content inside condition</param> /// <returns></returns> public string GenerateConditionCode(uNode.Node node, string contents) { if (eventList.Count > 0) { string str = GenerateCode(node, EventType.Condition); if (!string.IsNullOrEmpty(str)) { str = str.Insert(0, "if("); if (!string.IsNullOrEmpty(contents)) { contents = ("\n" + contents).AddTabAfterNewLine(1) + "\n"; } str += ") {" + contents + "}"; return(str); } } else { //Debug.Log("No event.", node); } if (!string.IsNullOrEmpty(contents)) { contents = ("\n" + contents).AddTabAfterNewLine(1) + "\n"; } return("if(true) {" + contents + "}"); }
public string GenerateCode(uNode.Node node, EventData.EventType type = EventData.EventType.Action) { if (eventType == EventType.Or) { return(null); } return(CodeGenerator.GenerateEventCode(node, block, type)); }
/// <summary> /// Generate coroutine action code. /// </summary> /// <param name="node"></param> /// <param name="runInParallel"></param> /// <returns></returns> public string GenerateCoroutineCode(uNode.Node node, bool runInParallel) { if (eventList.Count > 0) { System.Text.StringBuilder builder = new System.Text.StringBuilder(); int index = 0; foreach (EventActionData action in eventList) { try { if (action.isCoroutine && runInParallel) { if (CodeGenerator.generatorData.coroutineEvent.ContainsKey(action.block)) { builder.Append(CodeGenerator.RunEvent(action.block).AddLineInFirst()); } else { string data = action.GenerateCode(node, EventType.Action); if (!string.IsNullOrEmpty(data)) { CodeGenerator.SetCoroutineAction(action.block, data); if (!CodeGenerator.generatorData.portableActionInNode.Contains(node)) { CodeGenerator.generatorData.portableActionInNode.Add(node); } builder.Append(CodeGenerator.RunEvent(action.block).AddLineInFirst()); } } } else { string s = action.GenerateCode(node, EventType.Action); if (!string.IsNullOrEmpty(s)) { builder.Append(s.AddLineInFirst()); } } index++; } catch { Debug.LogError("Error in event:" + action.displayName + " |in index :" + index); throw; } } if (runInParallel) { foreach (EventActionData action in eventList) { if (action.isCoroutine) { builder.Append(CodeGenerator.WaitEvent(action.block, false).AddLineInFirst()); } } } return(builder.ToString()); } return(null); }
/// <summary> /// Function for generating condition code /// </summary> /// <param name="node"></param> /// <param name="contents"></param> /// <param name="elseContents"></param> /// <returns></returns> public string GenerateConditionCode(uNode.Node node, string contents, string elseContents) { var result = GenerateConditionCode(node, contents); if (string.IsNullOrEmpty(result)) { return(result); } return(result.Add(" else {").AddLineInEnd() + elseContents.AddTabAfterNewLine().AddLineInEnd().Add("}")); }
/// <summary> /// Generate code for event action or condition. /// </summary> /// <param name="node"></param> /// <param name="type"></param> /// <returns></returns> public string GenerateCode(uNode.Node node, EventType type) { if (eventList.Count > 0) { System.Text.StringBuilder builder = new System.Text.StringBuilder(); int index = 0; int lastVLevel = 0; bool lastIsOR = false; foreach (EventActionData data in eventList) { try { string s = data.GenerateCode(node, type); int VLevel = data.levelValidation; if (!string.IsNullOrEmpty(s)) { if (type == EventType.Action) { builder.Append(s.AddLineInFirst()); } else { if (index != 0) { if (!lastIsOR) { builder.Append(" && "); } if (useLevelValidation) { while (lastVLevel < VLevel) { builder.Append("("); VLevel--; } } } builder.Append(s); } } else if (type == EventType.Condition) { if (data.eventType == EventActionData.EventType.Event) { if (index != 0) { if (!lastIsOR) { builder.Append(" && "); } if (useLevelValidation) { while (lastVLevel < VLevel) { builder.Append("("); VLevel--; } } } builder.Append("true"); } else { lastIsOR = true; builder.Append(" || "); lastVLevel = data.levelValidation; index++; continue; } } VLevel = data.levelValidation; if (type == EventType.Condition && useLevelValidation) { if (index + 1 >= eventList.Count) { lastVLevel = VLevel; VLevel = 0; } else { lastVLevel = VLevel; VLevel = eventList[index + 1].levelValidation; } while (lastVLevel > VLevel) { builder.Append(")"); lastVLevel--; } } lastIsOR = false; lastVLevel = data.levelValidation; index++; } catch { Debug.LogError("Error in event:" + data.displayName + " |in index :" + index); throw; } } if (type == EventType.Condition && string.IsNullOrEmpty(builder.ToString())) { Debug.Log("No event generate code.", node); builder.Append("true"); } return(builder.ToString()); } if (type == EventType.Condition) { return("true"); } return(null); }