public void DrawTransitionChooser(AttachItem attach, FD.FlowWindow fromWindow, FD.FlowWindow toWindow, bool doubleSided) {
			
			if (this.drawWindowContent == false) return;

			if (toWindow.IsEnabled() == false) return;
			if (toWindow.IsContainer() == true) return;

			var factor = 0.5f;
			var transitionsContainer = fromWindow;
			var namePrefix = string.Empty;

			if (fromWindow.IsSmall() == true &&
				fromWindow.IsABTest() == true) {

				// is ABTest
				//Debug.Log(fromWindow.id + " => " + toWindow.id + " :: " + attach.index + " :: " + doubleSided);
				transitionsContainer = FlowSystem.GetWindow(fromWindow.abTests.sourceWindowId);
				if (transitionsContainer == null) return;

				namePrefix = string.Format("Variant{0}", attach.index.ToString());
				factor = 0.2f;

			} else {

				if (toWindow.IsSmall() == true) {

					if (toWindow.IsFunction() == false) return;

				}

			}

			if (FlowSystem.GetData().modeLayer == ModeLayer.Audio) {

				if (FlowSystem.GetData().HasView(FlowView.AudioTransitions) == false) return;

			} else {
				
				if (FlowSystem.GetData().HasView(FlowView.VideoTransitions) == false) return;

			}

			const float size = 32f;
			const float offset = size * 0.5f + 5f;

			Vector2 centerOffset = Flow.OnDrawNodeCurveOffset(this, attach, fromWindow, toWindow, doubleSided);

			if (doubleSided == true) {

				var q = Quaternion.LookRotation(toWindow.rect.center - fromWindow.rect.center, Vector3.back);
				var attachRevert = FlowSystem.GetAttachItem(toWindow.id, fromWindow.id);
				
				this.DrawTransitionChooser(attachRevert, toWindow, toWindow, fromWindow, centerOffset, q * Vector2.left * offset, size, factor, namePrefix);
				this.DrawTransitionChooser(attach, fromWindow, fromWindow, toWindow, centerOffset, q * Vector2.right * offset, size, factor, namePrefix);

			} else {

				this.DrawTransitionChooser(attach, transitionsContainer, fromWindow, toWindow, centerOffset, Vector2.zero, size, factor, namePrefix);

			}

		}
		public override void OnFlowWindowLayoutGUI(Rect rect, FD.FlowWindow window) {
			
			if (window.isVisibleState == false) return;
			if (window.IsContainer() == true) return;
			if (window.IsSmall() == true && window.IsFunction() == true) return;
			if (window.IsShowDefault() == true) return;

			if (Heatmap.settings == null) Heatmap.settings = Heatmap.GetSettingsFile();

			var settings = Heatmap.settings;
			if (settings != null) {
				
				var data = settings.data.Get(window);
				if (data == null) return;
				
				LayoutWindowType screen;
				var layout = HeatmapSystem.GetLayout(window.id, out screen);
				if (layout == null) return;

				var targetScreenSize = new Vector2(layout.root.editorRect.width, layout.root.editorRect.height);

				foreach (var item in settings.items) {
					
					if (item.show == true && item.enabled == true) {

						foreach (var serviceBase in this.editor.services) {
							
							var service = serviceBase as IAnalyticsService;
							if (service.GetServiceName() == item.serviceName) {

								var key = string.Format("{0}_{1}", item.serviceName, window.id);
								HeatmapResult result;
								if (this.heatmapResultsCache.TryGetValue(key, out result) == true) {

									if (result != null) {

										var texture = this.heatmapTexturesCache[key];
										if (texture != null) {
											
											var scaleFactor = HeatmapSystem.GetFactor(targetScreenSize, rect.size);
											//var scaleFactorCanvas = layout.editorScale > 0f ? 1f / layout.editorScale : 1f;
											//scaleFactor *= scaleFactorCanvas;
											var r = layout.root.editorRect;
											r.x *= scaleFactor;
											r.y *= scaleFactor;
											r.x += rect.x + rect.width * 0.5f;
											r.y += rect.y + rect.height * 0.5f;
											r.width *= scaleFactor;
											r.height *= scaleFactor;

											var c = Color.white;
											GUI.color = c;
											GUI.DrawTexture(r, texture, ScaleMode.StretchToFill, alphaBlend: true);
											GUI.color = Color.white;

										} else {
											
											if (this.noDataTexture != null) GUI.DrawTexture(rect, this.noDataTexture, ScaleMode.ScaleToFit, alphaBlend: true);
											
										}

									} else {

										// still loading...

									}

								} else {

									if (Event.current.type == EventType.Repaint) {

										var rectSize = targetScreenSize;//rect.size;
										var rootRect = layout.root.editorRect;

										this.heatmapResultsCache.Add(key, null);
										this.heatmapTexturesCache.Add(key, null);
										service.GetHeatmapData(window.id, (int)targetScreenSize.x, (int)targetScreenSize.y, item.userFilter, (_result) => {

											var heatmapResult = _result as HeatmapResult;

											// Convert normalized points to real points
											for (int i = 0; i < heatmapResult.points.Length; ++i) {

												var root = layout.GetRootByTag((LayoutTag)heatmapResult.points[i].tag);
												if (root != null) {

													var xn = heatmapResult.points[i].x;
													var yn = heatmapResult.points[i].y;

													var sourceRect = root.editorRect;
													var radius = (float)HeatmapVisualizer.GetRadius();
													sourceRect.x += radius;
													sourceRect.y += radius;
													sourceRect.width -= radius * 2f;
													sourceRect.height -= radius * 2f;

													var scaleFactor = HeatmapSystem.GetFactor(targetScreenSize, rectSize);
													var r = sourceRect;
													r.x *= scaleFactor;
													r.y *= scaleFactor;
													r.x += rootRect.width * 0.5f;
													r.y = rootRect.height * 0.5f - r.y;
													r.width *= scaleFactor;
													r.height *= scaleFactor;

													heatmapResult.points[i].realPoint = new Vector2(r.x + xn * r.width, r.y - yn * r.height);

												}

											}

											this.heatmapResultsCache[key] = heatmapResult;
											HeatmapSystem.GenerateTextureFromData((int)targetScreenSize.x, (int)targetScreenSize.y, this.heatmapResultsCache[key], (texture) => { this.heatmapTexturesCache[key] = texture; });
											
										});

									}

								}

							}

						}

					}

				}

			}

		}
		private void DrawWindowToolbar(FD.FlowWindow window) {

			/*if (FlowSystem.GetData().modeLayer != ModeLayer.Flow) {

				return;

			}*/

			//var edit = false;
			var id = window.id;
			
			var buttonStyle = ME.Utilities.CacheStyle("FlowEditor.DrawWindowToolbar.Styles", "toolbarButton", (name) => {
				
				var _buttonStyle = new GUIStyle(EditorStyles.toolbarButton);
				_buttonStyle.stretchWidth = false;
				
				return _buttonStyle;
				
			});
			
			var buttonDropdownStyle = ME.Utilities.CacheStyle("FlowEditor.DrawWindowToolbar.Styles", "toolbarDropDown", (name) => {
				
				var _buttonStyle = new GUIStyle(EditorStyles.toolbarDropDown);
				_buttonStyle.stretchWidth = false;
				
				return _buttonStyle;
				
			});

			var buttonWarningStyle = ME.Utilities.CacheStyle("FlowEditor.DrawWindowToolbar.Styles", "buttonWarningStyle", (name) => {
				
				var _buttonStyle = new GUIStyle(EditorStyles.toolbarButton);
				_buttonStyle.stretchWidth = false;
				_buttonStyle.fontStyle = FontStyle.Bold;
				
				return _buttonStyle;
				
			});

			GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));
			if (this.waitForAttach == false || this.currentAttachComponent == null) {
				
				if (this.waitForAttach == true) {
					
					if (id != this.currentAttachId) {
						
						var currentAttach = FlowSystem.GetWindow(this.currentAttachId);
						if (currentAttach != null) {
							
							//var attachTo = FlowSystem.GetWindow(id);
							//var hasContainer = currentAttach.HasContainer();
							
							if (currentAttach.IsContainer() == false) {
								
								if (FlowSystem.AlreadyAttached(this.currentAttachId, this.currentAttachIndex, id) == true) {
									
									if (GUILayout.Button(string.Format("Detach Here{0}", (Event.current.alt == true ? " (Double Direction)" : string.Empty)), buttonStyle) == true) {
										
										FlowSystem.Detach(this.currentAttachId, this.currentAttachIndex, id, oneWay: Event.current.alt == false);
										if (this.onAttach != null) this.onAttach(id, this.currentAttachIndex, false);
										if (Event.current.shift == false) this.WaitForAttach(-1);
										
									}
									
								} else {

									var abTests = (window.abTests.sourceWindowId >= 0/* || currentAttach.attachItems.Any(x => FlowSystem.GetWindow(x.targetId).IsABTest() == true) == true*/);

									if (this.currentAttachIndex == 0 && 
									    (currentAttach.IsABTest() == true ||
									    abTests == true)) {
										/*
										if (abTests == true) {

											if (GUILayout.Button("Attach Here", buttonStyle) == true) {

												this.ShowNotification(new GUIContent("You can't connect using this method. Use `Attach` function on `A/B Test Condition`"));

											}

										}*/

									} else {

										if (GUILayout.Button(string.Format("Attach Here{0}", (Event.current.alt == true ? " (Double Direction)" : string.Empty)), buttonStyle) == true) {
											
											FlowSystem.Attach(this.currentAttachId, this.currentAttachIndex, id, oneWay: Event.current.alt == false);
											if (this.onAttach != null) this.onAttach(id, this.currentAttachIndex, true);
											if (Event.current.shift == false) this.WaitForAttach(-1);
											
										}

									}

								}
								
							}
							
						}
						
					} else {
						
						if (GUILayout.Button("Cancel", buttonStyle) == true) {
							
							this.WaitForAttach(-1);
							
						}
						
					}
					
				} else {
					
					if (window.IsSmall() == false ||
					    window.IsFunction() == true ||
					    window.IsABTest() == true) {
						
						if (GUILayout.Button("Attach/Detach", buttonStyle) == true) {
							
							this.ShowNotification(new GUIContent("Use Attach/Detach buttons to Connect/Disconnect a window"));
							this.WaitForAttach(id);
							
						}
						
					}

				}
				
				if (window.IsSmall() == false) {
					
					//var isExit = false;
					
					var functionWindow = window.GetFunctionContainer();
					if (functionWindow != null) {
						
						if (functionWindow.functionRootId == 0) functionWindow.functionRootId = id;
						if (functionWindow.functionExitId == 0) functionWindow.functionExitId = id;
						
						//isExit = (functionWindow.functionExitId == id);
						
					}
					
					var isRoot = (FlowSystem.GetRootWindow() == id || (functionWindow != null && functionWindow.functionRootId == id));
					if (GUILayout.Toggle(isRoot, new GUIContent("R", "Set as root"), buttonStyle) != isRoot) {
						
						if (functionWindow != null) {
							
							if (isRoot == true) {
								
								// Was root
								// Setup root for the first window in function
								functionWindow.functionRootId = window.id;
								
							} else {
								
								// Was not root
								// Setup as root but inside this function only
								functionWindow.functionRootId = window.id;
								
							}
							
						} else {
							
							if (isRoot == true) {
								
								// Was root
								FlowSystem.SetRootWindow(-1);
								
							} else {
								
								// Was not root
								FlowSystem.SetRootWindow(id);
								
							}
							
						}
						
						FlowSystem.SetDirty();
						
					}
					/*
					if (functionWindow != null) {

						if (GUILayout.Toggle(isExit, new GUIContent("E", "Set as exit point"), buttonStyle) != isExit) {

							if (isExit == true) {
								
								// Was exit
								// Setup exit for the first window in function
								functionWindow.functionExitId = window.id;
								
							} else {
								
								// Was not exit
								// Setup as exit but inside this function only
								functionWindow.functionExitId = window.id;
								
							}

							FlowSystem.SetDirty();
							
						}

					}*/
					
					var isDefault = FlowSystem.GetDefaultWindows().Contains(id);
					if (GUILayout.Toggle(isDefault, new GUIContent("D", "Set as default"), buttonStyle) != isDefault) {
						
						if (isDefault == true) {
							
							// Was as default
							FlowSystem.GetDefaultWindows().Remove(id);
							
						} else {
							
							// Was not as default
							FlowSystem.GetDefaultWindows().Add(id);
							
						}
						
						FlowSystem.SetDirty();
						
					}
					
				}
				
				GUILayout.FlexibleSpace();
				
				if (window.IsSmall() == false && FlowSceneView.IsActive() == false && window.storeType == FD.FlowWindow.StoreType.NewScreen) {

					var state = GUILayout.Button("Screen", buttonDropdownStyle);
					if (Event.current.type == EventType.Repaint) {

						this.layoutStateSelectButtonRect = GUILayoutUtility.GetLastRect();

					}

					if (state == true) {

						var menu = new GenericMenu();
						menu.AddItem(new GUIContent("Select Package"), on: false, func: () => { this.SelectWindow(window); });
						
						if (window.compiled == true) {

							menu.AddItem(new GUIContent("Edit..."), on: false, func: () => {

								var path = Path.GetDirectoryName(AssetDatabase.GetAssetPath(window.GetScreen()));
								var filename = window.compiledDerivedClassName + ".cs";
								EditorUtility.OpenWithDefaultApp(string.Format("{0}/../{1}", path, filename));

							});

						}

						menu.AddItem(new GUIContent("Create on Scene"), on: false, func: () => { this.CreateOnScene(window); });

						var screen = window.GetScreen();

						var methodsCount = 0;
						WindowSystem.CollectCallVariations(screen, (types, names) => {

							++methodsCount;

						});

						menu.AddDisabledItem(new GUIContent("Calls/Methods: " + methodsCount.ToString()));
						menu.AddSeparator("Calls/");

						if (window.compiled == true &&
						    screen != null) {

							methodsCount = 0;
							WindowSystem.CollectCallVariations(screen, (types, names) => {

								var parameters = new List<string>();
								for (int i = 0; i < types.Length; ++i) {

									parameters.Add(ME.Utilities.FormatParameter(types[i]) + " " + names[i]);

								}

								var paramsStr = parameters.Count > 0 ? "(" + string.Join(", ", parameters.ToArray()) + ")" : string.Empty;
								menu.AddItem(new GUIContent("Calls/OnParametersPass" + paramsStr), on: false, func: () => {

									Selection.activeObject = screen;

								});

								++methodsCount;

							});

							if (methodsCount == 0) {
								
								menu.AddDisabledItem(new GUIContent("Calls/No `OnParametersPass` Methods Found"));

							}

						} else {
							
							menu.AddDisabledItem(new GUIContent("Calls/You need to compile window"));

						}

						Flow.OnFlowWindowScreenMenuGUI(this, window, menu);

						menu.DropDown(this.layoutStateSelectButtonRect);

					}
					
					/*
					if (GUILayout.Button("Edit", buttonStyle) == true) {
						
						if (window.compiled == false) {
							
							this.ShowNotification(new GUIContent("You need to compile this window to use 'Edit' command"));
							
						} else {
							
							edit = true;
							
						}
						
					}*/
					
				}
				
				if (GUILayout.Button("X", buttonWarningStyle) == true) {
					
					if (EditorUtility.DisplayDialog("Are you sure?", "Current window will be destroyed with all links.", "Yes, destroy", "No") == true) {
						
						this.ShowNotification(new GUIContent(string.Format("The window `{0}` was successfully destroyed", window.title)));
						FlowSystem.DestroyWindow(id);
						return;
						
					}
					
				}

			} else {
				
				// Draw Attach/Detach component link
				
				if (this.currentAttachId == id) {
					
					// Cancel
					if (GUILayout.Button("Cancel", buttonStyle) == true) {
						
						this.WaitForAttach(-1);
						
					}
					
				} else {
					
					// If it's other window
					if (window.IsSmall() == false ||
					    window.IsFunction() == true) {
						
						if (FlowSystem.AlreadyAttached(this.currentAttachId, this.currentAttachIndex, id, this.currentAttachComponent) == true) {
							
							if (GUILayout.Button("Detach Here", buttonStyle) == true) {
								
								FlowSystem.Detach(this.currentAttachId, this.currentAttachIndex, id, oneWay: true, component: this.currentAttachComponent);
								if (this.onAttach != null) this.onAttach(id, this.currentAttachIndex, false);
								if (Event.current.shift == false) this.WaitForAttach(-1);

							}
							
						} else {
							
							if (GUILayout.Button("Attach Here", buttonStyle) == true) {
								
								FlowSystem.Attach(this.currentAttachId, this.currentAttachIndex, id, oneWay: true, component: this.currentAttachComponent);
								if (this.onAttach != null) this.onAttach(id, this.currentAttachIndex, true);
								if (Event.current.shift == false) this.WaitForAttach(-1);
								
							}
							
						}
						
					}
					
				}
				
				GUILayout.FlexibleSpace();
				
			}
			GUILayout.EndHorizontal();
			
			/*if (edit == true) {
				
				FlowSceneView.SetControl(this, window, this.OnItemProgress);

			}*/
			
		}
		public override void OnFlowWindow(FD.FlowWindow window) {

			if (window.isVisibleState == false) return;
			if (window.IsContainer() == true) return;
			if (window.IsSmall() == true && window.IsFunction() == true) return;
			if (window.IsShowDefault() == true) return;

			if (Heatmap.settings == null) Heatmap.settings = Heatmap.GetSettingsFile();
			
			var settings = Heatmap.settings;
			if (settings != null) {

				var result = new ScreenResult();

				foreach (var item in settings.items) {
					
					if (item.show == true && item.enabled == true) {
						
						foreach (var serviceBase in this.editor.services) {

							var service = serviceBase as IAnalyticsService;
							if (service.GetServiceName() == item.serviceName) {

								var rect = window.rect;
								this.DrawBubble(new Rect(new Vector2(rect.x + rect.width * 0.5f, rect.y), Vector2.zero), 0, window.id, -1, Vector2.zero, "LabelGreen");

								int value;
								var keyTransition = string.Format("{0}_{1}", item.serviceName, window.id);
								if (this.resultsTransitionCache.TryGetValue(keyTransition, out value) == true) {

									result.uniqueCount = value;

								}

								if (result.uniqueCount > 0 && result.popup == false) {

									// Draw exit bubble
									this.DrawBubble(new Vector2(rect.x + rect.width * 0.5f, rect.y + rect.height), result, Vector2.zero, "LabelRed", "{1}");

								}

							}

						}

					}

				}

			}

		}
		public override void OnFlowWindowScreenMenuGUI(FD.FlowWindow window, GenericMenu menu) {
			
			if (window.isVisibleState == false) return;
			if (window.IsContainer() == true) return;
			if (window.IsSmall() == true && window.IsFunction() == true) return;
			if (window.IsShowDefault() == true) return;
			
			if (Heatmap.settings == null) Heatmap.settings = Heatmap.GetSettingsFile();
			
			var settings = Heatmap.settings;
			if (settings != null) {
				
				var data = settings.data.Get(window);
				if (data == null) return;

				foreach (var item in settings.items) {
					
					if (item.show == true && item.enabled == true) {
						
						foreach (var serviceBase in this.editor.services) {

							var service = serviceBase as IAnalyticsService;
							if (service.GetServiceName() == item.serviceName) {
								
								var key = string.Format("{0}_{1}", item.serviceName, window.id);
								var windowId = window.id;
								menu.AddItem(new GUIContent("Open Heatmap..."), false, () => {

									//this.fullScreenData = this.heatmapResultsCache[key];
									this.fullScreenTexture = this.heatmapTexturesCache[key];
									this.fullScreenWindowId = windowId;
									this.fullScreenEditor = null;

									this.openFullScreen = true;
									this.flowEditor.SetDisabled();

								});

							}

						}

					}

				}

			}

		}
		public void DrawTransitionChooser(FD.FlowWindow.AttachItem attach, FD.FlowWindow fromWindow, FD.FlowWindow toWindow, bool doubleSided) {
			
			if (toWindow.IsEnabled() == false) return;
			if (toWindow.IsContainer() == true) return;

			if (toWindow.IsSmall() == true) {

				if (toWindow.IsFunction() == false) return;

			}

			const float size = 32f;
			const float offset = size * 0.5f + 5f;

			if (doubleSided == true) {

				var q = Quaternion.LookRotation(toWindow.rect.center - fromWindow.rect.center, Vector3.back);
				var attachRevert = FlowSystem.GetAttachItem(toWindow.id, fromWindow.id);
				
				this.DrawTransitionChooser(attachRevert, toWindow, fromWindow, q * Vector2.left * offset, size);
				this.DrawTransitionChooser(attach, fromWindow, toWindow, q * Vector2.right * offset, size);

			} else {

				this.DrawTransitionChooser(attach, fromWindow, toWindow, Vector2.zero, size);

			}

		}
		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 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 override bool IsCompilerTransitionAttachedGeneration(FD.FlowWindow windowFrom, FD.FlowWindow windowTo) {

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

		}
		public static void CreateTransition(FD.FlowWindow flowWindow, FD.FlowWindow toWindow, string localPath, System.Action<TransitionInputTemplateParameters> callback = null) {

			if (flowWindow.GetScreen() == null) return;

			var screenPath = AssetDatabase.GetAssetPath(flowWindow.GetScreen());
			screenPath = System.IO.Path.GetDirectoryName(screenPath);
			var splitted = screenPath.Split(new string[] {"/"}, System.StringSplitOptions.RemoveEmptyEntries);
			var packagePath = string.Join("/", splitted, 0, splitted.Length - 1);
			var path = packagePath + localPath;

			FlowChooserFilterWindow.Show<TransitionInputTemplateParameters>(
				root: null,
			    onSelect: (element) => {
				
				// Clean up previous transitions if exists
				var attachItem = flowWindow.GetAttachItem(toWindow);
				if (attachItem != null) {
					
					if (attachItem.transition != null && attachItem.transitionParameters != null) {

						AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(attachItem.transitionParameters.gameObject));
						
						attachItem.transition = null;
						attachItem.transitionParameters = null;

					}
					
				}

				if (System.IO.Directory.Exists(path) == false) {

					System.IO.Directory.CreateDirectory(path);

				}

				if (element == null) return;

				var elementPath = AssetDatabase.GetAssetPath(element.gameObject);
				var targetName = "Transition-" + element.gameObject.name + "-" + (toWindow.IsFunction() == true ? FlowSystem.GetWindow(toWindow.functionId).directory : toWindow.directory);
				var targetPath = path + "/" + targetName + ".prefab";

				if (AssetDatabase.CopyAsset(elementPath, targetPath) == true) {

					AssetDatabase.ImportAsset(targetPath);

					var newInstance = AssetDatabase.LoadAssetAtPath<GameObject>(targetPath);
					var instance = newInstance.GetComponent<TransitionInputTemplateParameters>();
					instance.useAsTemplate = false;
					EditorUtility.SetDirty(instance);

					attachItem.transition = instance.transition;
					attachItem.transitionParameters = instance;

					if (callback != null) callback(instance);

				}

			},
			onEveryGUI: (element) => {
				
				// on gui
				
				var style = new GUIStyle(GUI.skin.label);
				style.wordWrap = true;
				
				if (element != null) {

					GUILayout.Label(element.name, style);

				} else {

					GUILayout.Label("None", style);

				}

			},
			predicate: (element) => {

				var elementPath = AssetDatabase.GetAssetPath(element.gameObject);
				var isInPackage = FlowProjectWindowObject.IsValidPackage(elementPath + "/../");

				if (element.transition != null && (isInPackage == true || element.useAsTemplate == true)) {

					var name = element.GetType().FullName;
					var baseName = name.Substring(0, name.IndexOf("Parameters"));

					var type = System.Type.GetType(baseName + ", " + element.GetType().Assembly.FullName, throwOnError: true, ignoreCase: true);
					if (type != null) {

						var attribute = type.GetCustomAttributes(inherit: true).OfType<TransitionCameraAttribute>().FirstOrDefault();
						if (attribute != null) {

							return true;

						} else {

							Debug.Log("No Attribute: " + baseName, element);

						}

					} else {

						Debug.Log("No type: " + baseName);

					}

				}

				return false;

			},
			strongType: false,
			directory: null,
			useCache: false,
			drawNoneOption: true,
			updateRedraw: true);
			
		}