public static string GenerateTransitionMethod(FlowSystemEditorWindow flowEditor, FlowWindow windowFrom, 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.GetNamespace(root) + "." + Tpl.GetDerivedClassName(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(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.windows.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.windows) {
					
					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 = GUILayoutExt.LargeButton(functionContainer != null ? functionContainer.title : "None", GUILayout.MaxHeight(60f), GUILayout.MaxWidth(150f));
				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.windows) {
						
						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 string OnCompilerTransitionAttachedGeneration(FlowWindow windowFrom, FlowWindow windowTo, bool everyPlatformHasUniqueName) {

			if (windowTo.IsFunction() == true && 
			    windowTo.IsSmall() == true &&
			    windowTo.IsContainer() == false &&
			    windowTo.GetFunctionId() > 0) {
				
				return FlowFunctionsTemplateGenerator.GenerateTransitionMethod(this.flowEditor, windowFrom, windowTo);
				
			}

			return base.OnCompilerTransitionAttachedGeneration(windowFrom, windowTo, everyPlatformHasUniqueName);
			
		} 
		public override bool IsCompilerTransitionAttachedGeneration(FlowWindow windowFrom, FlowWindow windowTo) {

			return windowTo.IsFunction() == true && 
					windowTo.IsSmall() == true &&
					windowTo.IsContainer() == false &&
					windowTo.GetFunctionId() > 0;

		}
Exemplo n.º 5
0
		public override void OnFlowWindowGUI(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 functionId = window.GetFunctionId();
				var functionContainer = data.GetWindow(functionId);
				var isActiveSelected = true;

				var oldColor = GUI.color;
				GUI.color = isActiveSelected ? Color.white : Color.grey;
				var result = GUILayoutExt.LargeButton(functionContainer != null ? functionContainer.title : "None", 60f, 150f);
				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;

					});

					foreach (var win in data.windows) {
						
						if (win.IsFunction() == true &&
						    win.IsContainer() == true) {

							var id = win.id;
							menu.AddItem(new GUIContent(win.title), win.id == window.functionId, () => {

								window.functionId = id;

							});

						}
						
					}

					menu.DropDown(rect);

				}

			}

		}
Exemplo n.º 6
0
		public void DrawNodeCurve(FlowWindow from, FlowWindow to, bool doubleSide) {

			if (from.IsEnabled() == false || to.IsEnabled() == false) return;
			
			var fromRect = from.rect;
			Rect centerStart = fromRect;
			
			var toRect = to.rect;
			Rect centerEnd = toRect;
			
			var fromComponent = false;
			var toComponent = false;
			
			if (from.IsFunction() == true &&
			    from.IsContainer() == false) {
				
				var func = FlowSystem.GetWindow(from.GetFunctionId());
				if (func != null) {
					
					var selected = FlowSystem.GetSelected();
					var isSelected = selected.Contains(from.id) || (selected.Count == 0 && this.editor.focusedGUIWindow == from.id);
					if (isSelected == true) {
						
						var color = new Color(0f, 0f, 0f, 0.1f);
						var backColor = new Color(0.5f, 0.5f, 0.5f, 0.1f);
						
						this.DrawPolygon(new Vector3(from.rect.xMin, from.rect.yMin, 0f),
						                 new Vector3(func.rect.xMin, func.rect.yMin, 0f),
						                 new Vector3(func.rect.xMin, func.rect.yMax, 0f),
						                 new Vector3(from.rect.xMin, from.rect.yMax, 0f),
						                 backColor);
						
						this.DrawPolygon(new Vector3(from.rect.xMin, from.rect.yMin, 0f),
						                 new Vector3(func.rect.xMin, func.rect.yMin, 0f),
						                 new Vector3(func.rect.xMax, func.rect.yMin, 0f),
						                 new Vector3(from.rect.xMax, from.rect.yMin, 0f),
						                 backColor);
						
						this.DrawPolygon(new Vector3(from.rect.xMax, from.rect.yMin, 0f),
						                 new Vector3(func.rect.xMax, func.rect.yMin, 0f),
						                 new Vector3(func.rect.xMax, func.rect.yMax, 0f),
						                 new Vector3(from.rect.xMax, from.rect.yMax, 0f),
						                 backColor);
						
						this.DrawPolygon(new Vector3(from.rect.xMax, from.rect.yMax, 0f),
						                 new Vector3(func.rect.xMax, func.rect.yMax, 0f),
						                 new Vector3(func.rect.xMin, func.rect.yMax, 0f),
						                 new Vector3(from.rect.xMin, from.rect.yMax, 0f),
						                 backColor);
						
						this.DrawNodeCurveDotted(new Vector3(from.rect.xMin, from.rect.yMin, 0f),
						                         new Vector3(func.rect.xMin, func.rect.yMin, 0f),
						                         color
						                         );
						
						this.DrawNodeCurveDotted(new Vector3(from.rect.xMin, from.rect.yMax, 0f),
						                         new Vector3(func.rect.xMin, func.rect.yMax, 0f),
						                         color
						                         );
						
						this.DrawNodeCurveDotted(new Vector3(from.rect.xMax, from.rect.yMin, 0f),
						                         new Vector3(func.rect.xMax, func.rect.yMin, 0f),
						                         color
						                         );
						
						this.DrawNodeCurveDotted(new Vector3(from.rect.xMax, from.rect.yMax, 0f),
						                         new Vector3(func.rect.xMax, func.rect.yMax, 0f),
						                         color
						                         );
						
					}
					
				}
				
			}
			
			if (FlowSystem.GetData().flowWindowWithLayout == true) {
				
				var comps = from.attachedComponents.Where((c) => c.targetWindowId == to.id && c.sourceComponentTag != LayoutTag.None);
				foreach (var comp in comps) {
					
					var component = from.GetLayoutComponent(comp.sourceComponentTag);
					if (component != null) {
						
						fromRect = centerStart;
						
						var rect = component.tempEditorRect;
						fromRect = new Rect(fromRect.x + rect.x, fromRect.y + rect.y, rect.width, rect.height);
						
						this.DrawNodeCurve(from.GetContainer(), to.GetContainer(), centerStart, centerEnd, fromRect, toRect, doubleSide, 0f);
						
						fromComponent = true;
						
					}
					
				}
				
				if (doubleSide == true) {
					
					comps = to.attachedComponents.Where((c) => c.targetWindowId == from.id && c.sourceComponentTag != LayoutTag.None);
					foreach (var comp in comps) {
						
						var component = to.GetLayoutComponent(comp.sourceComponentTag);
						if (component != null) {
							
							toRect = centerEnd;
							
							var rect = component.tempEditorRect;
							toRect = new Rect(toRect.x + rect.x, toRect.y + rect.y, rect.width, rect.height);
							
							this.DrawNodeCurve(from.GetContainer(), to.GetContainer(), centerStart, centerEnd, fromRect, toRect, doubleSide, 0f);
							
							toComponent = true;
							
						}
						
					}
					
				}
				
			}
			
			if (fromComponent == false && toComponent == false) this.DrawNodeCurve(from.GetContainer(), to.GetContainer(), centerStart, centerEnd, fromRect, toRect, doubleSide);
			
		}