private void ArrangeByGrid(WindowLayoutElement element, Vector2 grid)
        {
            var rect = element.transform as RectTransform;

            rect.anchoredPosition = this.GridBy(rect.anchoredPosition, grid);
            rect.sizeDelta        = this.GridBy(rect.sizeDelta, grid);
        }
Beispiel #2
0
            public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root)
            {
                this.root = root;

                if (this.component == null && this.root == null)
                {
                    return(null);
                }

                if (this.component == null)
                {
                    this.root.Setup(null, this);
                    return(null);
                }

                var instance = this.component.Spawn();

                instance.SetParent(root, setTransformAsSource: false);
                instance.SetTransformAs();

                var rect = instance.transform as RectTransform;

                rect.sizeDelta        = (this.component.transform as RectTransform).sizeDelta;
                rect.anchoredPosition = (this.component.transform as RectTransform).anchoredPosition;

                this.root.Setup(instance, this);
                instance.Setup(window);

                instance.transform.SetSiblingIndex(this.sortingOrder);

                this.instance = instance;

                return(instance);
            }
        public override void OnInit()
        {
            base.OnInit();

            this.all = ME.ListPool <string> .Get();

            this.queue = ME.ListPool <string> .Get();

            this.GetLayoutComponent(out this.exceptionBorder, LayoutTag.Tag6);
            this.GetLayoutComponent(out this.alwaysShownText, LayoutTag.Tag4);

            this.GetLayoutComponent(out this.commandQueue);
            this.commandQueue.SetScreen(this);

            this.queueContainer = this.GetLayoutContainer(LayoutTag.Tag3);

            this.GetLayoutComponent(out this.commandLine);
            this.commandLine.SetCallbacks(null, (text) => {
                this.AddLineCmd(text);
            });

            this.container = this.GetLayoutContainer(LayoutTag.Tag1);

            this.HideExceptionBorder();
            Application.logMessageReceived += this.OnMessage;
        }
Beispiel #4
0
        public override void OnInit()
        {
            base.OnInit();

            this.all = ME.ListPool <string> .Get();

            this.queue = ME.ListPool <string> .Get();

            this.GetLayoutComponent(out this.exceptionBorder, LayoutTag.Tag6);
            this.GetLayoutComponent(out this.alwaysShownText, LayoutTag.Tag4);

            this.GetLayoutComponent(out this.commandQueue);
            this.commandQueue.SetScreen(this);

            this.queueContainer = this.GetLayoutContainer(LayoutTag.Tag3);

            this.GetLayoutComponent(out this.commandLine);
            this.commandLine.SetCallbacks(null, (text) => {
                if (text.Trim() != "`" && string.IsNullOrEmpty(text.Trim()) == false)
                {
                    UnityEngine.UI.Windows.Plugins.Analytics.Analytics.SendEvent(this.windowId, "Command", text);
                }
                this.AddLineCmd(text);
            });

            this.container = this.GetLayoutContainer(LayoutTag.Tag1);

            this.HideExceptionBorder();
            Application.logMessageReceived += this.OnMessage;
        }
Beispiel #5
0
        public void Detach(int source, int other, bool oneWay, WindowLayoutElement component = null)
        {
            var window = this.GetWindow(source);

            window.Detach(other, oneWay, component);

            this.isDirty = true;
        }
Beispiel #6
0
        public bool AlreadyAttached(int source, int other, WindowLayoutElement component = null)
        {
            if (component != null)
            {
                return(this.windows.Any((w) => w.id == source && w.AlreadyAttached(other, component)));
            }

            return(this.windows.Any((w) => w.id == source && w.AlreadyAttached(other)));
        }
Beispiel #7
0
        public bool AlreadyAttached(int id, WindowLayoutElement component = null)
        {
            if (component != null)
            {
                return(this.attachedComponents.Any((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag));
            }

            return(this.attaches.Contains(id));
        }
Beispiel #8
0
        public bool AlreadyAttached(int id, int index = 0, WindowLayoutElement component = null)
        {
            if (component != null)
            {
                return(this.attachedComponents.Any((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag));
            }

            return(this.attachItems.Any((item) => item.targetId == id && item.index == index));
        }
Beispiel #9
0
            public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root)
            {
                this.root = root;

                if (this.component == null && this.root == null)
                {
                    return(null);
                }

                if (this.component == null)
                {
                    this.root.Setup(null, this);
                    return(null);
                }

                var instance = this.component.Spawn();

                //instance.SetComponentState(WindowObjectState.NotInitialized);
                instance.SetParent(root, setTransformAsSource: false, worldPositionStays: false);
                instance.SetTransformAs();

                if (this.componentParameters != null)
                {
                    instance.Setup(this.componentParameters);
                }

                var rect = instance.transform as RectTransform;

                if (rect != null)
                {
                    rect.sizeDelta        = (this.component.transform as RectTransform).sizeDelta;
                    rect.anchoredPosition = (this.component.transform as RectTransform).anchoredPosition;
                }

                this.root.Setup(instance, this);
                instance.Setup(window);

                if (instance.autoRegisterInRoot == true && root.autoRegisterSubComponents == true)
                {
                    root.RegisterSubComponent(instance);
                }

                instance.transform.SetSiblingIndex(this.sortingOrder);

                this.instance = instance;

                return(instance);
            }
Beispiel #10
0
    public override void OnInit()
    {
        base.OnInit();

        this.content = this.GetLayoutContainer(LayoutTag.Tag2);

        this.tabs = this.GetLayoutComponent <Tabs>();
        this.tabs.SetContent(this.content);

        var i = 0;

        foreach (var component in this.components)
        {
            var button = this.tabs.AddItem <ButtonWithTextComponent, WindowComponent>(component);
            button.SetText((++i).ToString() + ". " + component.name);
        }
    }
        public void OnEnable()
        {
            SceneView.onSceneGUIDelegate -= this.OnSceneView;
            SceneView.onSceneGUIDelegate += this.OnSceneView;

            this._target = this.target as WindowLayoutElement;
            if (this._target == null)
            {
                return;
            }

            this.layout = this._target.GetComponentInParent <WindowLayout>();

            if (this._target != null)
            {
                this.lastPivot = (this._target.transform as RectTransform).pivot;
            }
        }
Beispiel #12
0
        public bool Attach(int id, int index = 0, bool oneWay = false, WindowLayoutElement component = null)
        {
            if (this.id == id)
            {
                return(false);
            }

            var result = false;

            if (component != null)
            {
                if (this.attachedComponents.Any((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag) == false)
                {
                    this.attachedComponents.Add(new ComponentLink(id, component.tag, component.comment));

                    // If we attaching component - try to attach window if not

                    oneWay = true;
                    result = true;
                }
                else
                {
                    return(false);
                }
            }

            if (this.AlreadyAttached(id, index) == false)
            {
                this.attachItems.Add(new AttachItem(id, index));

                if (oneWay == false)
                {
                    var window = FlowSystem.GetWindow(id);
                    window.Attach(this.id, oneWay: true);
                }

                return(true);
            }

            return(result);
        }
Beispiel #13
0
        public bool Detach(int id, int index = 0, bool oneWay = false, WindowLayoutElement component = null)
        {
            if (this.id == id)
            {
                return(false);
            }

            var result = false;

            if (component != null)
            {
                if (this.attachedComponents.Any((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag) == true)
                {
                    this.attachedComponents.RemoveAll((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag);

                    result = true;
                }
            }
            else
            {
                if (this.AlreadyAttached(id, index) == true)
                {
                    this.attachItems.RemoveAll((c) => c.targetId == id && c.index == index);
                    this.attachedComponents.RemoveAll((c) => c.targetWindowId == id);

                    result = true;
                }

                if (oneWay == false)
                {
                    var window = FlowSystem.GetWindow(id);
                    if (window != null)
                    {
                        result = window.Detach(this.id, oneWay: true);
                    }
                }
            }

            return(result);
        }
Beispiel #14
0
        public override void OnFlowWindowScreenMenuGUI(FD.FlowWindow windowSource, GenericMenu menu)
        {
            menu.AddItem(new GUIContent("Components Editor..."), on: false, func: (object win) => {
                var window = win as FD.FlowWindow;
                var screen = window.GetScreen() as LayoutWindowType;
                if (screen != null)
                {
                    this.flowEditor.SetDisabled();
                    //this.window = window;
                    this.screen = screen;
                    this.editor = Editor.CreateEditor(window.GetScreen()) as IPreviewEditor;

                    this.component          = null;
                    this.hovered            = null;
                    this.element            = null;
                    this.listScrollPosition = Vector2.zero;
                    var serializedObject    = new SerializedObject(this.screen);
                    var layout     = serializedObject.FindProperty("layout");
                    var components = layout.FindPropertyRelative("components");
                    this.props.Clear();
                    for (int i = 0; i < components.arraySize; ++i)
                    {
                        var component = components.GetArrayElementAtIndex(i);
                        this.props.Add(component);

                        var componentParametersEditor = this.screen.layout.components[i].OnComponentChanged(this.screen, this.screen.layout.components[i].component);
                        if (componentParametersEditor != null)
                        {
                            var e = Editor.CreateEditor(componentParametersEditor) as IParametersEditor;
                            this.screen.layout.components[i].componentParametersEditor = e;
                        }
                    }

                    this.settingsScrollPosition = Vector2.zero;

                    this.opened = true;
                }
            }, userData: windowSource);
        }
Beispiel #15
0
            public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root)
            {
                this.root = root;

                WindowComponent component = null;

                if (this.componentResource.loadableResource == true)
                {
                    component = this.componentResource.Load <WindowComponent>();
                    if (component == null)
                    {
                        Debug.LogError("[ Layout ] Be sure your UI project placed in Resources folder (ex: Assets/Resources/MyProject/UIProject.asset).");
                    }
                }
                else
                {
                    component = this.componentNoResource;
                }

                if (component == null && this.root == null)
                {
                    return(null);
                }

                if (component == null)
                {
                    this.root.Setup(null, this);
                    return(null);
                }

                var instance = component.Spawn();

                //instance.SetComponentState(WindowObjectState.NotInitialized);
                instance.SetParent(root, setTransformAsSource: false, worldPositionStays: false);
                instance.SetTransformAs();

                if (this.componentParameters != null)
                {
                    instance.Setup(this.componentParameters);
                }

                var rect = instance.transform as RectTransform;

                if (rect != null)
                {
                    rect.sizeDelta        = (component.transform as RectTransform).sizeDelta;
                    rect.anchoredPosition = (component.transform as RectTransform).anchoredPosition;
                }

                this.root.Setup(instance, this);
                instance.Setup(window);

                if (instance.autoRegisterInRoot == true && root.autoRegisterSubComponents == true)
                {
                    root.RegisterSubComponent(instance);
                }

                instance.transform.SetSiblingIndex(this.sortingOrder);

                this.instance = instance;

                return(instance);
            }
 public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, WindowLayoutElement selectedElement)
 {
     this.OnPreviewGUI(color, r, background, drawInfo, selectable, hovered: false, selectedElement: selectedElement, onSelection: null, onElementGUI: null, highlighted: null);
 }
Beispiel #17
0
 public static void Attach(int source, int index, int other, bool oneWay, WindowLayoutElement component = null)
 {
     FlowSystem.instance.data.Attach(source, index, other, oneWay, component);
     FlowSystem.SetCompileDirty();
 }
 public void OnPreviewGUI(Color color, Rect rect, GUIStyle style, WindowLayoutElement selectedElement, System.Action <WindowLayoutElement> onSelection, List <WindowLayoutElement> highlighted)
 {
     this.OnPreviewGUI(color, rect, style, drawInfo: true, selectable: true, hovered: false, selectedElement: selectedElement, onSelection: onSelection, onElementGUI: null, highlighted: highlighted);
 }
		public static void Detach(int source, int other, bool oneWay, WindowLayoutElement component = null) {
			
			FlowSystem.instance.data.Detach(source, other, oneWay, component);

		}
		public bool Detach(int id, bool oneWay = false, WindowLayoutElement component = null) {
			
			if (this.id == id) return false;
			
			var result = false;

			if (component != null) {

				if (this.attachedComponents.Any((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag) == true) {

					this.attachedComponents.RemoveAll((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag);

					result = true;

				}

			} else {

				if (this.attachItems.Any((item) => item.targetId == id) == true) {
					
					this.attachItems.RemoveAll((item) => item.targetId == id);
					this.attachedComponents.RemoveAll((c) => c.targetWindowId == id);
					
					result = true;
					
				}
				
				if (oneWay == false) {
					
					var window = FlowSystem.GetWindow(id);
					if (window != null) result = window.Detach(this.id, oneWay: true);
					
				}

			}

			return result;
			
		}
		public bool AlreadyAttached(int id, WindowLayoutElement component = null) {
			
			if (component != null) {
				
				return this.attachedComponents.Any((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag);
				
			}
			
			return this.attachItems.Any((item) => item.targetId == id);
			
		}
Beispiel #22
0
            public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root)
            {
                this.root = root;

                WindowComponent component = null;

                if (this.componentResource.loadableResource == true)
                {
                    component = this.componentResource.Load <WindowComponent>();
                    if (component == null)
                    {
                        Debug.LogError("[ Layout ] Be sure your UI project placed in Resources folder (ex: Assets/Resources/MyProject/UIProject.asset).");
                    }
                }
                else
                {
                    component = this.componentNoResource;
                                        #if UNITY_EDITOR
                    if (component != null)
                    {
                        Debug.LogWarningFormat("[ Layout ] Resource `{0}` [{1}] should be placed in `Resources` folder to be loaded/unloaded automaticaly. Window `{2}` requested this resource. This warning shown in editor only.", component.name, UnityEditor.AssetDatabase.GetAssetPath(component.GetInstanceID()), window.name);
                    }
                                        #endif
                }

                if (component == null && this.root == null)
                {
                    return(null);
                }

                if (component == null)
                {
                    this.root.Setup(null, this);
                    return(null);
                }

                var instance = component.Spawn();
                //instance.SetComponentState(WindowObjectState.NotInitialized);
                instance.SetParent(root, setTransformAsSource: false, worldPositionStays: false);
                instance.SetTransformAs();

                if (this.componentParameters != null)
                {
                    instance.Setup(this.componentParameters);
                }

                var rect = instance.transform as RectTransform;
                if (rect != null)
                {
                    rect.sizeDelta        = (component.transform as RectTransform).sizeDelta;
                    rect.anchoredPosition = (component.transform as RectTransform).anchoredPosition;
                }

                this.root.Setup(instance, this);
                instance.Setup(window);

                if (instance.autoRegisterInRoot == true && root.autoRegisterSubComponents == true)
                {
                    root.RegisterSubComponent(instance);
                }

                instance.transform.SetSiblingIndex(this.sortingOrder);

                this.instance = instance;

                return(instance);
            }
        public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, System.Action <WindowLayoutElement, Rect, bool> onElementGUI)
        {
            var oldColor = GUI.color;
            var c        = Color.white;

            c.a       = 1f;
            GUI.color = c;
            GUI.Box(r, string.Empty, background);
            GUI.color = oldColor;

            var _target = this.target as UnityEngine.UI.Windows.WindowLayout;

            if (_target == null)
            {
                return;
            }

            var elements = _target.elements;

            if (ME.EditorUtilities.IsPrefab(_target.gameObject) == false && _target.gameObject.activeInHierarchy == true)
            {
                var pos = _target.transform.localPosition;
                _target.transform.localPosition = Vector3.zero;

                foreach (var element in elements)
                {
                    var rectTransform = (element.transform as RectTransform);

                    var corners = new Vector3[4];
                    rectTransform.GetWorldCorners(corners);

                    var rect = new Rect(corners[0].x, -corners[1].y, corners[2].x - corners[1].x, corners[2].y - corners[3].y);

                    element.editorRect = rect;

                    //element.autoStretchX = (rectTransform.anchorMin.x != rectTransform.anchorMax.x);
                    //element.autoStretchY = (rectTransform.anchorMin.y != rectTransform.anchorMax.y);
                }

                _target.root.editorRect = (_target.root.transform as RectTransform).rect;
                (_target.transform as RectTransform).localPosition = pos;
            }

            var scaleFactor = 0f;

            if (elements.Count > 0)
            {
                scaleFactor = this.GetFactor(new Vector2(_target.root.editorRect.width, _target.root.editorRect.height), new Vector2(r.width, r.height));
            }

            var selected       = WindowLayoutStyles.styles.boxSelected;
            var styles         = WindowLayoutStyles.styles.boxes;
            var stylesSelected = WindowLayoutStyles.styles.boxesSelected;

            var horArrowsStyle  = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.horArrowsStyle", "ColorPickerHorizThumb", (style) => new GUIStyle(style));
            var vertArrowsStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.vertArrowsStyle", "ColorPickerVertThumb", (style) => new GUIStyle(style));

            var horStyle  = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.horStyle", "box", (style) => new GUIStyle(style));
            var vertStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.vertStyle", "box", (style) => new GUIStyle(style));

            foreach (var element in elements)
            {
                element.editorDrawDepth = element.GetComponentsInParent <WindowLayoutElement>(true).Length - 1;

                var rect = element.editorRect;

                rect.x *= scaleFactor;
                rect.y *= scaleFactor;

                rect.x += r.x + r.width * 0.5f;
                rect.y += r.y + r.height * 0.5f;

                rect.width  *= scaleFactor;
                rect.height *= scaleFactor;

                var style = styles[Mathf.Clamp(element.editorDrawDepth, 0, WindowLayoutStyles.MAX_DEPTH - 1)];
                if (rect.Contains(Event.current.mousePosition) == true)
                {
                    style = stylesSelected[Mathf.Clamp(element.editorDrawDepth, 0, WindowLayoutStyles.MAX_DEPTH - 1)];

                    element.editorHovered = true;
                    this.Repaint();
                }
                else
                {
                    element.editorHovered = false;
                    this.Repaint();
                }

                if (WindowLayoutElement.waitForComponentConnectionElementTemp == element)
                {
                    style = selected;
                }

                GUI.color = color;
                GUI.Label(rect, string.Empty, style);

                GUI.color = oldColor;

                var boxColor = EditorGUIUtility.isProSkin ? oldColor : new Color(1f, 1f, 1f, 0.2f);

                var marginX = 4f;
                var marginY = 2f;

                if (element.autoStretchX == true)
                {
                    var vRect = new Rect(rect);
                    vRect.x     += marginX;
                    vRect.y      = vRect.y + vRect.height * 0.5f - vertArrowsStyle.fixedHeight * 0.5f;
                    vRect.width -= marginX * 2f;
                    vRect.height = vertArrowsStyle.fixedHeight;

                    GUI.color = oldColor;
                    GUI.Label(vRect, string.Empty, vertArrowsStyle);
                    GUI.color = boxColor;
                    GUI.Label(vRect, string.Empty, vertStyle);
                }

                if (element.autoStretchY == true)
                {
                    var vRect = new Rect(rect);
                    vRect.x       = vRect.x + vRect.width * 0.5f - horArrowsStyle.fixedWidth * 0.5f;
                    vRect.y      += marginY;
                    vRect.width   = horArrowsStyle.fixedWidth;
                    vRect.height -= marginY * 2f;

                    GUI.color = oldColor;
                    GUI.Label(vRect, string.Empty, horArrowsStyle);
                    GUI.color = boxColor;
                    GUI.Label(vRect, string.Empty, horStyle);
                }

                if (Event.current.type == EventType.Repaint)
                {
                    element.tempEditorRect = rect;
                }
            }

            if (drawInfo == true || onElementGUI != null)
            {
                WindowLayoutElement maxDepthElement = null;
                var _maxDepth = -1;
                foreach (var element in elements)
                {
                    if (element.showInComponentsList == false)
                    {
                        continue;
                    }
                    if (element.editorHovered == false)
                    {
                        continue;
                    }

                    if (_maxDepth < element.editorDrawDepth)
                    {
                        _maxDepth       = element.editorDrawDepth;
                        maxDepthElement = element;
                    }
                }

                foreach (var element in elements)
                {
                    if (element.showInComponentsList == false)
                    {
                        continue;
                    }
                    if (element.editorHovered == false || maxDepthElement != element)
                    {
                        continue;
                    }

                    if (GUI.Button(element.tempEditorRect, string.Empty, GUIStyle.none) == true)
                    {
                        if (selectable == true)
                        {
                            WindowLayoutElement.waitForComponentConnectionElementTemp = element;
                            WindowLayoutElement.waitForComponentConnectionTemp        = true;

                            if (onElementGUI != null)
                            {
                                onElementGUI(element, element.tempEditorRect, true);
                            }
                        }
                    }
                    else
                    {
                        if (onElementGUI != null)
                        {
                            onElementGUI(element, element.tempEditorRect, false);
                        }
                    }
                }
            }

            GUI.color = oldColor;
        }
        public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, bool hovered, WindowLayoutElement selectedElement, System.Action <WindowLayoutElement> onSelection, System.Action <WindowLayoutElement, Rect, bool> onElementGUI, List <WindowLayoutElement> highlighted)
        {
            GUI.BeginClip(r);

            var oldColor = GUI.color;
            var c        = Color.white;

            c.a       = 0.3f;
            GUI.color = c;
            GUI.Box(r, string.Empty, background);
            GUI.color = oldColor;

            var _target = this.target as UnityEngine.UI.Windows.WindowLayout;

            if (_target == null)
            {
                return;
            }

            color.a = 0.4f;
            var selectedColor    = color;
            var notSelectedColor = color;

            selectedColor.a    = 0.8f;
            notSelectedColor.a = 0.4f;

            var elements = _target.elements;

            if (ME.EditorUtilities.IsPrefab(_target.gameObject) == false && _target.gameObject.activeInHierarchy == true)
            {
                this.CalculateRects(_target);
            }

            var scaleFactor = 0f;

            if (elements.Count > 0)
            {
                scaleFactor = this.GetFactor(new Vector2(_target.root.editorRectLocal.width, _target.root.editorRectLocal.height), new Vector2(r.width, r.height));
            }

            if (ME.EditorUtilities.IsPrefab(_target.gameObject) == true)
            {
                if (this.processReconnection == false && scaleFactor == 0f)
                {
                    this.processReconnection = true;

                    // We must re-attach prefab
                    var tempGo = UnityEditor.PrefabUtility.InstantiatePrefab(_target.gameObject) as GameObject;
                    Selection.activeGameObject = tempGo;
                    foreach (var component in tempGo.GetComponents <Component>())
                    {
                        var editor = Editor.CreateEditor(component) as WindowLayoutEditor;
                        if (editor != null)
                        {
                            editor.CalculateRects(component as UnityEngine.UI.Windows.WindowLayout);
                            EditorUtility.SetDirty(component);
                        }
                    }

                    var i = 0;
                    EditorApplication.update += () => {
                        ++i;

                        if (i == 30)
                        {
                            UnityEditor.PrefabUtility.ReplacePrefab(tempGo, PrefabUtility.GetPrefabParent(tempGo), ReplacePrefabOptions.ConnectToPrefab);
                            GameObject.DestroyImmediate(tempGo);

                            this.processReconnection = false;
                        }
                    };
                }
            }

            var scaleFactorCanvas = _target.editorScale > 0f ? 1f / _target.editorScale : 1f;

            scaleFactor *= scaleFactorCanvas;

            var selected              = WindowLayoutStyles.styles.boxSelected;
            var styles                = WindowLayoutStyles.styles.boxes;
            var stylesSelected        = WindowLayoutStyles.styles.boxesSelected;
            var elementSelectedStyle  = WindowLayoutStyles.styles.layoutElementSelected;
            var elementHighlightStyle = WindowLayoutStyles.styles.layoutElementHighlighted;

            var horArrowsStyle  = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.horArrowsStyle", "ColorPickerHorizThumb", (style) => new GUIStyle(style));
            var vertArrowsStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.vertArrowsStyle", "ColorPickerVertThumb", (style) => new GUIStyle(style));

            var horStyle  = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.horStyle", "box", (style) => new GUIStyle(style));
            var vertStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.vertStyle", "box", (style) => new GUIStyle(style));

            var tagSelectedRectBool = false;
            var tagSelectedRect     = new Rect();

            var selectedRect = new Rect();

            foreach (var element in elements)
            {
                if (element == null)
                {
                    continue;
                }

                element.editorDrawDepth = element.GetComponentsInParent <WindowLayoutElement>(true).Length - 1;

                var rect = element.editorRect;

                rect.x      *= scaleFactor;
                rect.y      *= scaleFactor;
                rect.x      += r.x + r.width * 0.5f;
                rect.y      += r.y + r.height * 0.5f;
                rect.x      -= r.x;
                rect.y      -= r.y;
                rect.width  *= scaleFactor;
                rect.height *= scaleFactor;

                var styleDepth = Mathf.Clamp(element.editorDrawDepth, 0, WindowLayoutStyles.MAX_DEPTH - 1);

                var style = styles[styleDepth];
                if (rect.Contains(Event.current.mousePosition) == true)
                {
                    style = stylesSelected[styleDepth];

                    element.editorHovered = true;
                    this.Repaint();
                }
                else
                {
                    element.editorHovered = false;
                    this.Repaint();
                }

                if (/*WindowLayoutElement.waitForComponentConnectionElementTemp == element ||*/ Selection.gameObjects.Contains(element.gameObject) == true)
                {
                    style        = selected;
                    selectedRect = rect;
                }

                if (selectedElement != null)
                {
                    GUI.color = (selectedElement == element) ? selectedColor : notSelectedColor;
                    if (selectedElement == element)
                    {
                        style        = selected;
                        selectedRect = rect;
                    }
                }
                else
                {
                    GUI.color = color;
                }

                GUI.Label(rect, string.Empty, style);

                GUI.color = oldColor;

                var boxColor = EditorGUIUtility.isProSkin ? oldColor : new Color(1f, 1f, 1f, 0.2f);

                var marginX = 4f;
                var marginY = 2f;

                if (element.autoStretchX == true)
                {
                    var vRect = new Rect(rect);
                    vRect.x     += marginX;
                    vRect.y      = vRect.y + vRect.height * 0.5f - vertArrowsStyle.fixedHeight * 0.5f;
                    vRect.width -= marginX * 2f;
                    vRect.height = vertArrowsStyle.fixedHeight;

                    GUI.color = oldColor;
                    GUI.Label(vRect, string.Empty, vertArrowsStyle);
                    GUI.color = boxColor;
                    GUI.Label(vRect, string.Empty, vertStyle);
                }

                if (element.autoStretchY == true)
                {
                    var vRect = new Rect(rect);
                    vRect.x       = vRect.x + vRect.width * 0.5f - horArrowsStyle.fixedWidth * 0.5f;
                    vRect.y      += marginY;
                    vRect.width   = horArrowsStyle.fixedWidth;
                    vRect.height -= marginY * 2f;

                    GUI.color = oldColor;
                    GUI.Label(vRect, string.Empty, horArrowsStyle);
                    GUI.color = boxColor;
                    GUI.Label(vRect, string.Empty, horStyle);
                }

                if (Event.current.type == EventType.Repaint)
                {
                    element.tempEditorRect = rect;
                }

                if (UnityEditor.UI.Windows.Plugins.Flow.Layout.LayoutSettingsEditor.selectedTagIndex == (int)element.tag)
                {
                    tagSelectedRectBool = true;
                    tagSelectedRect     = rect;
                }
            }

            if (highlighted != null)
            {
                foreach (var element in elements)
                {
                    if (highlighted.Contains(element) == true)
                    {
                        GUI.Box(element.tempEditorRect, string.Empty, elementHighlightStyle);
                    }
                }
            }

            GUI.Box(selectedRect, string.Empty, elementSelectedStyle);

            if (drawInfo == true || onElementGUI != null || selectable == true)
            {
                WindowLayoutElement maxDepthElement = null;
                var _maxDepth = -1;
                foreach (var element in elements)
                {
                    if (element.showInComponentsList == false)
                    {
                        continue;
                    }
                    if (element.editorHovered == false)
                    {
                        continue;
                    }

                    if (_maxDepth < element.editorDrawDepth)
                    {
                        _maxDepth       = element.editorDrawDepth;
                        maxDepthElement = element;
                    }
                }

                foreach (var element in elements)
                {
                    if (element.showInComponentsList == false)
                    {
                        continue;
                    }
                    if (element.editorHovered == false || maxDepthElement != element)
                    {
                        continue;
                    }

                    if (GUI.Button(element.tempEditorRect, string.Empty, GUIStyle.none) == true)
                    {
                        if (selectable == true)
                        {
                            //WindowLayoutElement.waitForComponentConnectionElementTemp = element;
                            //WindowLayoutElement.waitForComponentConnectionTemp = true;
                            if (onSelection != null)
                            {
                                onSelection(element);
                            }

                            if (onElementGUI != null)
                            {
                                onElementGUI(element, element.tempEditorRect, true);
                            }
                        }
                    }
                    else
                    {
                        if (onElementGUI != null)
                        {
                            onElementGUI(element, element.tempEditorRect, false);
                        }
                    }
                }
            }

            GUI.color = oldColor;

            GUI.EndClip();

            if (tagSelectedRectBool == true)
            {
                var scrollValue = Vector2.zero;

                var inspectorType = Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.InspectorWindow");
                if (EditorWindow.mouseOverWindow != null)
                {
                    var scrollType = inspectorType.GetField("m_ScrollPosition", BindingFlags.Instance | BindingFlags.Public);
                    if (scrollType != null)
                    {
                        scrollValue = (Vector2)scrollType.GetValue(EditorWindow.mouseOverWindow);
                    }
                }

                var tagSelectedRectOffset = tagSelectedRect;
                tagSelectedRectOffset.center += r.center;
                tagSelectedRectOffset.center -= new Vector2(r.width * 0.5f, r.height * 0.5f);
                var rc = UnityEditor.UI.Windows.Plugins.Flow.Layout.LayoutSettingsEditor.selectedTagRect;
                rc.center -= scrollValue;
                GUI.Box(tagSelectedRectOffset, string.Empty, elementHighlightStyle);
                GUI.Box(rc, string.Empty, elementHighlightStyle);
                WindowLayoutEditor.DrawNavigationArrow(true, Vector2.up, tagSelectedRectOffset.xMin <= 20f ? Vector2.down : Vector2.left, rc, tagSelectedRectOffset);
            }
        }
Beispiel #25
0
 public static void Detach(int source, int other, bool oneWay, WindowLayoutElement component = null)
 {
     FlowSystem.instance.data.Detach(source, other, oneWay, component);
 }
            public void Create(WindowBase window, WindowLayoutElement root, System.Action <WindowComponent> callback = null, bool async = false, System.Action <WindowObjectElement> onItem = null)
            {
                if (this.stopped == true)
                {
                    return;
                }

                this.window = window;
                this.root   = root;

                System.Action <WindowComponent> onLoaded = (component) => {
                    if (this.stopped == true)
                    {
                        return;
                    }

                    if (component == null && this.root == null)
                    {
                        if (callback != null)
                        {
                            callback.Invoke(null);
                        }
                        return;
                    }

                    if (component == null)
                    {
                        this.root.Setup(null, this);
                        if (callback != null)
                        {
                            callback.Invoke(null);
                        }
                        return;
                    }

                    //Debug.Log("Unpack component: " + component.name);
                    var instance = component.Spawn(activeByDefault: false);
                    //instance.SetComponentState(WindowObjectState.NotInitialized);
                    instance.SetParent(root, setTransformAsSource: false, worldPositionStays: false);
                    instance.SetTransformAs();

                    if (this.componentParameters != null)
                    {
                        instance.Setup(this.componentParameters);
                    }

                    var rect = instance.transform as RectTransform;
                    if (rect != null)
                    {
                        rect.sizeDelta        = (component.transform as RectTransform).sizeDelta;
                        rect.anchoredPosition = (component.transform as RectTransform).anchoredPosition;
                    }

                    this.root.Setup(instance, this);
                    instance.Setup(window);

                    if (instance.autoRegisterInRoot == true && root.autoRegisterSubComponents == true)
                    {
                        root.RegisterSubComponent(instance);
                    }

                    instance.transform.SetSiblingIndex(this.sortingOrder);

                    this.instance = instance;
                    instance.DoLoad(async, onItem, () => {
                        if (this.stopped == true)
                        {
                            return;
                        }

                        if (instance != null)
                        {
                            instance.gameObject.SetActive(true);
                        }
                        if (callback != null)
                        {
                            callback.Invoke(this.instance as WindowComponent);
                        }
                    });
                };

                WindowComponent loadedComponent = null;

                if (this.componentResource.IsLoadable() == true)
                {
                    WindowSystemResources.LoadRefCounter <WindowComponent>(this, (component) => {
                        loadedComponent = component;
                        onLoaded.Invoke(loadedComponent);

                        WindowSystemResources.Unload(this, this.GetResource(), resetController: false);
                    }, () => {
                                                #if UNITY_EDITOR
                        Debug.LogWarningFormat("[ Layout ] Resource request failed {0} [{1}].", UnityEditor.AssetDatabase.GetAssetPath(this.component.GetInstanceID()), window.name);
                                                #endif
                    }, async);
                    return;
                }
                else
                {
                    loadedComponent = this.componentNoResource;
                                        #if UNITY_EDITOR
                    if (loadedComponent != null)
                    {
                        Debug.LogWarningFormat("[ Layout ] Resource `{0}` [{1}] should be placed in `Resources` folder to be loaded/unloaded automaticaly. Window `{2}` requested this resource. This warning shown in editor only.", loadedComponent.name, UnityEditor.AssetDatabase.GetAssetPath(loadedComponent.GetInstanceID()), window.name);
                    }
                                        #endif
                }

                onLoaded.Invoke(loadedComponent);
            }
		public static bool AlreadyAttached(int source, int other, WindowLayoutElement component = null) {
			
			return FlowSystem.instance.data.AlreadyAttached(source, other, component);

		}
		public static void Attach(int source, int index, int other, bool oneWay, WindowLayoutElement component = null) {

			FlowSystem.instance.data.Attach(source, index, other, oneWay, component);
			FlowSystem.SetCompileDirty();
			
		}
Beispiel #29
0
        public override void OnGUI()
        {
            if (Layout.styles == null)
            {
                Layout.styles = new Styles();
            }

            if (this.opened == true)
            {
                const float settingsWidth = 320f;
                const float listHeight    = 200f;
                const float padding       = 5f;
                const float closeSize     = 30f;
                const float scrollWidth   = 16f;

                var rect            = new Rect(0f, -OFFSET, Screen.width, Screen.height - OFFSET).PixelPerfect();
                var rectContent     = new Rect(rect.x + MARGIN + settingsWidth + padding, rect.y + MARGIN, rect.width - MARGIN * 2f - padding - settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT).PixelPerfect();
                var rectList        = new Rect(MARGIN, rect.y + MARGIN, settingsWidth, listHeight - padding).PixelPerfect();
                var rectSettings    = new Rect(MARGIN, rect.y + MARGIN + listHeight, settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT - listHeight).PixelPerfect();
                var rectCloseButton = new Rect(rectContent.x + rectContent.width, rectContent.y - closeSize * 0.5f, closeSize, closeSize).PixelPerfect();

                GUI.Box(new Rect(rect.x + MARGIN, rect.y + MARGIN, rect.width - MARGIN * 2f, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT).PixelPerfect(), string.Empty, Layout.styles.layoutBack);
                GUI.Box(rect, string.Empty, Layout.styles.backLock);
                GUI.Box(new Rect(0f, 0f, Screen.width, Screen.height).PixelPerfect(), string.Empty, Layout.styles.dropShadow);
                GUI.Box(rectList, string.Empty, Layout.styles.content);
                GUI.Box(rectSettings, string.Empty, Layout.styles.content);
                GUI.Box(rectContent, string.Empty, Layout.styles.contentScreen);

                GUI.BeginGroup(rectSettings);
                {
                    if (this.component != null)
                    {
                        const float offsetTop = 50f;

                        var viewRect   = new Rect(0f, 0f, rectSettings.width, 0f).PixelPerfect();
                        var scrollView = new Rect(0f, 0f + offsetTop, rectSettings.width, rectSettings.height - offsetTop).PixelPerfect();

                        System.Action <WindowComponent> onChange = (WindowComponent component) => {
                            //Debug.Log(component + "!=" + this.component.component);
                            if (component != this.component.component)
                            {
                                this.component.componentParametersEditor = null;
                                this.component.componentParameters       = this.component.OnComponentChanged(this.screen, component);

                                if (this.component.componentParameters != null)
                                {
                                    var e = Editor.CreateEditor(this.component.componentParameters) as IParametersEditor;
                                    this.component.componentParametersEditor = e;
                                }

                                UnityEditor.EditorUtility.SetDirty(this.screen);
                            }
                        };

                        var c = EditorGUI.ObjectField(new Rect(5f, 5f, viewRect.width - 40f - 5f * 2f, 16f).PixelPerfect(), this.component.component, typeof(WindowComponent), allowSceneObjects: false) as WindowComponent;
                        if (c != this.component.component)
                        {
                            onChange(c);
                        }

                        var nRect = new Rect(viewRect.width - 40f, 5f, 40f - 5f, 16f).PixelPerfect();
                        GUILayoutExt.DrawComponentChooser(nRect, this.screen.gameObject, this.component.component, (component) => {
                            onChange(component);
                        });

                        if (this.component.component != null)
                        {
                            var editor = this.component.componentParametersEditor;

                            nRect.x     = 5f;
                            nRect.width = viewRect.width - 5f * 2f;
                            nRect.y    += nRect.height + 5f;
                            this.component.sortingOrder = EditorGUI.IntField(nRect, new GUIContent("Sorting Order"), this.component.sortingOrder);

                            if (editor != null)
                            {
                                var h = Mathf.Max(scrollView.height, (editor == null) ? 0f : editor.GetHeight());
                                viewRect = new Rect(scrollView.x, scrollView.y, viewRect.width - scrollWidth, h).PixelPerfect();

                                var oldSkin = GUI.skin;
                                GUI.skin = FlowSystemEditorWindow.defaultSkin;
                                this.settingsScrollPosition = GUI.BeginScrollView(scrollView, this.settingsScrollPosition, viewRect, false, true);
                                GUI.skin = oldSkin;
                                {
                                    if (editor != null)
                                    {
                                        EditorGUIUtility.labelWidth = 100f;
                                        //++EditorGUI.indentLevel;
                                        editor.OnParametersGUI(viewRect);
                                        //--EditorGUI.indentLevel;
                                        EditorGUIUtilityExt.LookLikeControls();
                                    }
                                }
                                GUI.EndScrollView();
                            }
                            else
                            {
                                GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height).PixelPerfect(), "Selected component have no parameters", EditorStyles.centeredGreyMiniLabel);
                            }
                        }
                    }
                    else
                    {
                        GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height).PixelPerfect(), "Select an Element", EditorStyles.centeredGreyMiniLabel);
                    }
                }
                GUI.EndGroup();

                GUI.BeginGroup(rectList);
                {
                    const float itemHeight = 30f;

                    this.highlighted.Clear();

                    var viewRect = new Rect(0f, 0f, rectList.width - scrollWidth, 0f).PixelPerfect();
                    this.allListHeight = 0f;
                    for (int i = 0; i < this.props.Count; ++i)
                    {
                        var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag);
                        if (root.showInComponentsList == false)
                        {
                            continue;
                        }

                        if (this.screen.layout.components[i].component == null)
                        {
                            this.highlighted.Add(root);
                        }

                        this.allListHeight += itemHeight;
                    }

                    viewRect.height = Mathf.Max(rectList.height, this.allListHeight);

                    var oldSkin = GUI.skin;
                    GUI.skin = FlowSystemEditorWindow.defaultSkin;
                    this.listScrollPosition = GUI.BeginScrollView(new Rect(0f, 0f, rectList.width, rectList.height).PixelPerfect(), this.listScrollPosition, viewRect, false, true);
                    GUI.skin = oldSkin;
                    {
                        GUI.BeginGroup(viewRect);
                        {
                            var h = 0f;
                            this.hovered = null;
                            for (int i = 0; i < this.props.Count; ++i)
                            {
                                var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag);
                                if (root.showInComponentsList == false)
                                {
                                    continue;
                                }

                                var r = new Rect(0f, h, viewRect.width, itemHeight).PixelPerfect();
                                h += r.height;

                                var isSelected = (this.element == root);
                                if (isSelected == true)
                                {
                                    GUI.Label(r, this.screen.layout.components[i].description, Layout.styles.listButtonSelected);
                                }
                                else
                                {
                                    //r.width -= scrollWidth;
                                    if (GUI.Button(r, this.screen.layout.components[i].description, Layout.styles.listButton) == true)
                                    {
                                        this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == root.tag);
                                        this.element   = root;
                                    }

                                    var inRect = rectList.Contains(Event.current.mousePosition - this.listScrollPosition + Vector2.up * 40f);
                                    if (GUI.enabled == true)
                                    {
                                        EditorGUIUtility.AddCursorRect(r, MouseCursor.Link);
                                    }
                                    if (r.Contains(Event.current.mousePosition) == true && inRect == true)
                                    {
                                        this.hovered = this.screen.layout.components[i];
                                    }
                                    //r.width += scrollWidth;
                                }

                                //r.width -= scrollWidth;
                                GUI.Label(r, this.screen.layout.components[i].tag.ToString(), Layout.styles.listTag);
                            }
                        }
                        GUI.EndGroup();
                    }
                    GUI.EndScrollView();
                }
                GUI.EndGroup();

                var selected = (this.hovered != null) ? this.screen.layout.layout.GetRootByTag(this.hovered.tag) : this.element;
                this.editor.OnPreviewGUI(Color.white, rectContent, Layout.styles.content, selected: selected, onSelection: (element) => {
                    this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == element.tag);
                    this.element   = element;
                }, highlighted: this.highlighted);

                if (GUI.Button(rectCloseButton, string.Empty, Layout.styles.closeButton) == true)
                {
                    this.flowEditor.SetEnabled();
                    this.opened = false;
                }
            }
        }
Beispiel #30
0
        public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, System.Action <WindowLayoutElement, Rect, bool> onElementGUI)
        {
            var oldColor = GUI.color;

            GUI.Box(r, string.Empty);

            var _target = this.target as UnityEngine.UI.Windows.WindowLayout;

            if (_target == null)
            {
                return;
            }

            var elements = _target.elements;

            if (ME.EditorUtilities.IsPrefab(_target.gameObject) == false)
            {
                var pos = (_target.transform as RectTransform).localPosition;
                (_target.transform as RectTransform).localPosition = Vector3.zero;

                foreach (var element in elements)
                {
                    var rectTransform = (element.transform as RectTransform);

                    var corners = new Vector3[4];
                    rectTransform.GetWorldCorners(corners);

                    var rect = new Rect(corners[0].x, -corners[1].y, corners[2].x - corners[1].x, corners[2].y - corners[3].y);

                    element.editorRect = rect;

                    //element.autoStretchX = (rectTransform.anchorMin.x != rectTransform.anchorMax.x);
                    //element.autoStretchY = (rectTransform.anchorMin.y != rectTransform.anchorMax.y);
                }

                _target.root.editorRect = (_target.root.transform as RectTransform).rect;
                (_target.transform as RectTransform).localPosition = pos;
            }

            var scaleFactor = 0f;

            if (elements.Count > 0)
            {
                scaleFactor = this.GetFactor(new Vector2(_target.root.editorRect.width, _target.root.editorRect.height), new Vector2(r.width, r.height));
            }

            var selected = new GUIStyle("flow node 6");

            const int maxDepth = 6;
            var       styles   = new GUIStyle[maxDepth] {
                new GUIStyle("flow node 0"),
                new GUIStyle("flow node 1"),
                new GUIStyle("flow node 2"),
                new GUIStyle("flow node 3"),
                new GUIStyle("flow node 4"),
                new GUIStyle("flow node 5")
            };
            var stylesSelected = new GUIStyle[maxDepth] {
                new GUIStyle("flow node 0 on"),
                new GUIStyle("flow node 1 on"),
                new GUIStyle("flow node 2 on"),
                new GUIStyle("flow node 3 on"),
                new GUIStyle("flow node 4 on"),
                new GUIStyle("flow node 5 on")
            };

            var horArrowsStyle  = new GUIStyle("ColorPickerHorizThumb");
            var vertArrowsStyle = new GUIStyle("ColorPickerVertThumb");

            var horStyle  = new GUIStyle("box");
            var vertStyle = new GUIStyle("box");

            foreach (var element in elements)
            {
                element.editorDrawDepth = element.GetComponentsInParent <WindowLayoutElement>(true).Length - 1;

                var rect = element.editorRect;

                rect.x *= scaleFactor;
                rect.y *= scaleFactor;

                rect.x += r.x + r.width * 0.5f;
                rect.y += r.y + r.height * 0.5f;

                rect.width  *= scaleFactor;
                rect.height *= scaleFactor;

                var style = styles[Mathf.Clamp(element.editorDrawDepth, 0, maxDepth - 1)];
                if (rect.Contains(Event.current.mousePosition) == true)
                {
                    style = stylesSelected[Mathf.Clamp(element.editorDrawDepth, 0, maxDepth - 1)];

                    element.editorHovered = true;
                    this.Repaint();
                }
                else
                {
                    element.editorHovered = false;
                    this.Repaint();
                }

                if (WindowLayoutElement.waitForComponentConnectionElementTemp == element)
                {
                    style = selected;
                }

                GUI.color = color;
                GUI.Label(rect, string.Empty, style);

                GUI.color = oldColor;

                var boxColor = EditorGUIUtility.isProSkin ? oldColor : new Color(1f, 1f, 1f, 0.2f);

                var marginX = 4f;
                var marginY = 2f;

                if (element.autoStretchX == true)
                {
                    var vRect = new Rect(rect);
                    vRect.x     += marginX;
                    vRect.y      = vRect.y + vRect.height * 0.5f - vertArrowsStyle.fixedHeight * 0.5f;
                    vRect.width -= marginX * 2f;
                    vRect.height = vertArrowsStyle.fixedHeight;

                    GUI.color = oldColor;
                    GUI.Label(vRect, string.Empty, vertArrowsStyle);
                    GUI.color = boxColor;
                    GUI.Label(vRect, string.Empty, vertStyle);
                }

                if (element.autoStretchY == true)
                {
                    var vRect = new Rect(rect);
                    vRect.x       = vRect.x + vRect.width * 0.5f - horArrowsStyle.fixedWidth * 0.5f;
                    vRect.y      += marginY;
                    vRect.width   = horArrowsStyle.fixedWidth;
                    vRect.height -= marginY * 2f;

                    GUI.color = oldColor;
                    GUI.Label(vRect, string.Empty, horArrowsStyle);
                    GUI.color = boxColor;
                    GUI.Label(vRect, string.Empty, horStyle);
                }

                if (Event.current.type == EventType.Repaint)
                {
                    element.tempEditorRect = rect;
                }
            }

            if (drawInfo == true || onElementGUI != null)
            {
                WindowLayoutElement maxDepthElement = null;
                var _maxDepth = -1;
                foreach (var element in elements)
                {
                    if (element.editorHovered == false)
                    {
                        continue;
                    }

                    if (_maxDepth < element.editorDrawDepth)
                    {
                        _maxDepth       = element.editorDrawDepth;
                        maxDepthElement = element;
                    }
                }

                var labelStyle = new GUIStyle(EditorStyles.whiteMiniLabel);
                labelStyle.alignment = TextAnchor.UpperLeft;

                foreach (var element in elements)
                {
                    if (element.editorHovered == false || maxDepthElement != element)
                    {
                        continue;
                    }

                    if (GUI.Button(element.tempEditorRect, string.Empty, GUIStyle.none) == true)
                    {
                        if (selectable == true)
                        {
                            WindowLayoutElement.waitForComponentConnectionElementTemp = element;
                            WindowLayoutElement.waitForComponentConnectionTemp        = true;

                            if (onElementGUI != null)
                            {
                                onElementGUI(element, element.tempEditorRect, true);
                            }
                        }
                    }
                    else
                    {
                        if (onElementGUI != null)
                        {
                            onElementGUI(element, element.tempEditorRect, false);
                        }
                    }

                    var rect = element.tempEditorRect;
                    rect.y -= 2f;

                    var w = Mathf.Clamp(element.editorMinWidth, 0, element.editorMinWidth);
                    var h = Mathf.Clamp(element.editorMinHeight, 0, element.editorMinHeight);

                    if (w > 0 || h > 0)
                    {
                        GUI.Label(rect, "min: " + w.ToString() + "x" + h.ToString(), labelStyle);
                    }

                    rect.y += 8f;

                    if (element.autoStretchX == false && element.autoStretchY == false)
                    {
                        w = element.editorRect.width;
                        h = element.editorRect.height;

                        GUI.Label(rect, "size: " + w.ToString() + "x" + h.ToString(), labelStyle);
                    }
                    else if (element.autoStretchX == false)
                    {
                        w = element.editorRect.width;

                        GUI.Label(rect, "size x: " + w.ToString(), labelStyle);
                    }
                    else if (element.autoStretchY == false)
                    {
                        h = element.editorRect.height;

                        GUI.Label(rect, "size y: " + h.ToString(), labelStyle);
                    }
                }
            }

            GUI.color = oldColor;
        }
Beispiel #31
0
		public void Detach(int source, int other, bool oneWay, WindowLayoutElement component = null) {
			
			var window = this.GetWindow(source);
			window.Detach(other, oneWay, component);

			this.isDirty = true;

		}
		public bool Attach(int id, bool oneWay = false, WindowLayoutElement component = null) {
			
			if (this.id == id) return false;

			var result = false;

			if (component != null) {

				if (this.attachedComponents.Any((c) => c.targetWindowId == id && c.sourceComponentTag == component.tag) == false) {

					this.attachedComponents.Add(new ComponentLink(id, component.tag, component.comment));

					// If we attaching component - try to attach window if not

					oneWay = true;
					result = true;

				} else {

					return false;

				}

			}

			if (this.attachItems.Any((item) => item.targetId == id) == false) {
				
				this.attachItems.Add(new AttachItem(id));
				
				if (oneWay == false) {
					
					var window = FlowSystem.GetWindow(id);
					window.Attach(this.id, oneWay: true);
					
				}
				
				return true;
				
			}
			
			return result;
			
		}
Beispiel #33
0
		public bool AlreadyAttached(int source, int other, WindowLayoutElement component = null) {
			
			if (component != null) {
				
				return this.windows.Any((w) => w.id == source && w.AlreadyAttached(other, component));
				
			}
			
			return this.windows.Any((w) => w.id == source && w.AlreadyAttached(other));
			
		}
        public void OnPreviewGUI(Color color, Rect rect, GUIStyle style, bool drawInfo, bool selectable, bool hovered, WindowLayoutElement selectedElement, System.Action <WindowLayoutElement> onSelection, List <WindowLayoutElement> highlighted)
        {
            const float sliderHeight = 20f;
            const float padding      = 40f;

            if (this.styles == null)
            {
                this.styles = new Styles();
            }

            var _target = this.target as TransitionInputTemplateParameters;

            if (_target == null)
            {
                return;
            }

            this.changed = false;

            if (drawInfo == true)
            {
                var sliderRect = new Rect(rect.x + padding, rect.y, rect.width - padding * 2f, sliderHeight);
                rect.y      += sliderHeight;
                rect.height -= sliderHeight;

                var newValue = GUI.HorizontalSlider(sliderRect, this.sliderPosition, 0f, 1f);
                if (newValue != this.sliderPosition)
                {
                    this.changed = true;
                }
                this.sliderPosition = newValue;
            }
            else
            {
                this.changed = true;
                this.hovered = hovered;
            }

            var _targetVideo = this.target as TransitionVideoInputTemplateParameters;

            if (_targetVideo != null)
            {
                if (this.targetTexture != null)
                {
                    GUI.DrawTexture(rect, this.targetTexture);
                }
            }

            var _targetAudio = this.target as TransitionAudioInputTemplateParameters;

            if (_targetAudio != null)
            {
                var pars     = _target.GetParameters <TransitionBase.ParametersAudioBase>();
                var oldEvent = new Event(Event.current);
                //Event.current.Use();
                this.audioCurveIn = new AnimationCurve();
                for (float t = 0f; t <= pars.inDuration + 0.01f; t += 0.05f)
                {
                    var value = pars.GetVolumeValueIn(t);
                    var key   = new Keyframe(t, value);
                    this.audioCurveIn.AddKey(key);
                }

                this.audioCurveOut = new AnimationCurve();
                for (float t = 0f; t <= pars.outDuration + 0.01f; t += 0.05f)
                {
                    var value = pars.GetVolumeValueOut(t);
                    var key   = new Keyframe(t, value);
                    this.audioCurveOut.AddKey(key);
                }

                AnimationCurveUtility.SetLinear(ref this.audioCurveIn);
                AnimationCurveUtility.SetLinear(ref this.audioCurveOut);

                this.audioCurveIn.postWrapMode = WrapMode.Clamp;
                this.audioCurveIn.preWrapMode  = WrapMode.Clamp;

                this.audioCurveOut.postWrapMode = WrapMode.Clamp;
                this.audioCurveOut.preWrapMode  = WrapMode.Clamp;

                {
                    if (Event.current.type == EventType.MouseDown)
                    {
                        Event.current.type = EventType.Repaint;
                    }
                    EditorGUI.CurveField(new Rect(rect.x, rect.y, rect.width, rect.height * 0.5f), string.Empty, this.audioCurveIn, Color.red, new Rect(0f, 0f, pars.inDuration, 1f));
                    EditorGUI.CurveField(new Rect(rect.x, rect.y + rect.height * 0.5f, rect.width, rect.height * 0.5f), string.Empty, this.audioCurveOut, Color.cyan, new Rect(0f, 0f, pars.outDuration, 1f));

                    if (this.sliderPosition > 0f)
                    {
                        GUI.Box(new Rect(rect.x + (this.sliderPosition * rect.width), rect.y, 3f, rect.height * 0.5f), string.Empty);
                        GUI.Box(new Rect(rect.x + (this.sliderPosition * rect.width), rect.y + rect.height * 0.5f, 3f, rect.height * 0.5f), string.Empty);
                    }

                    EditorGUI.DropShadowLabel(new Rect(rect.x, rect.y, rect.width, rect.height * 0.5f), "In");
                    EditorGUI.DropShadowLabel(new Rect(rect.x, rect.y + rect.height * 0.5f, rect.width, rect.height * 0.5f), "Out");
                }
                Event.current = oldEvent;
            }
        }
Beispiel #35
0
 public static bool AlreadyAttached(int source, int other, WindowLayoutElement component = null)
 {
     return(FlowSystem.instance.data.AlreadyAttached(source, other, component));
 }
Beispiel #36
0
 public void SetContent(WindowLayoutElement layoutContent)
 {
     this.layoutContent = layoutContent;
 }
Beispiel #37
0
        public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, bool hovered, WindowLayoutElement selectedElement, System.Action <WindowLayoutElement> onSelection, System.Action <WindowLayoutElement, Rect, bool> onElementGUI, List <WindowLayoutElement> highlighted)
        {
            var _target = this.target as LayoutWindowType;

            if (_target == null || _target.GetCurrentLayout() == null)
            {
                return;
            }
            var layout         = _target.GetCurrentLayout().layout;
            var layoutElements = _target.GetCurrentLayout().components;

            if (layout != null)
            {
                if (this.layoutEditor == null || this.layoutCache != layout)
                {
                    this.layoutEditor = Editor.CreateEditor(layout) as WindowLayoutEditor;
                }
                this.layoutCache = layout;
                if (this.layoutEditor != null)
                {
                    //var emptyStyle = GUIStyle.none;

                    if (Event.current.type != EventType.Layout)
                    {
                        this.layoutEditor.OnPreviewGUI(color, r, background, drawInfo, selectable: selectable, hovered: hovered, selectedElement: selectedElement, onSelection: onSelection, onElementGUI: (element, elementRect, isClicked) => {
                            if (isClicked == true)
                            {
                                var tag  = element.tag;
                                var comp = layoutElements.FirstOrDefault((e) => e.tag == tag);
                                if (comp != null)
                                {
                                    this.selectedComponent = comp;
                                }
                            }

                            /*var tag = element.tag;
                             * var comp = layoutElements.FirstOrDefault((e) => e.tag == tag);
                             * if (comp != null) {
                             *
                             *      comp.OnPreviewGUI(elementRect, emptyStyle);
                             *
                             * }*/
                        }, highlighted: highlighted);
                    }
                }
            }
        }