public static string GenerateTransitionMethod(FlowSystemEditorWindow flowEditor, FD.FlowWindow windowFrom, FD.FlowWindow windowTo) { var file = Resources.Load("UI.Windows/Functions/Templates/TemplateTransitionMethod") as TextAsset; if (file == null) { Debug.LogError("Functions Template Loading Error: Could not load template 'TemplateTransitionMethod'"); return string.Empty; } var data = FlowSystem.GetData(); if (data == null) return string.Empty; var result = string.Empty; var part = file.text; // Function link var functionId = windowTo.GetFunctionId(); // Find function container var functionContainer = data.GetWindow(functionId); if (functionContainer == null) { // Function not found return string.Empty; } // Get function root window var root = data.GetWindow(functionContainer.functionRootId); //var exit = data.GetWindow(functionContainer.functionExitId); var functionName = functionContainer.title; var functionCallName = functionContainer.directory; var classNameWithNamespace = Tpl.GetClassNameWithNamespace(root); var transitionMethods = Tpl.GenerateTransitionMethods(windowTo); transitionMethods = transitionMethods.Replace("\r\n", "\r\n\t") .Replace("\n", "\n\t"); result += part.Replace("{TRANSITION_METHODS}", transitionMethods) .Replace("{FUNCTION_NAME}", functionName) .Replace("{FUNCTION_CALL_NAME}", functionCallName) .Replace("{FLOW_FROM_ID}", windowFrom.id.ToString()) .Replace("{FLOW_TO_ID}", windowTo.id.ToString()) .Replace("{CLASS_NAME_WITH_NAMESPACE}", classNameWithNamespace); return result; }
public override void OnFlowWindowGUI(FD.FlowWindow window) { var data = FlowSystem.GetData(); if (data == null) return; var flag = (window.IsFunction() == true && window.IsSmall() == true && window.IsContainer() == false); if (flag == true) { var alreadyConnectedFunctionIds = new List<int>(); // Find caller window var windowFrom = data.windowAssets.FirstOrDefault((item) => item.HasAttach(window.id)); if (windowFrom != null) { var attaches = windowFrom.GetAttachedWindows(); foreach (var attachWindow in attaches) { if (attachWindow.IsFunction() == true) { alreadyConnectedFunctionIds.Add(attachWindow.GetFunctionId()); } } } foreach (var win in data.windowAssets) { if (win.IsFunction() == true && win.IsContainer() == true) { var count = alreadyConnectedFunctionIds.Count((e) => e == win.id); if ((window.GetFunctionId() == win.id && count == 1) || count == 0) { } else { if (win.id == window.functionId) window.functionId = 0; alreadyConnectedFunctionIds.Remove(win.id); } } } var functionId = window.GetFunctionId(); var functionContainer = functionId == 0 ? null : data.GetWindow(functionId); var isActiveSelected = true; var oldColor = GUI.color; GUI.color = isActiveSelected ? Color.white : Color.grey; var result = GUILayout.Button(functionContainer != null ? functionContainer.title : "None", FlowSystemEditorWindow.defaultSkin.button, GUILayout.ExpandHeight(true)); GUI.color = oldColor; var rect = GUILayoutUtility.GetLastRect(); rect.y += rect.height; if (result == true) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("None"), window.functionId == 0, () => { window.functionId = 0; }); if (windowFrom != null) { alreadyConnectedFunctionIds.Clear(); var attaches = windowFrom.GetAttachedWindows(); foreach (var attachWindow in attaches) { if (attachWindow.IsFunction() == true) { alreadyConnectedFunctionIds.Add(attachWindow.GetFunctionId()); } } } foreach (var win in data.windowAssets) { if (win.IsFunction() == true && win.IsContainer() == true) { var count = alreadyConnectedFunctionIds.Count((e) => e == win.id); if ((window.GetFunctionId() == win.id && count == 1) || count == 0) { var id = win.id; menu.AddItem(new GUIContent(win.title), win.id == window.functionId, () => { window.functionId = id; }); } else { if (win.id == window.functionId) window.functionId = 0; alreadyConnectedFunctionIds.Remove(win.id); menu.AddDisabledItem(new GUIContent(win.title)); } } } menu.DropDown(rect); } } }
public override bool IsCompilerTransitionAttachedGeneration(FD.FlowWindow windowFrom, FD.FlowWindow windowTo) { return windowTo.IsFunction() == true && windowTo.IsSmall() == true && windowTo.IsContainer() == false && windowTo.GetFunctionId() > 0; }
public override string OnCompilerTransitionTypedAttachedGeneration(FD.FlowWindow windowFrom, FD.FlowWindow windowTo, bool everyPlatformHasUniqueName, System.Type[] types, string[] names) { if (windowTo.IsFunction() == true && windowTo.IsSmall() == true && windowTo.IsContainer() == false && windowTo.GetFunctionId() > 0) { return FlowFunctionsTemplateGenerator.GenerateTransitionTypedMethod(this.flowEditor, windowFrom, windowTo, types, names); } return base.OnCompilerTransitionTypedAttachedGeneration(windowFrom, windowTo, everyPlatformHasUniqueName, types, names); }
public static string GenerateTransitionTypedMethod(FlowSystemEditorWindow flowEditor, FD.FlowWindow windowFrom, FD.FlowWindow windowTo, System.Type[] parameters, string[] parameterNames) { var file = Resources.Load("UI.Windows/Functions/Templates/TemplateTransitionTypedMethod") as TextAsset; if (file == null) { Debug.LogError("Functions Template Loading Error: Could not load template 'TemplateTransitionTypedMethod'"); return string.Empty; } var data = FlowSystem.GetData(); if (data == null) return string.Empty; var result = string.Empty; var part = file.text; // Function link var functionId = windowTo.GetFunctionId(); // Find function container var functionContainer = data.GetWindow(functionId); if (functionContainer == null) { // Function not found return string.Empty; } // Get function root window var root = data.GetWindow(functionContainer.functionRootId); //var exit = data.GetWindow(functionContainer.functionExitId); var functionName = functionContainer.title; var functionCallName = functionContainer.directory; var classNameWithNamespace = Tpl.GetNamespace(root) + "." + Tpl.GetDerivedClassName(root); var transitionMethods = Tpl.GenerateTransitionMethods(windowTo); transitionMethods = transitionMethods.Replace("\r\n", "\r\n\t") .Replace("\n", "\n\t"); var definition = parameters.Select((x, i) => ME.Utilities.FormatParameter(x) + " " + parameterNames[i]).ToArray(); var call = parameterNames; var description = parameters.Select((x, i) => "/// <param name=\"" + parameterNames[i] + "\">" + parameterNames[i] + " to OnParametersPass</param>").ToArray(); result += part.Replace("{TRANSITION_METHODS}", transitionMethods) .Replace("{FUNCTION_NAME}", functionName) .Replace("{FUNCTION_CALL_NAME}", functionCallName) .Replace("{FLOW_FROM_ID}", windowFrom.id.ToString()) .Replace("{FLOW_TO_ID}", windowTo.id.ToString()) .Replace("{CLASS_NAME_WITH_NAMESPACE}", classNameWithNamespace) .Replace("{PARAMETERS_DEFINITION}", string.Join(", ", definition)) .Replace("{PARAMETERS_CALL}", string.Join(", ", call)) .Replace("{PARAMETERS_DESCRIPTION}", string.Join(System.Environment.NewLine, description)); return result; }