public Window Get(FlowWindow window) { Window result = null; this.list.RemoveAll((info) => { var w = Flow.FlowSystem.GetWindow(info.id); return w == null || w.IsSocial() == false; }); if (window.IsSocial() == false) return result; foreach (var item in this.list) { if (item.id == window.id) { result = item; break; } } if (result == null) { result = new Window(window); this.list.Add(result); } return result; }
public static string GenerateReturnMethod(FlowSystemEditorWindow flowEditor, FlowWindow exitWindow) { var file = Resources.Load("UI.Windows/Functions/Templates/TemplateReturnMethod") as TextAsset; if (file == null) { Debug.LogError("Functions Template Loading Error: Could not load template 'TemplateReturnMethod'"); return string.Empty; } var data = FlowSystem.GetData(); if (data == null) return string.Empty; var result = string.Empty; var part = file.text; var functionContainer = exitWindow.GetFunctionContainer(); var functionName = functionContainer.title; var functionCallName = functionContainer.directory; var classNameWithNamespace = Tpl.GetNamespace(exitWindow) + "." + Tpl.GetDerivedClassName(exitWindow); result += part.Replace("{FUNCTION_NAME}", functionName) .Replace("{FUNCTION_CALL_NAME}", functionCallName) .Replace("{CLASS_NAME_WITH_NAMESPACE}", classNameWithNamespace); return result; }
public static WindowBase GenerateScreen(FlowWindow window, FlowLayoutWindowTypeTemplate template) { WindowBase instance = null; if (window.compiled == false) { return(instance); } var tplName = template.name; //"Layout"; var tplData = template; //FlowSystem.LoadPrefabTemplate<WindowBase>(FlowSystem.SCREENS_FOLDER, tplName); if (tplData != null) { var filepath = window.compiledDirectory + "/" + FlowDatabase.SCREENS_FOLDER + "/" + tplName + "Screen.prefab"; instance = FlowDatabase.GenerateScreen(filepath, window.compiledDerivedClassName, string.Empty, tplData); } else { Debug.LogError("Template Loading Error: " + tplName); } return(instance); }
public static WindowLayout GenerateLayout(FlowWindow window, FlowWindowLayoutTemplate layout) { WindowLayout instance = null; if (window.compiled == false) { return(instance); } var tplName = layout.name; //"3Buttons"; var tplData = layout; //FlowSystem.LoadPrefabTemplate<WindowLayout>(FlowSystem.LAYOUT_FOLDER, tplName); if (tplData != null) { var filepath = window.compiledDirectory + "/" + FlowDatabase.LAYOUT_FOLDER + "/" + tplName + "Layout.prefab"; instance = FlowDatabase.GenerateLayout(filepath, tplData); } else { Debug.LogError("Template Loading Error: " + tplName); } return(instance); }
public override void OnFlowWindowLayoutGUI(Rect rect, UnityEngine.UI.Windows.Plugins.Flow.FlowWindow window) { if (Heatmap.settings == null) { Heatmap.settings = this.GetSettingsFile(); } var settings = Heatmap.settings; if (settings != null) { if (settings.show == true) { var data = settings.data.Get(window); data.UpdateMap(); if (data != null && data.texture != null && data.status == HeatmapSettings.WindowsData.Window.Status.Loaded) { GUI.DrawTexture(rect, data.texture, ScaleMode.StretchToFill, alphaBlend: true); } else { if (this.noDataTexture != null) { GUI.DrawTexture(rect, this.noDataTexture, ScaleMode.StretchToFill, alphaBlend: true); } } } } }
public override void OnFlowWindowGUI(FlowWindow window) { if (window.CanCompiled() == false) return; if (string.IsNullOrEmpty(window.compiledDirectory) == false) { window.compiled = System.IO.File.Exists(window.compiledDirectory + "/" + window.compiledBaseClassName + ".cs"); } var oldColor = GUI.color; var style = new GUIStyle("U2D.dragDotDimmed"); var styleCompiled = new GUIStyle("U2D.dragDot"); var elemWidth = style.fixedWidth - 3f; var posY = -1f; var posX = -1f; GUI.color = window.compiled ? Color.white : Color.red; GUI.Label(new Rect(posX, posY, elemWidth, style.fixedHeight), new GUIContent(string.Empty, window.compiled ? "Compiled" : "Not compiled"), window.compiled ? styleCompiled : style); GUI.color = oldColor; }
public void RemoveTag(FlowWindow window, FlowTag tag) { window.RemoveTag(tag); this.isDirty = true; }
public Info(FlowWindow window) { this.baseNamespace = window.compiledNamespace; this.classname = window.compiledDerivedClassName; this.baseClassname = window.compiledBaseClassName; this.screenName = window.directory; }
public FlowWindow CreateContainer() { var newId = this.AllocateId(); var window = new FlowWindow(newId, isContainer: true); this.windows.Add(window); this.isDirty = true; return window; }
public FlowWindow CreateWindow() { var newId = this.AllocateId(); var window = new FlowWindow(newId, isContainer: false); this.windows.Add(window); this.windowsCache.Clear(); this.isDirty = true; return(window); }
public FlowWindow CreateDefaultLink() { var newId = this.AllocateId(); var window = new FlowWindow(newId, isDefaultLink: true); this.windows.Add(window); this.isDirty = true; return window; }
public FlowWindow CreateWindow(FlowWindow.Flags flags) { var newId = this.AllocateId(); var window = new FlowWindow(newId, flags); this.windows.Add(window); this.windowsCache.Clear(); this.isDirty = true; return(window); }
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 FlowWindow CreateDefaultLink() { var newId = this.AllocateId(); var window = new FlowWindow(newId, isDefaultLink: true); window.title = "Default Link"; window.rect.width = 150f; window.rect.height = 30f; this.windows.Add(window); this.windowsCache.Clear(); this.isDirty = true; return(window); }
public void AddTag(FlowWindow window, FlowTag tag) { var contains = this.tags.FirstOrDefault((t) => t.title.ToLower() == tag.title.ToLower()); if (contains == null) { this.tags.Add(tag); } else { tag = contains; } window.AddTag(tag); this.isDirty = true; }
public void DrawComponentCurve(FlowWindow from, ref UnityEngine.UI.Windows.Plugins.Flow.FlowWindow.ComponentLink link, FlowWindow to) { if (from.IsEnabled() == false || to.IsEnabled() == false) return; var component = from.GetLayoutComponent(link.sourceComponentTag); if (component != null) { var rect = component.tempEditorRect; var start = new Rect(from.rect.x + rect.x, from.rect.y + rect.y, rect.width, rect.height); var end = to.rect; var zOffset = -4f; var offset = Vector2.zero; var startPos = new Vector3(start.center.x + offset.x, start.center.y + offset.y, zOffset); var endPos = new Vector3(end.center.x + offset.x, end.center.y + offset.y, zOffset); var scale = FlowSystem.GetData().flowWindowWithLayoutScaleFactor; var side1 = from.rect.size.x * 0.5f; var side2 = from.rect.size.y * 0.5f; var stopDistance = Mathf.Sqrt(side1 * side1 + side2 * side2); var color = Color.white; if (from.GetContainer() != to.GetContainer()) { color = Color.gray; if (to.GetContainer() != null) color = to.GetContainer().randomColor; } var comment = this.DrawComponentCurve(startPos, endPos, color, stopDistance + 50f * scale, link.comment); if (link.comment != comment) { link.comment = comment; FlowSystem.SetDirty(); } } }
private void SelectWindow(FlowWindow window) { for (int i = 0; i < window.states.Length; ++i) window.SetCompletedState(i, CompletedState.NotReady); if (window.compiled == false) { this.ShowNotification(new GUIContent("You need to compile this window to use `Select` command")); } else { if (Directory.Exists(window.compiledDirectory) == false) { window.compiledDirectory = Path.GetDirectoryName(AssetDatabase.GetAssetPath(FlowSystem.GetData())) + "/" + window.compiledNamespace.Replace(FlowSystem.GetData().namespaceName, string.Empty) + "/" + window.compiledNamespace.Replace(".", "/"); } Selection.activeObject = AssetDatabase.LoadAssetAtPath(window.compiledDirectory.Trim('/'), typeof(Object)); EditorGUIUtility.PingObject(Selection.activeObject); //if (window.screen == null) { window.SetCompletedState(0, CompletedState.NotReady); var files = AssetDatabase.FindAssets("t:GameObject", new string[] { window.compiledDirectory.Trim('/') + "/Screens" }); foreach (var file in files) { var path = AssetDatabase.GUIDToAssetPath(file); var go = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject; if (go != null) { var screen = go.GetComponent<WindowBase>(); if (screen != null) { window.SetScreen(screen); window.SetCompletedState(0, CompletedState.Ready); var lWin = screen as LayoutWindowType; if (lWin != null) { if (lWin.layout.layout != null) { window.SetCompletedState(1, CompletedState.Ready); window.SetCompletedState(2, (lWin.layout.components.Any((c) => c.component == null) == true) ? CompletedState.ReadyButWarnings : CompletedState.Ready); } else { window.SetCompletedState(0, CompletedState.NotReady); window.SetCompletedState(1, CompletedState.NotReady); window.SetCompletedState(2, CompletedState.NotReady); } } else { window.SetCompletedState(1, CompletedState.Ready); } break; } else { window.SetCompletedState(0, CompletedState.ReadyButWarnings); } } } //} } }
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); }*/ }
private void DrawTags(FlowWindow window, bool defaultWindow = false) { EditorGUIUtility.labelWidth = 35f; var tagStyles = FlowSystemEditor.GetTagStyles(); var tagCaptionStyleText = ME.Utilities.CacheStyle("FlowEditor.DrawTags.Styles", "sv_label_0"); var tagCaptionStyle = ME.Utilities.CacheStyle("FlowEditor.DrawTags.Styles", "tagCaptionStyle", (styleName) => { var _tagCaptionStyle = new GUIStyle(GUI.skin.textField); _tagCaptionStyle.alignment = TextAnchor.MiddleCenter; _tagCaptionStyle.fixedWidth = 90f; _tagCaptionStyle.fixedHeight = tagCaptionStyleText.fixedHeight; _tagCaptionStyle.stretchWidth = false; _tagCaptionStyle.font = tagCaptionStyleText.font; _tagCaptionStyle.fontStyle = tagCaptionStyleText.fontStyle; _tagCaptionStyle.fontSize = tagCaptionStyleText.fontSize; _tagCaptionStyle.normal = tagCaptionStyleText.normal; _tagCaptionStyle.focused = tagCaptionStyleText.normal; _tagCaptionStyle.active = tagCaptionStyleText.normal; _tagCaptionStyle.hover = tagCaptionStyleText.normal; _tagCaptionStyle.border = tagCaptionStyleText.border; //_tagCaptionStyle.padding = tagCaptionStyleText.padding; //_tagCaptionStyle.margin = tagCaptionStyleText.margin; _tagCaptionStyle.margin = new RectOffset(); return _tagCaptionStyle; }); var tagStyleAdd = ME.Utilities.CacheStyle("FlowEditor.DrawTags.Styles", "sv_label_3", (styleName) => { var _tagStyleAdd = new GUIStyle(styleName); _tagStyleAdd.margin = new RectOffset(0, 0, 0, 0); _tagStyleAdd.padding = new RectOffset(3, 5, 0, 2); _tagStyleAdd.alignment = TextAnchor.MiddleCenter; _tagStyleAdd.stretchWidth = false; return _tagStyleAdd; }); var tagsLabel = ME.Utilities.CacheStyle("FlowEditor.DrawTags.Styles", "defaultLabel", (styleName) => { var _tagsLabel = new GUIStyle(FlowSystemEditorWindow.defaultSkin.label); _tagsLabel.padding = new RectOffset(_tagsLabel.padding.left, _tagsLabel.padding.right, _tagsLabel.padding.top, _tagsLabel.padding.bottom + 4); return _tagsLabel; }); var changed = false; GUILayout.BeginHorizontal(); { GUILayoutExt.LabelWithShadow("Tags:", tagsLabel, GUILayout.Width(EditorGUIUtility.labelWidth)); GUILayout.BeginVertical(); { GUILayout.Space(4f); var tagCaption = string.Empty; if (this.showTagsPopupId == window.id) tagCaption = this.tagCaption; var isEnter = (Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.Return); GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { var columns = 3; var i = 0; foreach (var tag in window.tags) { if (i % columns == 0) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } var tagInfo = FlowSystem.GetData().GetTag(tag); if (tagInfo == null) { window.tags.Remove(tag); break; } if (GUILayout.Button(tagInfo.title, tagStyles[tagInfo.color]) == true) { FlowSystem.RemoveTag(window, tagInfo); break; } ++i; } if (i % columns != 0) GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { var newTagCaption = string.Empty; var rect = new Rect(); GUILayout.BeginHorizontal(); { var oldEnabled = GUI.enabled; GUI.enabled = !string.IsNullOrEmpty(this.tagCaption) && (this.showTagsPopupId == window.id); if ((GUILayout.Button(new GUIContent("+"), tagStyleAdd) == true || isEnter == true) && GUI.enabled == true) { FlowSystem.AddTag(window, new FlowTag(FlowSystem.GetData().GetNextTagId(), this.tagCaption)); this.tagCaption = string.Empty; } GUI.enabled = oldEnabled; newTagCaption = GUILayout.TextField(tagCaption, tagCaptionStyle); rect = GUILayoutUtility.GetLastRect(); } GUILayout.EndHorizontal(); if (tagCaption != newTagCaption) { this.showTagsPopupId = window.id; this.tagCaption = newTagCaption; this.showTagsPopup = false; changed = true; } if (this.showTagsPopupId == window.id && newTagCaption.Length > 0) { // Show Tags Popup var allTags = FlowSystem.GetTags(); if (allTags != null) { this.showTagsPopup = true; if (Event.current.type == EventType.Repaint) { this.showTagsPopupRect = new Rect(window.rect.x + rect.x + SETTINGS_WIDTH, window.rect.y + rect.y + (defaultWindow == true ? window.rect.height : 0f), rect.width, rect.height); } if (changed == true) this.Repaint(); } } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); if (changed == true) { this.Repaint(); } EditorGUIUtility.LookLikeControls(); }
public void SetCenterTo(FlowWindow window) { FlowSystem.SetZoom(1f); FlowSystem.SetScrollPosition(-new Vector2(window.rect.x - this.scrollRect.width * 0.5f, window.rect.y - this.scrollRect.height * 0.5f)); }
public FlowWindow CreateDefaultLink() { var newId = this.AllocateId(); var window = new FlowWindow(newId, isDefaultLink: true); window.title = "Default Link"; window.rect.width = 150f; window.rect.height = 30f; this.windows.Add(window); this.windowsCache.Clear(); this.isDirty = true; return window; }
public FlowWindow CreateWindow(FlowWindow.Flags flags) { var newId = this.AllocateId(); var window = new FlowWindow(newId, flags); this.windows.Add(window); this.windowsCache.Clear(); this.isDirty = true; return window; }
public AttachItem GetAttachItem(FlowWindow window) { return(this.attachItems.FirstOrDefault((item) => item.targetId == window.id)); }
public static void AddTag(FlowWindow window, FlowTag tag) { FlowSystem.instance.data.AddTag(window, tag); }
public FlowWindow CreateWindow() { var newId = this.AllocateId(); var window = new FlowWindow(newId, isContainer: false); this.windows.Add(window); this.windowsCache.Clear(); this.isDirty = true; return window; }
public static string GetBaseClassName(FlowWindow flowWindow) { return flowWindow.directory.UppercaseFirst() + "ScreenBase"; }
public static string GetNamespace(FlowWindow window) { return Tpl.GetNamespace() + IO.GetRelativePath(window, "."); }
public float GetTagsHeight(FlowWindow window) { var columns = 3; var height = 16f; return Mathf.CeilToInt(window.tags.Count / (float)columns) * height + height + 2f; }
public Vector2 GetWindowSize(FlowWindow window) { var flowWindowWithLayout = FlowSystem.GetData().flowWindowWithLayout; var flowWindowWithLayoutScaleFactor = FlowSystem.GetData().flowWindowWithLayoutScaleFactor; if (flowWindowWithLayout == true) { return new Vector2(250f, 250f) * (1f + flowWindowWithLayoutScaleFactor); } return new Vector2(250f, 80f + (Mathf.CeilToInt(window.tags.Count / 3f)) * 15f); }
private void DrawStates(CompletedState[] states, FlowWindow window) { if (states == null) return; var oldColor = GUI.color; var style = ME.Utilities.CacheStyle("FlowEditor.DrawStates.Styles", "Grad Down Swatch"); var elemWidth = style.fixedWidth - 3f; var width = window.rect.width - 6f; var posY = -9f; var color = Color.black; color.a = 0.6f; var posX = width - elemWidth; var shadowOffset = 1f; for (int i = states.Length - 1; i >= 0; --i) { GUI.color = color; GUI.Label(new Rect(posX + shadowOffset, posY + shadowOffset, elemWidth, style.fixedHeight), string.Empty, style); posX -= elemWidth; } posX = width - elemWidth; for (int i = states.Length - 1; i >= 0; --i) { var state = states[i]; if (state == CompletedState.NotReady) { color = new Color(1f, 0.3f, 0.3f, 1f); } else if (state == CompletedState.Ready) { color = new Color(0.3f, 1f, 0.3f, 1f); } else if (state == CompletedState.ReadyButWarnings) { color = new Color(1f, 1f, 0.3f, 1f); } GUI.color = color; GUI.Label(new Rect(posX, posY, elemWidth, style.fixedHeight), string.Empty, style); posX -= elemWidth; } GUI.color = oldColor; }
public void DrawTransitionChooser(UnityEngine.UI.Windows.Plugins.Flow.FlowWindow.AttachItem attach, FlowWindow fromWindow, FlowWindow toWindow, Vector2 offset, float size) { var _size = Vector2.one * size; var rect = new Rect(Vector2.Lerp(fromWindow.rect.center, toWindow.rect.center, 0.5f) + offset - _size * 0.5f, _size); var transitionStyle = ME.Utilities.CacheStyle("UI.Windows.Styles.DefaultSkin", "TransitionIcon", (name) => FlowSystemEditorWindow.defaultSkin.FindStyle("TransitionIcon")); var transitionStyleBorder = ME.Utilities.CacheStyle("UI.Windows.Styles.DefaultSkin", "TransitionIconBorder", (name) => FlowSystemEditorWindow.defaultSkin.FindStyle("TransitionIconBorder")); if (transitionStyle != null && transitionStyleBorder != null) { if (fromWindow.GetScreen() != null) { System.Action onClick = () => { FlowChooserFilter.CreateTransition(fromWindow, toWindow, "/Transitions", (element) => { FlowSystem.Save(); }); }; // Has transition or not? var hasTransition = attach.transition != null && attach.transitionParameters != null; if (hasTransition == true) { var hovered = rect.Contains(Event.current.mousePosition); if (attach.editor == null) { attach.editor = Editor.CreateEditor(attach.transitionParameters) as IPreviewEditor; hovered = true; } if (attach.editor.HasPreviewGUI() == true) { if (hovered == false) { attach.editor.OnDisable(); } else { attach.editor.OnEnable(); } var style = new GUIStyle(EditorStyles.toolbarButton); attach.editor.OnPreviewGUI(Color.white, rect, style, false, false, hovered); } if (GUI.Button(rect, string.Empty, transitionStyleBorder) == true) { onClick(); } } else { GUI.Box(rect, string.Empty, transitionStyle); if (GUI.Button(rect, string.Empty, transitionStyleBorder) == true) { onClick(); } } } } }
public bool IsVisible(FlowWindow window) { /*var scrollPos = FlowSystem.GetScrollPosition(); var rect = new Rect(scrollPos.x - this.scrollRect.width * 0.5f + this.scrollRect.x, scrollPos.y + this.scrollRect.y, this.scrollRect.width, this.scrollRect.height); var newState = true;//rect.ScaleSizeBy(this.zoomDrawer.GetZoom()).Overlaps(window.rect.ScaleSizeBy(this.zoomDrawer.GetZoom())); if (newState == true && window.isVisibleState == false) { window.isVisibleState = true; this.Repaint(); return false; } return newState;*/ return true; }
public static void RemoveTag(FlowWindow window, FlowTag tag) { FlowSystem.instance.data.RemoveTag(window, tag); }
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); } }
private static IEnumerable<FlowWindow> GetParentContainers(FlowWindow window, IEnumerable<FlowWindow> containers) { var parent = containers.FirstOrDefault(where => where.attaches.Contains(window.id)); while (parent != null) { yield return parent; parent = containers.FirstOrDefault(where => where.attaches.Contains(parent.id)); } }
public void DrawWindowLayout(FlowWindow window) { var flowWindowWithLayout = FlowSystem.GetData().flowWindowWithLayout; if (flowWindowWithLayout == true) { if (this.layoutBoxStyle == null) this.layoutBoxStyle = FlowSystemEditorWindow.defaultSkin.FindStyle("LayoutBox"); GUILayout.Box(string.Empty, this.layoutBoxStyle, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true)); var rect = GUILayoutUtility.GetLastRect(); if (window.OnPreviewGUI(rect, FlowSystemEditorWindow.defaultSkin.button, this.layoutBoxStyle, drawInfo: true, selectable: true, onCreateScreen: () => { this.SelectWindow(window); FlowChooserFilter.CreateScreen(Selection.activeObject, window.compiledNamespace, "/Screens", () => { this.SelectWindow(window); }); }, onCreateLayout: () => { this.SelectWindow(window); Selection.activeObject = window.GetScreen(); FlowChooserFilter.CreateLayout(Selection.activeObject, Selection.activeGameObject, () => { this.SelectWindow(window); }); }) == true) { // Set for waiting connection var element = WindowLayoutElement.waitForComponentConnectionElementTemp; this.WaitForAttach(window.id, element); WindowLayoutElement.waitForComponentConnectionTemp = false; } UnityEditor.UI.Windows.Plugins.Flow.Flow.OnDrawWindowLayoutGUI(rect, window); } }
public static string GetRelativePath(FlowWindow window, string token) { var result = GetParentContainers(window, FlowSystem.GetContainers()) .Reverse() .Select(w => w.directory) .Aggregate(string.Empty, (total, path) => total + token + path); if (string.IsNullOrEmpty(result) == true) { result = token + FlowDatabase.OTHER_NAME; } result += token + window.directory; return result; }
private void BringBackOrFront(FlowWindow current, IEnumerable<FlowWindow> windows) { // Is any of other window has bigger size and collide current foreach (var window in windows) { if (window.id != current.id) { var p1 = window.rect.width * window.rect.height; var p2 = current.rect.width * current.rect.height; if (p1 > p2 && window.rect.Overlaps(current.rect) == true) { // Bring window to front GUI.BringWindowToFront(current.id); if (this.bringFront.ContainsKey(current.id) == true) { foreach (var item in this.bringFront[current.id]) { GUI.BringWindowToFront(item.id); } } if (this.bringFront.ContainsKey(window.id) == true) { this.bringFront[window.id].Add(current); } else { this.bringFront.Add(window.id, new List<FlowWindow>() { current }); } } } } }
/* private static bool CompiledInfoIsInvalid( FlowWindow flowWindow ) { return GetBaseClassName( flowWindow ) != flowWindow.compiledBaseClassName || GetNamespace( flowWindow ) != flowWindow.compiledNamespace; } private static void UpdateInheritedClasses( string oldBaseClassName, string newBaseClassName, string oldDerivedClassName, string newDerivedClassName, string oldNamespace, string newNamespace ) { if ( string.IsNullOrEmpty( oldBaseClassName ) || string.IsNullOrEmpty( newBaseClassName ) ) { return; } var oldFullClassPath = oldNamespace + oldBaseClassName; var newFullClassPath = newNamespace + newBaseClassName; AssetDatabase.StartAssetEditing(); try { var scripts = AssetDatabase.FindAssets( "t:MonoScript" ) .Select( _ => AssetDatabase.GUIDToAssetPath( _ ) ) .Select( _ => AssetDatabase.LoadAssetAtPath( _, typeof( MonoScript ) ) ) .OfType<MonoScript>() .Where( _ => _.text.Contains( oldBaseClassName ) || _.text.Contains( oldDerivedClassName ) || _.text.Contains( oldNamespace ) ) .Where( _ => _.name != newBaseClassName ); foreach ( var each in scripts ) { var path = AssetDatabase.GetAssetPath( each ); var lines = File.ReadAllLines( path ); var writer = new StreamWriter( path ); foreach ( var line in lines ) { writer.WriteLine( line.Replace( oldFullClassPath, newFullClassPath ) .Replace( oldNamespace, newNamespace ) .Replace( oldBaseClassName, newBaseClassName ) .Replace( oldDerivedClassName, newDerivedClassName ) ); } writer.Dispose(); } } catch ( Exception e ) { Debug.LogException( e ); } AssetDatabase.StopAssetEditing(); AssetDatabase.Refresh( ImportAssetOptions.ForceUpdate ); } private static void GenerateUIWindow( string fullpath, FlowWindow window, bool recompile = false ) { var isCompiledInfoInvalid = window.compiled && CompiledInfoIsInvalid( window ); if ( window.compiled == false || recompile == true || isCompiledInfoInvalid ) { var baseClassName = GetBaseClassName( window ); var derivedClassName = GetDerivedClassName( window ); var classNamespace = GetNamespace( window ); var baseClassTemplate = FlowTemplateGenerator.GenerateWindowLayoutBaseClass( baseClassName, classNamespace, GenerateTransitionMethods( window ) ); var derivedClassTemplate = FlowTemplateGenerator.GenerateWindowLayoutDerivedClass( derivedClassName, baseClassName, classNamespace ); #if !UNITY_WEBPLAYER var baseClassPath = ( fullpath + "/" + baseClassName + ".cs" ).Replace( "//", "/" ); var derivedClassPath = ( fullpath + "/" + derivedClassName + ".cs" ).Replace( "//", "/" ); #endif if ( baseClassTemplate != null && derivedClassTemplate != null ) { IO.CreateDirectory( fullpath, string.Empty ); IO.CreateDirectory( fullpath, FlowDatabase.COMPONENTS_FOLDER ); IO.CreateDirectory( fullpath, FlowDatabase.LAYOUT_FOLDER ); IO.CreateDirectory( fullpath, FlowDatabase.SCREENS_FOLDER ); #if !UNITY_WEBPLAYER Directory.CreateDirectory( fullpath ); File.WriteAllText( baseClassPath, baseClassTemplate ); if ( !File.Exists( derivedClassPath ) ) { File.WriteAllText( derivedClassPath, derivedClassTemplate ); AssetDatabase.ImportAsset( derivedClassName ); } AssetDatabase.ImportAsset( baseClassPath ); #endif } else { return; } var oldBaseClassName = window.compiledBaseClassName; var newBaseClassName = baseClassName; var oldDerivedClassName = window.compiledDerivedClassName; var newDerivedClassName = derivedClassName; var oldNamespace = window.compiledNamespace; window.compiledBaseClassName = baseClassName; window.compiledDerivedClassName = derivedClassName; window.compiledNamespace = classNamespace; var newNamespace = window.compiledNamespace; window.compiledDirectory = fullpath; window.compiled = true; AssetDatabase.Refresh( ImportAssetOptions.ForceUpdate ); if ( isCompiledInfoInvalid ) { EditorApplication.delayCall += () => UpdateInheritedClasses( oldBaseClassName, newBaseClassName, oldDerivedClassName, newDerivedClassName, oldNamespace, newNamespace ); } } } public static void GenerateUI( string pathToData, bool recompile = false, Func<FlowWindow, bool> predicate = null ) { var filename = Path.GetFileName( pathToData ); var directory = pathToData.Replace( filename, "" ); currentProject = Path.GetFileNameWithoutExtension( pathToData ); var basePath = directory + currentProject; CreateDirectory( basePath, string.Empty ); CreateDirectory( basePath, FlowDatabase.OTHER_NAME ); AssetDatabase.StartAssetEditing(); predicate = predicate ?? delegate { return true; }; try { foreach ( var each in FlowSystem.GetWindows().Where( _ => !_.isDefaultLink && predicate( _ ) ) ) { var relativePath = GetRelativePath( each, "/" ); if ( !string.IsNullOrEmpty( each.directory ) ) { CreateDirectory( basePath, relativePath ); } GenerateUIWindow( basePath + relativePath + "/", each, recompile ); } } catch ( Exception e ) { Debug.LogException( e ); } AssetDatabase.StopAssetEditing(); AssetDatabase.Refresh( ImportAssetOptions.ForceUpdate ); }*/ #endregion private static void GenerateWindow(string newPath, FlowWindow window, bool recompile) { if (window.compiled == true && recompile == false) return; var oldPath = window.compiledDirectory; var newInfo = new Tpl.Info(Tpl.GetNamespace(window), Tpl.GetDerivedClassName(window), Tpl.GetBaseClassName(window), window.directory); var oldInfo = new Tpl.Info(window); if (string.IsNullOrEmpty(oldPath) == true) { oldPath = newPath; } var path = oldPath; if (window.compiled == true && (oldPath != newPath)) { // If window is moving and compiled - just rename // Replace in files IO.ReplaceInFiles(FlowCompilerSystem.currentProjectDirectory, (file) => { var text = file.text; return text.Contains(oldInfo.baseNamespace); }, (text) => { return Tpl.ReplaceText(text, oldInfo, newInfo); }); // Rename base class name IO.RenameFile(oldPath + oldInfo.baseClassnameFile, oldPath + newInfo.baseClassnameFile); // Rename derived class name IO.RenameFile(oldPath + oldInfo.classnameFile, oldPath + newInfo.classnameFile); // Rename main folder IO.RenameDirectory(oldPath, newPath); path = newPath; } // Rebuild without rename //Debug.Log(window.title + " :: REBUILD BASE :: " + path); IO.CreateDirectory(path, string.Empty); IO.CreateDirectory(path, FlowDatabase.COMPONENTS_FOLDER); IO.CreateDirectory(path, FlowDatabase.LAYOUT_FOLDER); IO.CreateDirectory(path, FlowDatabase.SCREENS_FOLDER); var baseClassTemplate = FlowTemplateGenerator.GenerateWindowLayoutBaseClass(newInfo.baseClassname, newInfo.baseNamespace, Tpl.GenerateTransitionMethods(window)); var derivedClassTemplate = FlowTemplateGenerator.GenerateWindowLayoutDerivedClass(newInfo.classname, newInfo.baseClassname, newInfo.baseNamespace); if (baseClassTemplate != null && derivedClassTemplate != null) { IO.CreateFile(path, newInfo.baseClassnameFile, baseClassTemplate, rewrite: true); IO.CreateFile(path, newInfo.classnameFile, derivedClassTemplate, rewrite: false); } window.compiledNamespace = newInfo.baseNamespace; window.compiledScreenName = newInfo.screenName; window.compiledBaseClassName = newInfo.baseClassname; window.compiledDerivedClassName = newInfo.classname; window.compiledDirectory = path; window.compiled = true; }
public bool HasContainer(FlowWindow predicate) { return(this.attachItems.Any((item) => item.targetId == predicate.id && FlowSystem.GetWindow(item.targetId).IsContainer())); }
public static void GenerateByWindow(string pathToData, bool recompile = false, FlowWindow window = null) { FlowCompilerSystem.Generate(pathToData, recompile, flowWindow => flowWindow == window); }
public static string GenerateTransitionMethods(FlowWindow window) { var flowData = FlowSystem.GetData(); var transitions = flowData.windows.Where(w => window.attaches.Contains(w.id) && w.CanCompiled() && !w.IsContainer()); var result = string.Empty; foreach (var each in transitions) { var className = each.directory; var classNameWithNamespace = Tpl.GetNamespace(each) + "." + Tpl.GetDerivedClassName(each); result += FlowTemplateGenerator.GenerateWindowLayoutTransitionMethod(className, classNameWithNamespace); } // Make FlowDefault() method if exists var c = 0; var everyPlatformHasUniqueName = false; foreach (var attachId in window.attaches) { var attachedWindow = FlowSystem.GetWindow(attachId); var tmp = UnityEditor.UI.Windows.Plugins.Flow.Flow.IsCompilerTransitionAttachedGeneration(attachedWindow); if (tmp == true) ++c; } everyPlatformHasUniqueName = c > 1; foreach (var attachId in window.attaches) { var attachedWindow = FlowSystem.GetWindow(attachId); if (attachedWindow.IsShowDefault() == true) { result += FlowTemplateGenerator.GenerateWindowLayoutTransitionMethodDefault(); } result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionAttachedGeneration(attachedWindow, everyPlatformHasUniqueName); } // Run addons transition logic result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionGeneration(window); return result; }
public bool HasContainer(FlowWindow predicate) { return(this.attaches.Any((id) => id == predicate.id && FlowSystem.GetWindow(id).isContainer)); }