/// <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> /// Register a Coroutine Event /// </summary> /// <param name="obj"></param> /// <param name="generator"></param> /// <returns></returns> public static string RegisterCoroutineEvent(object obj, Func <string> generator, bool customExecution = false) { if (CodeGenerator.generatorData.coroutineEvent.ContainsKey(obj)) { return(CodeGenerator.RunEvent(obj)); } else { if (customExecution) { CodeGenerator.SetCoroutineExecution(obj, generator()); } else { CodeGenerator.SetCoroutineAction(obj, generator()); } return(CodeGenerator.RunEvent(obj)); } }
/// <summary> /// Override this function to implement custom code generation for validation. /// </summary> /// <param name="obj"></param> /// <returns></returns> public virtual string GenerateConditionCode(Object obj) { if (this is Action && (this as Action).IsCoroutine()) { if (CodeGenerator.generatorData.eventActions.ContainsKey(this)) { return(CodeGenerator.RunEvent(this)); } else { string data = GenerateCode(obj); if (!string.IsNullOrEmpty(data)) { CodeGenerator.generatorData.eventActions.Add(this, data); CodeGenerator.generatorData.portableActionInNode.Add(obj as uNode.Node); return(CodeGenerator.RunEvent(this)); } } } else { if (CodeGenerator.generatorData.eventActions.ContainsKey(this)) { return(CodeGenerator.GetInvokeActionCode(this)); } else { string data = GenerateCode(obj); if (!string.IsNullOrEmpty(data)) { CodeGenerator.generatorData.eventActions.Add(this, data); CodeGenerator.generatorData.portableActionInNode.Add(obj as uNode.Node); return(CodeGenerator.GetInvokeActionCode(this)); } } } throw new System.NotImplementedException(this.GetType().FullName); }