コード例 #1
0
		public void DrawTransitionChooser(UnityEngine.UI.Windows.Plugins.Flow.FlowWindow.AttachItem attach, FlowWindow fromWindow, 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);

			}

		}
コード例 #2
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 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);

				}

			}

		}
コード例 #3
0
		private void DrawWindowToolbar(FlowWindow window) {
			
			//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;

			});

			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, id) == true) {
									
									if (GUILayout.Button(string.Format("Detach Here{0}", (Event.current.alt == true ? " (Double Direction)" : string.Empty)), buttonStyle) == true) {
										
										FlowSystem.Detach(this.currentAttachId, id, oneWay: Event.current.alt == false);
										if (Event.current.shift == false) this.WaitForAttach(-1);
										
									}
									
								} else {
									
									if (GUILayout.Button(string.Format("Attach Here{0}", (Event.current.alt == true ? " (Double Direction)" : string.Empty)), buttonStyle) == true) {
										
										FlowSystem.Attach(this.currentAttachId, id, oneWay: Event.current.alt == false);
										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) {
						
						if (GUILayout.Button("Attach/Detach", buttonStyle) == true) {
							
							this.ShowNotification(new GUIContent("Use Attach/Detach buttons to Connect/Disconnect a window"));
							this.WaitForAttach(id);
							
						}
						
					}
					
					if (GUILayout.Button("Destroy", buttonStyle) == 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;
							
						}
						
					}
					
				}
				
				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 == FlowWindow.StoreType.NewScreen) {
					
					if (GUILayout.Button("Select", buttonStyle) == true) {
						
						this.SelectWindow(window);
						
					}
					
					/*
					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;
							
						}
						
					}*/
					
				}
				
			} 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, id, this.currentAttachComponent) == true) {
							
							if (GUILayout.Button("Detach Here", buttonStyle) == true) {
								
								FlowSystem.Detach(this.currentAttachId, id, oneWay: true, component: this.currentAttachComponent);
								if (Event.current.shift == false) this.WaitForAttach(-1);
								
							}
							
						} else {
							
							if (GUILayout.Button("Attach Here", buttonStyle) == true) {
								
								FlowSystem.Attach(this.currentAttachId, id, oneWay: true, component: this.currentAttachComponent);
								if (Event.current.shift == false) this.WaitForAttach(-1);
								
							}
							
						}
						
					}
					
				}
				
				GUILayout.FlexibleSpace();
				
			}
			GUILayout.EndHorizontal();
			
			/*if (edit == true) {
				
				FlowSceneView.SetControl(this, window, this.OnItemProgress);

			}*/
			
		}
コード例 #4
0
		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);
			
		} 
コード例 #5
0
		public override bool IsCompilerTransitionAttachedGeneration(FlowWindow windowFrom, FlowWindow windowTo) {

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

		}
コード例 #6
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);

				}

			}

		}
コード例 #7
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);
			
		}
コード例 #8
0
		public static void CreateTransition(FlowWindow flowWindow, 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);
			
		}