private void Update_EDITOR(UnityEngine.UI.Windows.WindowLayout _target)
        {
            foreach (var element in _target.elements)
            {
                element.OnValidateEditor();
            }

            #region COMPONENTS
            _target.canvas    = ME.Utilities.FindReferenceChildren <Canvas>(_target);
            _target.raycaster = ME.Utilities.FindReferenceChildren <UnityEngine.EventSystems.BaseRaycaster>(_target);
            #endregion

            _target.initialized = (_target.canvas != null);

            #region SETUP
            if (_target.initialized == true)
            {
                WindowSystem.ApplyToSettings(_target.canvas);

                // Raycaster
                if ((_target.raycaster as GraphicRaycaster) != null)
                {
                    (_target.raycaster as GraphicRaycaster).GetType().GetField("m_BlockingMask", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue((_target.raycaster as GraphicRaycaster), (LayerMask)(1 << _target.gameObject.layer));
                }
            }
            #endregion
        }
Example #2
0
        private void Update_EDITOR(UnityEngine.UI.Windows.WindowLayout _target)
        {
            foreach (var element in _target.elements)
            {
                element.Update_EDITOR();
            }

            #region COMPONENTS
            _target.canvas = _target.GetComponentsInChildren <Canvas>(true)[0];
            var raycasters = _target.GetComponentsInChildren <UnityEngine.EventSystems.BaseRaycaster>(true);
            if (raycasters != null && raycasters.Length > 0)
            {
                _target.raycaster = raycasters[0];
            }
            #endregion

            _target.initialized = (_target.canvas != null);

            #region SETUP
            if (_target.initialized == true)
            {
                WindowSystem.ApplyToSettings(_target.canvas);

                // Raycaster
                if ((_target.raycaster as GraphicRaycaster) != null)
                {
                    (_target.raycaster as GraphicRaycaster).GetType().GetField("m_BlockingMask", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue((_target.raycaster as GraphicRaycaster), (LayerMask)(1 << _target.gameObject.layer));
                }
            }
            #endregion
        }
        private void DrawLayoutChooser(float width)
        {
            if (this.screenInstance == null)
            {
                return;
            }

            var layouts = new string[this.layouts.Count + 1];

            layouts[0] = "None";
            for (int i = 1; i < layouts.Length; ++i)
            {
                layouts[i] = this.layouts[i - 1].name.Replace("Layout", string.Empty);
            }

            GUILayout.Label("Use existing layout:");

            var index = this.layoutPrefab == null ? 0 : (System.Array.IndexOf(layouts, this.layoutPrefab.name.Replace("Layout", string.Empty)));

            index = EditorGUILayout.Popup(index, layouts);
            if (index > 0)
            {
                this.layoutPrefab = this.layouts[index - 1];
            }

            this.layoutPrefab = EditorGUILayout.ObjectField(this.layoutPrefab, typeof(WindowLayout), false) as WindowLayout;
            if (GUILayout.Button("Load") == true)
            {
                this.LoadLayout(this.layoutPrefab);
            }

            GUILayout.Label("Or create the new one:");

            if (GUILayout.Button("Create Layout...", GUILayout.Height(30f)) == true)
            {
                this.showLayoutWindow = true;
            }

            if (Event.current.type == EventType.Repaint && this.showLayoutWindow == true)
            {
                this.showLayoutWindow = false;

                var commentStyle = new GUIStyle(EditorStyles.miniLabel);
                commentStyle.wordWrap = true;

                FlowChooserFilterWindow.Show <FlowWindowLayoutTemplate>(this.rootWindow, (layout) => {
                    this.layoutPrefab = FlowDatabase.GenerateLayout(this.window, layout);
                    this.ReloadLayouts();
                    this.LoadLayout(this.layoutPrefab);

                    this.isScreenDirty = true;
                }, (layout) => {
                    GUILayout.Label(layout.comment, commentStyle);
                });
            }
        }
        private void Setup_EDITOR(UnityEngine.UI.Windows.WindowLayout _target)
        {
            var elements = _target.GetComponentsInChildren <WindowLayoutElement>(true);

            _target.elements = _target.elements.Where((e) => e != null).ToList();
            foreach (var e in elements)
            {
                if (_target.elements.Contains(e) == false)
                {
                    // New elements will be added
                    e.tag = LayoutTag.None;
                }
            }

            var usedTags = new List <LayoutTag>();

            _target.elements = _target.elements.Where((e) => elements.Contains(e)).ToList();

            foreach (var element in elements)
            {
                if (usedTags.Contains(element.tag) == true)
                {
                    element.Reset();
                }
                else
                {
                    if (element.tag != LayoutTag.None)
                    {
                        usedTags.Add(element.tag);
                    }
                }

                if (_target.elements.Contains(element) == true)
                {
                    continue;
                }

                if (element.tag == LayoutTag.None)
                {
                    // Element not installed
                    _target.elements.Add(element);

                    this.isDirty = true;
                }
            }

            // Update
            foreach (var element in _target.elements)
            {
                if (element.tag == LayoutTag.None)
                {
                    element.tag = this.GetTag(usedTags);
                }
            }
        }
		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;

			}*/

		}
		public void Init(float depth, int raycastPriority, int orderInLayer, WindowLayout.ScaleMode scaleMode, Vector2 fixedScaleResolution) {
			
			if (this.initialized == false) {
				
				Debug.LogError("Can't initialize window instance because of some components was not installed properly.");
				return;
				
			}

			this.canvas.sortingOrder = orderInLayer;
			this.canvas.planeDistance = 10f;// * orderInLayer;
			this.canvas.worldCamera = this.GetWindow().workCamera;

			this.SetScale(scaleMode, fixedScaleResolution);

			for (int i = 0; i < this.elements.Count; ++i) this.elements[i].Setup(this.GetWindow());

		}
Example #7
0
        private void ApplyRoot(UnityEngine.UI.Windows.WindowLayout _target)
        {
            if (_target.root == null)
            {
                // Trying to find root
                var root = _target.transform.FindChild("Root");
                if (root != null)
                {
                    _target.root = root.GetComponent <WindowLayoutRoot>() as WindowLayoutRoot;
                    if (_target.root == null)
                    {
                        _target.root = root.gameObject.AddComponent <WindowLayoutRoot>();

                        this.isDirty = true;
                    }
                }
                else
                {
                    // Adding root
                    var go = new GameObject("Root");
                    if (go.GetComponent <RectTransform>() == null)
                    {
                        go.AddComponent <RectTransform>();
                    }

                    _target.root = go.AddComponent <WindowLayoutRoot>();

                    _target.root.transform.SetParent(_target.transform);
                    _target.root.transform.localPosition = Vector3.zero;
                    _target.root.transform.localScale    = Vector3.one;
                    _target.root.transform.localRotation = Quaternion.identity;

                    _target.root.rectTransform.pivot     = Vector3.one * 0.5f;
                    _target.root.rectTransform.anchorMin = new Vector2(0.5f, 0f);
                    _target.root.rectTransform.anchorMax = new Vector2(0.5f, 1f);
                    _target.root.rectTransform.sizeDelta = new Vector2(1080f, 0f);

                    this.isDirty = true;
                }
            }
        }
        private void ReloadLayouts()
        {
            this.layouts.Clear();

            var guids = AssetDatabase.FindAssets("t:GameObject", new string[] { window.compiledDirectory.Trim('/') + "/" + FlowDatabase.LAYOUT_FOLDER });

            foreach (var guid in guids)
            {
                var layout = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(WindowLayout)) as WindowLayout;
                if (layout != null)
                {
                    this.layouts.Add(layout);
                }
            }

            if (this.layouts.Count == 1 && this.autoloadedLayout == false)
            {
                this.layoutPrefab = this.layouts[0];
                this.LoadLayout(this.layoutPrefab);
                this.autoloadedLayout = true;
            }
        }
        private void LoadLayout(WindowLayout layoutPrefab)
        {
            if (layoutPrefab != null)
            {
                if (this.layoutInstance != null)
                {
                    GameObject.DestroyImmediate(this.layoutInstance.gameObject);
                }

                // Loading layout
                this.layoutInstance = FlowDatabase.LoadLayout(layoutPrefab);
                this.layoutInstance.transform.position   = Vector3.zero;
                this.layoutInstance.transform.rotation   = Quaternion.identity;
                this.layoutInstance.transform.localScale = Vector3.zero;

                if ((this.screenInstance as LayoutWindowType) != null)
                {
                    var layoutScreen = this.screenInstance as LayoutWindowType;
                    layoutScreen.layout.layout = layoutPrefab;
                    this.isScreenDirty         = true;
                }
            }
        }
        public void CalculateRects(UnityEngine.UI.Windows.WindowLayout _target)
        {
            var elements = _target.elements;

            var pos = _target.transform.localPosition;

            _target.transform.localPosition = Vector3.zero;

            for (int i = 0; i < elements.Count; ++i)
            {
                var element = elements[i];
                if (element == null)
                {
                    continue;
                }

                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;

                if (i == 0)
                {
                    _target.root.editorRect = rect;
                }

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

            _target.editorScale          = _target.transform.localScale.x;
            _target.root.editorRectLocal = (_target.root.transform as RectTransform).rect;

            (_target.transform as RectTransform).localPosition = pos;
        }
Example #11
0
        public void Create(WindowBase window, Transform root, float depth, int raycastPriority, int orderInLayer)
        {
            var instance = this.layout.Spawn();

            instance.transform.SetParent(root);
            instance.transform.localPosition = Vector3.zero;
            instance.transform.localRotation = Quaternion.identity;
            instance.transform.localScale    = Vector3.one;

            var rect = instance.transform as RectTransform;

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

            instance.Setup(window);
            instance.Init(depth, raycastPriority, orderInLayer, this.scaleMode);

            this.instance = instance;

            foreach (var component in this.components)
            {
                component.Create(window, instance.GetRootByTag(component.tag));
            }
        }
		public void Init(float depth, int raycastPriority, int orderInLayer, WindowLayout.ScaleMode scaleMode, Vector2 fixedScaleResolution, WindowLayoutPreferences layoutPreferences) {
			
			if (this.initialized == false) {
				
				Debug.LogError("Can't initialize window instance because of some components was not installed properly.");
				return;
				
			}
			
			this.transform.localScale = Vector3.zero;

			this.canvas.sortingOrder = orderInLayer;
			this.canvas.planeDistance = 10f;// * orderInLayer;
			this.canvas.worldCamera = this.GetWindow().workCamera;
			
			CanvasUpdater.ForceUpdate(this.canvas, this.canvasScaler);

			var matchWidthOrHeight = 0f;

			if (scaleMode == ScaleMode.Preferences) {

				var fixedScale = layoutPreferences.fixedScale;
				if (fixedScale == true) {

					scaleMode = ScaleMode.Fixed;

				} else {

					scaleMode = ScaleMode.Normal;

				}

				fixedScaleResolution = layoutPreferences.fixedScaleResolution;
				matchWidthOrHeight = layoutPreferences.matchWidthOrHeight;

			}

			this.SetScale(scaleMode, fixedScaleResolution, matchWidthOrHeight);

			for (int i = 0; i < this.elements.Count; ++i) {

				this.elements[i].Setup(this.GetWindow());
				this.elements[i].SetComponentState(WindowObjectState.NotInitialized, dontInactivate: true);

			}

			this.root.Setup(this.GetWindow());

		}
		private void DrawLayoutItem(WindowBase screen, WindowLayout layout, Layout.Component component, float width) {

			if (layout == null) return;

			var tempComponent = layout.elements.FirstOrDefault((e) => e != null && e.tag == component.tag);
			var selected = (Selection.activeGameObject == tempComponent.gameObject);
			var oldColor = GUI.color;

			var boxStyle = new GUIStyle(EditorStyles.toolbar);
			boxStyle.fixedHeight = 0f;
			boxStyle.stretchHeight = true;
			boxStyle.padding.right = -20;
			boxStyle.margin.right = -20;

			var titleStyle = EditorStyles.whiteMiniLabel;

			EditorGUILayout.Separator();

			GUI.color = selected == true ? new Color(0.7f, 1f, 0.7f, 1f) : Color.white;
			EditorGUILayout.BeginVertical(boxStyle, GUILayout.Width(width));

			if (GUILayout.Button(component.tag.ToString() + " (" + component.description + ")", titleStyle, GUILayout.Width(width)) == true) {

				Selection.activeGameObject = tempComponent.gameObject;

			}

			EditorGUILayout.BeginHorizontal();
			GUILayout.Label("Order:", GUILayout.Width(50f));
			var newOrder = EditorGUILayout.IntField(component.sortingOrder, EditorStyles.miniTextField, GUILayout.Width(50f));
			if (newOrder != component.sortingOrder) {

				component.sortingOrder = newOrder;
				this.isScreenDirty = true;

			}

			if (component.sortingOrder == 0) {

				GUILayout.Label("(Auto)", EditorStyles.miniLabel);

			} else {

				if (GUILayout.Button("Set Auto", EditorStyles.miniButton) == true) {

					component.sortingOrder = 0;
					this.isScreenDirty = true;

				}

			}

			EditorGUILayout.EndHorizontal();

			var newComponent = EditorGUILayout.ObjectField(component.component, typeof(WindowComponent), false, GUILayout.Width(width)) as WindowComponent;
			if (newComponent != component.component) {
				
				component.component = newComponent;
				this.isScreenDirty = true;
				
			}

			tempComponent.tempEditorComponent = component.component;

			EditorGUILayout.EndVertical();
			var rect = GUILayoutUtility.GetLastRect();
			if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition) == true) {

				Selection.activeGameObject = tempComponent.gameObject;

			}

			GUI.color = oldColor;

		}
Example #14
0
		public void SetScale(WindowLayout.ScaleMode scaleMode, Vector2 fixedResolution) {

			this.ValidateCanvasScaler();

			if (scaleMode == ScaleMode.Normal) {

				this.SetNoScale();

			} else {
				
				this.canvasScaler.enabled = true;

				if (scaleMode == ScaleMode.Fixed) {

					this.canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
					this.canvasScaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
					this.canvasScaler.matchWidthOrHeight = 0f;
					this.canvasScaler.referenceResolution = new Vector2(fixedResolution.x, fixedResolution.y);

				} else if (scaleMode == ScaleMode.Custom) {

					// We should not do anything in canvasScaler

				}

			}

		}
		private void DrawLayoutChooser(float width) {

			if (this.screenInstance == null) return;

			var layouts = new string[this.layouts.Count + 1];
			layouts[0] = "None";
			for (int i = 1; i < layouts.Length; ++i) layouts[i] = this.layouts[i - 1].name.Replace("Layout", string.Empty);

			GUILayout.Label("Use existing layout:");

			var index = this.layoutPrefab == null ? 0 : (System.Array.IndexOf(layouts, this.layoutPrefab.name.Replace("Layout", string.Empty)));
			index = EditorGUILayout.Popup(index, layouts);
			if (index > 0) {

				this.layoutPrefab = this.layouts[index - 1];

			}

			this.layoutPrefab = EditorGUILayout.ObjectField(this.layoutPrefab, typeof(WindowLayout), false) as WindowLayout;
			if (GUILayout.Button("Load") == true) {

				this.LoadLayout(this.layoutPrefab);

			}

			GUILayout.Label("Or create the new one:");

			if (GUILayout.Button("Create Layout...", GUILayout.Height(30f)) == true) {
				
				this.showLayoutWindow = true;
				
			}

			if (Event.current.type == EventType.Repaint && this.showLayoutWindow == true) {
				
				this.showLayoutWindow = false;
				
				var commentStyle = new GUIStyle(EditorStyles.miniLabel);
				commentStyle.wordWrap = true;

				FlowChooserFilterWindow.Show<FlowWindowLayoutTemplate>(this.rootWindow, (layout) => {

					this.layoutPrefab = FlowDatabase.GenerateLayout(this.window, layout);
					this.ReloadLayouts();
					this.LoadLayout(this.layoutPrefab);

					this.isScreenDirty = true;
					
				}, (layout) => {
					
					GUILayout.Label(layout.comment, commentStyle);
					
				});
				
			}

		}
		private void LoadLayout(WindowLayout layoutPrefab) {
			
			if (layoutPrefab != null) {
				
				if (this.layoutInstance != null) GameObject.DestroyImmediate(this.layoutInstance.gameObject);
				
				// Loading layout
				this.layoutInstance = FlowDatabase.LoadLayout(layoutPrefab);
				this.layoutInstance.transform.position = Vector3.zero;
				this.layoutInstance.transform.rotation = Quaternion.identity;
				this.layoutInstance.transform.localScale = Vector3.zero;
				
				if ((this.screenInstance as LayoutWindowType) != null) {
					
					var layoutScreen = this.screenInstance as LayoutWindowType;
					layoutScreen.layout.layout = layoutPrefab;
					this.isScreenDirty = true;

				}

			}
			
		}
		private void ReloadLayouts() {

			this.layouts.Clear();
			
			var guids = AssetDatabase.FindAssets("t:GameObject", new string[] { window.compiledDirectory.Trim('/') + "/" + FlowDatabase.LAYOUT_FOLDER });
			foreach (var guid in guids) {
				
				var layout = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(WindowLayout)) as WindowLayout;
				if (layout != null) this.layouts.Add(layout);
				
			}

			if (this.layouts.Count == 1 && this.autoloadedLayout == false) {
				
				this.layoutPrefab = this.layouts[0];
				this.LoadLayout(this.layoutPrefab);
				this.autoloadedLayout = true;
				
			}
			
		}
Example #18
0
 private void UpdateLinks(UnityEngine.UI.Windows.WindowLayout _target)
 {
     this.Setup_EDITOR(_target);
     this.Update_EDITOR(_target);
 }
Example #19
0
        public void OnGUI()
        {
            this.position = this.popupRect;

            var color = GUI.color;

            color.a   = this.progress;
            GUI.color = color;

            var depthOffset = 15f;

            var screen = (FlowSceneView.GetItem() != null) ? FlowSceneView.GetItem().GetScreenInstance() : null;

            UnityEngine.UI.Windows.WindowLayout layout = (FlowSceneView.GetItem() != null) ? FlowSceneView.GetItem().GetLayoutInstance() : null;

            if (layout != null || screen != null)
            {
                this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition, false, false);

                var elementStyle = new GUIStyle(EditorStyles.toolbarTextField);
                elementStyle.stretchHeight = false;
                elementStyle.fixedHeight   = 0f;
                elementStyle.margin        = new RectOffset(0, 0, 0, 2);
                elementStyle.padding       = new RectOffset(10, 10, 6, 6);

                GUILayout.BeginHorizontal(elementStyle);
                if (screen != null)
                {
                    var oldBackColor = GUI.backgroundColor;
                    var backColor    = new Color(0.4f, 0.4f, 0.4f, 1f);
                    GUI.backgroundColor = backColor;

                    GUILayout.BeginVertical();
                    {
                        GUILayout.Label(screen.name, EditorStyles.whiteLargeLabel);
                        GUILayout.Label("Screen", EditorStyles.miniLabel);
                    }
                    GUILayout.EndVertical();

                    var rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition) == true)
                    {
                        FlowSceneView.GetItem().SetTab(2);
                    }

                    GUI.backgroundColor = oldBackColor;
                }
                GUILayout.EndHorizontal();

                if (layout != null)
                {
                    var root = layout.root;
                    this.Traverse(root.transform, (element, depth) => {
                        var title       = string.Empty;
                        var descr       = string.Empty;
                        var headerStyle = EditorStyles.whiteLargeLabel;
                        color           = Color.white;

                        var layoutRoot = element.GetComponent <WindowLayoutRoot>();
                        if (layoutRoot != null)
                        {
                            headerStyle           = new GUIStyle(EditorStyles.whiteLargeLabel);
                            headerStyle.fontStyle = FontStyle.Bold;
                            title = "ROOT";
                            descr = "Layout Root";

                            color = new Color(0.8f, 0.8f, 0.6f, 1f);
                        }

                        var layoutElement = element.GetComponent <WindowLayoutElement>();
                        if (layoutElement != null)
                        {
                            title = layoutElement.comment;
                            descr = layoutElement.tag.ToString() + " (" + layoutElement.name + ")";
                        }

                        var maxDepth   = 10f;
                        var depthValue = depth / maxDepth;

                        var oldColor        = GUI.color;
                        var oldBackColor    = GUI.backgroundColor;
                        var backColor       = Selection.activeTransform == element ? new Color(0.7f, 1f, 0.7f, 1f) : color;
                        backColor.a         = 1f - depthValue;
                        GUI.backgroundColor = backColor;

                        GUILayout.BeginHorizontal(elementStyle);
                        {
                            GUILayout.BeginVertical();
                            {
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Label(string.Empty, GUILayout.Width(depthOffset * depth));
                                    GUILayout.Label(title, headerStyle);
                                }
                                GUILayout.EndVertical();
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Label(string.Empty, GUILayout.Width(depthOffset * depth));
                                    GUILayout.Label(descr, EditorStyles.miniLabel);
                                }
                                GUILayout.EndVertical();
                            }
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndHorizontal();

                        GUI.color           = oldColor;
                        GUI.backgroundColor = oldBackColor;

                        var rect     = GUILayoutUtility.GetLastRect();
                        var contains = rect.Contains(Event.current.mousePosition);

                        if (layoutElement != null)
                        {
                            var size             = 20f;
                            var addButtonRect    = rect;
                            addButtonRect.x     += addButtonRect.width - size - elementStyle.padding.right;
                            addButtonRect.y     -= elementStyle.margin.bottom;
                            addButtonRect.width  = size;
                            addButtonRect.height = size;

                            if (GUI.Button(addButtonRect, "+", EditorStyles.toolbarButton) == true)
                            {
                                // Add New Layout Element before current
                                this.CreateLayoutElement(element);
                                return;
                            }

                            var removeButtonRect = addButtonRect;
                            removeButtonRect.x  -= removeButtonRect.width;

                            if (GUI.Button(removeButtonRect, "-", EditorStyles.toolbarButton) == true)
                            {
                                this.RemoveLayoutElement(element);
                                return;
                            }

                            contains = contains && !addButtonRect.Contains(Event.current.mousePosition);
                        }

                        if (Event.current.type == EventType.MouseDown && contains == true)
                        {
                            Selection.activeTransform = element;
                        }
                    });
                }

                EditorGUILayout.EndScrollView();
            }
            else
            {
                var style = new GUIStyle(EditorStyles.whiteLargeLabel);
                style.alignment        = TextAnchor.MiddleCenter;
                style.normal.textColor = Color.gray;

                var rect = this.position;
                rect.x = 0f;
                rect.y = 0f;
                GUI.Label(rect, "No Scene and Layout Selected", style);
            }
        }