/// <summary> /// Find all node connection after coroutine node. /// </summary> /// <param name="node"></param> /// <param name="allNode"></param> /// <param name="includeSuperNode"></param> /// <param name="includeCoroutineEvent"></param> public static void FindFlowConnectionAfterCoroutineNode(NodeComponent node, ref HashSet <NodeComponent> allNode, bool includeSuperNode = true, bool includeCoroutineEvent = true, bool passCoroutine = false) { if (node != null && !allNode.Contains(node)) { bool isCoroutineNode = node.IsSelfCoroutine(); if (!passCoroutine && isCoroutineNode) { passCoroutine = true; } if (passCoroutine && (!isCoroutineNode || includeCoroutineEvent)) { allNode.Add(node); } var nodes = GetFlowConnection(node); if (nodes != null) { foreach (Node n in nodes) { if (n) { FindFlowConnectionAfterCoroutineNode(n, ref allNode, includeSuperNode, includeCoroutineEvent, passCoroutine); } } } if (includeSuperNode && node is ISuperNode) { ISuperNode superNode = node as ISuperNode; foreach (var n in superNode.nestedFlowNodes) { FindFlowConnectionAfterCoroutineNode(n, ref allNode, includeSuperNode, includeCoroutineEvent, passCoroutine); } } } }
/// <summary> /// Is the node are identified as coroutine node? /// </summary> /// <param name="node"></param> /// <returns></returns> public static bool IsCoroutineFlow(NodeComponent node) { return(node.IsSelfCoroutine()); }
/// <summary> /// Function for generating code for flow member. /// </summary> /// <param name="flowMember">The flow member</param> /// <param name="from">The node which flow member comes from</param> /// <param name="waitTarget">If true, will generate wait code on coroutine member.</param> /// <returns></returns> public static string GenerateFlowCode(MemberData flowMember, NodeComponent from, bool waitTarget = true) { if (flowMember == null) { return(null); } if (!flowMember.isAssigned) { return(null); } Node target = flowMember.GetTargetNode(); if (target == null) { return(null); } if (flowMember.targetType != MemberData.TargetType.FlowNode && flowMember.targetType != MemberData.TargetType.FlowInput) { throw new System.Exception("Incorrect target type : " + flowMember.targetType.ToString() + ", TargetType must FlowNode or FlowInput"); } if (flowMember.targetType != MemberData.TargetType.FlowInput && !target.IsFlowNode()) { throw new System.Exception("node is not flow node."); } string debug = null; if (setting.debugScript) { debug = GenerateDebugCode(flowMember).AddLineInEnd(); } if (flowMember.targetType == MemberData.TargetType.FlowNode) { if (!isInUngrouped && !uNodeUtility.IsInStateGraph(target) && !IsUngroupedNode(target)) { return(debug + GenerateNode(target)); } if (waitTarget && (isInUngrouped || from && from.IsSelfCoroutine() || allowYieldStatement && IsUngroupedNode(target))) { if (!generatorData.ungroupedNode.Contains(target)) { return(debug + GenerateNode(target)); } if (!allowYieldStatement) { throw new Exception("The current block doesn't allow coroutines / yield statements"); } return(debug + "yield return " + RunEvent(target)); } if (!isInUngrouped && generatorData.groupedNode.Contains(target)) { return(debug + GenerateNode(target)); } if (!generatorData.ungroupedNode.Contains(target)) { if (!allowYieldStatement && target.IsSelfCoroutine()) { throw new Exception("The current block doesn't allow coroutines / yield statements"); } throw new uNodeException($"Forbidden to generate state code because the node: {target.GetNodeName()} is not registered as State Node.\nEnsure to register it using {nameof(CodeGenerator)}.{nameof(CodeGenerator.RegisterAsStateNode)}", target); } return(debug + RunEvent(target)); } else { return(debug + GenerateFlowCode(flowMember.Invoke(null) as IFlowGenerate, target)); } // return debug + GetInvokeCode(_eventCode, false, generatorData.GetEventName(target)); }